e.g.
asp.net
Scenario : fill dataset in code-behind by passing a parameter variable in query string
Error : Must declare the scalar variable @Variable
Dim strSQL As String = "Select * from MyTable Where ID = @Variable "
Dim cmd As SqlClient.SqlCommand = New SqlClient.SqlCommand(strSQL, con)
cmd.Parameters.Add("@ID", SqlDbType.Int).Value = MyVariable
Dim da As SqlDataAdapter = New SqlDataAdapter(strSQL, con)
da.Fill(ds)
solution : add the paramater to the datadapter, not to the initial command
da.SelectCommand.Parameters.AddWithValue("@ID", MyVariable )
asp.net
Scenario : fill dataset in code-behind by passing a parameter variable in query string
Error : Must declare the scalar variable @Variable
Dim strSQL As String = "Select * from MyTable Where ID = @Variable "
Dim cmd As SqlClient.SqlCommand = New SqlClient.SqlCommand(strSQL, con)
cmd.Parameters.Add("@ID", SqlDbType.Int).Value = MyVariable
Dim da As SqlDataAdapter = New SqlDataAdapter(strSQL, con)
da.Fill(ds)
solution : add the paramater to the datadapter, not to the initial command
da.SelectCommand.Parameters.AddWithValue("@ID", MyVariable )