Skip to content
Advertisement

VB.net SQL error Must Declare the Scalar Variable

Hi I have been stuck for a long time on this simple but obtuse message “Must Declare the Scalar Variable”

I have a vb.net and SQL code that inserts data into a simple table. It works OK with sample data, but when I try to use a parameter ( insertcommand.Parameters.Add(“@ID”, SqlDbType.Int, 3).Value = 50) it gives me the error. If I replace the @ID with just a number it works.

Eventually .Value = txtid.text if I can get the parameter to work.

Thanks for your help.

Advertisement

Answer

The code is a bit mixed up – you’re setting up a SqlCommand object and then not using it. Try this:

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement