Param dataGrid Question

G

Guest

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
 
P

Patrick Olurotimi Ige

Oops found my error with VS.NET i needed to declare

<select id="MySelect" runat="server" name="MySelect">

like

Protected MySelect As System.Web.UI.HtmlControls.HtmlSelect

Which u musn't do in ASP.NET WebMAtrix..
Patrick
 
T

tmayfield

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

User submitted from AEWNET (http://www.aewnet.com/)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

param datagrid question 0
need some help 1
need help - -PLEASE 3
asp.net problem 2
Newbie Question 5
Refreshing DataGrid in page_load 7
Simple Datagrid sort problem 0
CheckBoxList in DataList Question? 4

Members online

No members online now.

Forum statistics

Threads
473,772
Messages
2,569,593
Members
45,112
Latest member
VinayKumar Nevatia
Top