I'm trying to learn how to use command parameters to do my SQL commands and seemed to have hit an impasse.
I created the following code:
When the ExecuteNonQuery command runs, I get the following error:
The variable name '@ID' has already been declared. Variable names must be unique within a query batch or stored procedure.
Must declare the scalar variable "@DateStamp".
My problem is that this variable name is not used anywhere else in my code, so it's not duplicate use of the name. What am I doing wrong?
I created the following code:
VB.NET:
cmd.CommandText = "Insert into PINS (PIN, ControlNumber, BatchID, Consumed) values (@PIN, @Control, @ID, @Consumed)"
cmd.Parameters.Add("@PIN", SqlDbType.VarChar).Value = pin.number
cmd.Parameters.Add("@Control", SqlDbType.VarChar).Value = pin.control
cmd.Parameters.Add("@ID", SqlDbType.Int).Value = BatchID
cmd.Parameters.Add("@Consumed", SqlDbType.Bit).Value = False
cmd.ExecuteNonQuery()
The variable name '@ID' has already been declared. Variable names must be unique within a query batch or stored procedure.
Must declare the scalar variable "@DateStamp".
My problem is that this variable name is not used anywhere else in my code, so it's not duplicate use of the name. What am I doing wrong?