P
Patrick Olurotimi Ige
Why does this Sub program work well with ASP.NET Web MAtrix and gives
ERROR when compiled in VS.NET 2003 :-
"Prepared statement '(@State nvarchar(2))select * from Authors where
state = @State' expects parameter @State, which was not supplied."
The error comes at line :-
MyCommand.SelectCommand.Parameters("@State").Value = MySelect.Value
Sub GetAuthors_Click(Sender As Object, E As EventArgs)
Dim DS As DataSet
Dim MyConnection As SqlConnection
Dim MyCommand As SqlDataAdapter
Dim SelectCommand As String = "select * from Authors where state
= @State"
MyConnection = New
SqlConnection("server=(local);database=pubs;integrated security=true;")
MyCommand = New SqlDataAdapter(SelectCommand, MyConnection)
MyCommand.SelectCommand.Parameters.Add(New
SqlParameter("@State", SqlDbType.NVarChar, 2))
MyCommand.SelectCommand.Parameters("@State").Value =
MySelect.Value
DS = new DataSet()
MyCommand.Fill(DS, "Authors")
MyDataGrid.DataSource=DS.Tables("Authors").DefaultView
MyDataGrid.DataBind()
End Sub
ERROR when compiled in VS.NET 2003 :-
"Prepared statement '(@State nvarchar(2))select * from Authors where
state = @State' expects parameter @State, which was not supplied."
The error comes at line :-
MyCommand.SelectCommand.Parameters("@State").Value = MySelect.Value
Sub GetAuthors_Click(Sender As Object, E As EventArgs)
Dim DS As DataSet
Dim MyConnection As SqlConnection
Dim MyCommand As SqlDataAdapter
Dim SelectCommand As String = "select * from Authors where state
= @State"
MyConnection = New
SqlConnection("server=(local);database=pubs;integrated security=true;")
MyCommand = New SqlDataAdapter(SelectCommand, MyConnection)
MyCommand.SelectCommand.Parameters.Add(New
SqlParameter("@State", SqlDbType.NVarChar, 2))
MyCommand.SelectCommand.Parameters("@State").Value =
MySelect.Value
DS = new DataSet()
MyCommand.Fill(DS, "Authors")
MyDataGrid.DataSource=DS.Tables("Authors").DefaultView
MyDataGrid.DataBind()
End Sub