WhiteStar1 WhiteStar1 - 7 months ago 21
Vb.net Question

Another - Must declare the scalar variable @TDate Vb.Net

I have searched long and hard on this issue and can't come up with anything that works! Please can you help me? What am I doing wrong to cause this error? Must "declare the scalar variable @TDate" I am updating two dates - dob and transfersate. In this case transferdate in the sql table and TDate a date value from a date control.

Using SQLCmd As New SqlClient.SqlCommand("UPDATE member SET "DOB = @DOB, transferdate=@TDate WHERE mid =" & MID, SQLCon)

SQLCmd.Parameters.Add("@transferdate", SqlDbType.Date)
SQLCmd.Parameters("@transferdate").Value = TDate

SQLCmd.Parameters.AddWithValue("@DOB", DOB)

i = SQLCmd.ExecuteNonQuery
End Using

Answer

In you sql query you refer to the variable @TDate in the bit transferdate=@TDate. You add SQLParameters to your cmd, but the parameter you add is called @transferdate.

Try changing this bit of code here:

            SQLCmd.Parameters.Add("@transferdate", SqlDbType.Date)
            SQLCmd.Parameters("@transferdate").Value = TDate

to this instead:

            SQLCmd.Parameters.Add("@TDate", SqlDbType.Date)
            SQLCmd.Parameters("@TDate").Value = TDate