Dim sqlminimum As String = ""
Dim iCount2 As Integer = 0
sqlminimum = " Select Tools.Tool_id,Tools.Tool_cost,Tools.Tool_sum,Tools.Lot_id,Tools.Type_id "
sqlminimum &= " from Tools INNER JOIN Type_Tools "
sqlminimum &= " on Tools.Type_id = Type_Tools.Type_id "
sqlminimum &= " where (Tools.Tool_sum < Type_Tools.Minimum) and (Type_Tools.Type_id='" & cmbtype.SelectedValue & "')"
With Conn
If .State = ConnectionState.Open Then .Close()
.ConnectionString = strConn
.Open()
End With
comm = New SqlCommand
With comm
.CommandType = CommandType.Text
.CommandText = sqlminimum
.Connection = Conn
.ExecuteNonQuery()
End With
da = New SqlDataAdapter(sqlminimum, Conn)
da.Fill(ds, "Minimum")
iCount2 = ds.Tables("Mimimum").Rows.Count ' Error ที่บรรทัดนี้ครับ
มัน Error ว่า Object reference not set to an instance of an object.
sqlminimum = " Select Count(*) ,Tools.Tool_id,Tools.Tool_cost,Tools.Tool_sum,Tools.Lot_id,Tools.Type_id "
sqlminimum &= " from Tools INNER JOIN Type_Tools "
sqlminimum &= " on Tools.Type_id = Type_Tools.Type_id "
sqlminimum &= " where (Tools.Tool_sum < Type_Tools.Minimum) and (Type_Tools.Type_id='" & cmbtype.SelectedValue & "')"
With Conn
If .State = ConnectionState.Open Then .Close()
.ConnectionString = strConn
.Open()
End With
comm = New SqlCommand
With comm
.CommandType = CommandType.Text
.CommandText = sqlminimum
.Connection = Conn
iCount2 = .ExecuteScalar() 'Error
End With
Column 'Tools.Tool_id' is invalid in the select list because it is not contained in an aggregate function and there is no GROUP BY clause.
Column 'Tools.Tool_cost' is invalid in the select list because it is not
Code (VB.NET)
sqlminimum = " Select Tools.Tool_id,Tools.Tool_cost,Tools.Tool_sum,Tools.Lot_id,Tools.Type_id "
sqlminimum &= " from Tools INNER JOIN Type_Tools "
sqlminimum &= " on Tools.Type_id = Type_Tools.Type_id "
sqlminimum &= " where (Tools.Tool_sum < Type_Tools.Minimum) and (Type_Tools.Type_id='" & cmbtype.SelectedValue & "')"
With Conn
If .State = ConnectionState.Open Then .Close()
.ConnectionString = strConn
.Open()
End With
comm = New SqlCommand
With comm
.CommandType = CommandType.Text
.CommandText = sqlminimum
.Connection = Conn
.ExecuteScalar()
End With
da = New SqlDataAdapter(sqlminimum, Conn)
da.Fill(ds, "Minimum")
iCount2 = ds.Tables("Mimimum").Rows.Count 'Error
รองเปลี่ยนตัวร้ายแล้วแต่ก็ยังฟ้องเหมือนเดิมอะครับ Object reference not set to an instance of an object.
Dim sqlminimum As String
sqlminimum = "Select [Tools].[Tool_id], [Tools].[Tool_cost], [Tools].[Tool_sum], [Tools].[Lot_id], [Tools].[pType_id] "
sqlminimum &= "From [Tools] Inner Join [Type_Tools] "
sqlminimum &= "On [Tools].[Type_id] = [Type_Tools].[Type_id] "
sqlminimum &= "Where ([Tools].[Tool_sum] < [Type_Tools].[Minimum]) And ([Type_Tools].[Type_id]=@Type_id)"
'With Conn
'If .State = ConnectionState.Open Then .Close()
'.ConnectionString = strConn
'.Open()
'End With
Dim comm As SqlCommand
comm = New SqlCommand(sqlminimum, Conn)
comm.Parameters.Add("@Type_id", SqlDbType.Int)
comm.Parameters("@Type_id").Value = cmbtype.SelectedValue
'With comm
'.CommandType = CommandType.Text
'.CommandText = sqlminimum
'.Connection = Conn
'.ExecuteScalar()
'End With
Dim da As SqlDataAdapter
da = New SqlDataAdapter(comm)
da.Fill(ds, "Minimum")
Dim iCount2 As Integer
iCount2 = ds.Tables("Mimimum").Rows.Count
Date :
2010-01-02 16:02:50
By :
tungman
No. 6
Guest
มัน Error ตรง Code (VB.NET)
da.Fill(ds, "Minimum") ' Failed to convert parameter value from a String to a Int32.
Dim sqlminimum As String
sqlminimum = "Select [Tools].[Tool_id], [Tools].[Tool_cost], [Tools].[Tool_sum], [Tools].[Lot_id], [Tools].[pType_id] "
sqlminimum &= "From [Tools] Inner Join [Type_Tools] "
sqlminimum &= "On [Tools].[Type_id] = [Type_Tools].[Type_id] "
sqlminimum &= "Where ([Tools].[Tool_sum] < [Type_Tools].[Minimum]) And ([Type_Tools].[Type_id]=@Type_id)"
'With Conn
'If .State = ConnectionState.Open Then .Close()
'.ConnectionString = strConn
'.Open()
'End With
Dim comm As SqlCommand
comm = New SqlCommand(sqlminimum, Conn)
comm.Parameters.Add("@Type_id", SqlDbType.NVarChar)
comm.Parameters("@Type_id").Value = cmbtype.SelectedValue
'With comm
'.CommandType = CommandType.Text
'.CommandText = sqlminimum
'.Connection = Conn
'.ExecuteScalar()
'End With
Dim da As SqlDataAdapter
da = New SqlDataAdapter(comm)
da.Fill(ds, "Minimum")
Dim iCount2 As Integer
iCount2 = ds.Tables("Mimimum").Rows.Count