I want your help with VB 2010 (Visual Studio 2010).
Here is the code snippet
objCommand.CommandText = "UPDATE tblCustomers SET weight= @weight, height= @height WHERE id=@id "
What i want to do is the following:
I have a form and i want,by clicking the appropriate button, to update the height and weight values which have the specified primary key ‘id’.
The primary key ‘id’ is of type IDENTITY.The problem is that the above code does not work. It says Must declare the scalar variable “@id”.
Any help is appreciated.Thank you
you need to add
@id,@weight,and@heightparameters to the parameters list of yourobjCommandwhere the values(second parameter of
SqlParameterconstructor) of your parameters come from your form.Note you should load the value of
@Idinto the form. I don’t know what is the data you have loaded but I think there is some control contains theIDvalue. You should read it back and pass it into your command paramerters