R
RN1
Using SqlCommand, this is how I am updating a database table:
--------------------------------------------------------------------------------
Sub UpdateDataGrid(obj As Object, ea As DataGridCommandEventArgs)
strSQL = "UPDATE Basket SET Quantity = Qty, Total = TotAmt WHERE
BasketID = BID AND ProductID = PID"
sqlCmd = New SqlCommand(strSQL, sqlConn)
With sqlCmd
.Parameters.Add("Qty", SqlDbType.Int).Value = CInt(iQty)
.Parameters.Add("TotAmt", SqlDbType.Money).Value = CInt(iQty)
* CType(ea.Item.FindControl("lblPrice"), Label).Text
.Parameters.Add("BID", SqlDbType.VarChar, 50).Value =
strBasketID
.Parameters.Add("PID", SqlDbType.VarChar, 50).Value =
CType(ea.Item.FindControl("lblID"), Label).Text
End With
sqlConn.Open()
sqlCmd.ExecuteNonQuery()
sqlConn.Close()
End Sub
--------------------------------------------------------------------------------
But the above code generates the following error pointing to the
sqlCmd.ExecuteNonQuery() line in the above code:
Invalid column name 'BID'.
Invalid column name 'PID'.
BID & PID are not the column names in the actual database table but
can't it be done in the way I have done above? In fact, Qty & TotAmt
are not the column names in the actual database table as well; so why
isn't the error pointing to Qty & TotAmt as they will be evaluated
before BID & PID, if I am not mistaken?
Thanks,
Ron
--------------------------------------------------------------------------------
Sub UpdateDataGrid(obj As Object, ea As DataGridCommandEventArgs)
strSQL = "UPDATE Basket SET Quantity = Qty, Total = TotAmt WHERE
BasketID = BID AND ProductID = PID"
sqlCmd = New SqlCommand(strSQL, sqlConn)
With sqlCmd
.Parameters.Add("Qty", SqlDbType.Int).Value = CInt(iQty)
.Parameters.Add("TotAmt", SqlDbType.Money).Value = CInt(iQty)
* CType(ea.Item.FindControl("lblPrice"), Label).Text
.Parameters.Add("BID", SqlDbType.VarChar, 50).Value =
strBasketID
.Parameters.Add("PID", SqlDbType.VarChar, 50).Value =
CType(ea.Item.FindControl("lblID"), Label).Text
End With
sqlConn.Open()
sqlCmd.ExecuteNonQuery()
sqlConn.Close()
End Sub
--------------------------------------------------------------------------------
But the above code generates the following error pointing to the
sqlCmd.ExecuteNonQuery() line in the above code:
Invalid column name 'BID'.
Invalid column name 'PID'.
BID & PID are not the column names in the actual database table but
can't it be done in the way I have done above? In fact, Qty & TotAmt
are not the column names in the actual database table as well; so why
isn't the error pointing to Qty & TotAmt as they will be evaluated
before BID & PID, if I am not mistaken?
Thanks,
Ron