Can anyone tell me please what am i doing wrong on this lines o code
I just want to make the Parameter to grab the Value from the QueryString
Thanks in advance for any Help
Cheers
Nothing jumps out at me as being wrong. What error are you getting?Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim strConn As OleDb.OleDbConnection = New OleDb.OleDbConnection(ConfigurationSettings.AppSettings("MyConn"))
Dim strSQL As String
Dim Search As String
Search = Request.QueryString("Search")strSQL = "SELECT ref FROM products WHERE ref LIKE ?"
Dim cmd As New OleDb.OleDbCommand(strSQL, strConn)
cmd.Parameters.Add("@dotnet.itags.org.ref", Search)strConn.Open()
Dim rdr As OleDb.OleDbDataReader = cmd.ExecuteReaderDataGrid1.DataSource = rdr
DataGrid1.DataBind()strConn.Close()
Response.Redirect("~/result.aspx?Search=" + TextBox1.Text)
End Sub
Hi :)
i get This Error
Exception Details: System.Data.OleDb.OleDbException: Parameter ?_1 has no default value.
Source Error:
Line 42:
Line 43: strConn.Open()
Line 44: Dim rdr As OleDb.OleDbDataReader = cmd.ExecuteReader
Line 45:
Line 46: DataGrid1.DataSource = rdr
try this change:
strSQL = "SELECT ref FROM products WHERE ref LIKE ?"
to
strSQL = "SELECT ref FROM products WHERE ref LIKE @.ref"
:(
It dosent work ...buahahhaa
What is the new error?
Here it goes
Exception Details: System.Data.OleDb.OleDbException: Parameter @.ref has no default value.
Source Error:
Line 42:
Line 43: strConn.Open()
Line 44: Dim rdr As OleDb.OleDbDataReader = cmd.ExecuteReader
Line 45:
Line 46: DataGrid1.DataSource = rdr
Stack Trace:
[OleDbException (0x80040e10): Parameter @.ref has no default value.]
System.Data.OleDb.OleDbCommand.ExecuteCommandTextErrorHandling(Int32 hr) +41
System.Data.OleDb.OleDbCommand.ExecuteCommandTextForSingleResult(tagDBPARAMS dbParams, Object& executeResult) +174
System.Data.OleDb.OleDbCommand.ExecuteCommandText(Object& executeResult) +92
System.Data.OleDb.OleDbCommand.ExecuteCommand(CommandBehavior behavior, Object& executeResult) +65
System.Data.OleDb.OleDbCommand.ExecuteReaderInternal(CommandBehavior behavior, String method) +112
System.Data.OleDb.OleDbCommand.ExecuteReader(CommandBehavior behavior) +69
System.Data.OleDb.OleDbCommand.ExecuteReader() +7
Sinfonia.NET.teste2.Button1_Click(Object sender, EventArgs e) in C:\Inetpub\Sinfonia.NET\Sinfonia.NET\teste2.aspx.vb:44
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +108
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +57
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +18
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +33
System.Web.UI.Page.ProcessRequestMain() +1277
Hmm... try this? (note I added the top If Statement because I think that might be one of the causes... if Search is Nothing [null] then that might mess things up)
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If IsNothing(Request.QueryString("Search")) Then
Response.Redirect("~/result.aspx?Search=" + TextBox1.Text)
End IfDim strConn As OleDb.OleDbConnection = New OleDb.OleDbConnection(ConfigurationSettings.AppSettings("MyConn"))
Dim strSQL As String = "SELECT ref FROM products WHERE ref LIKE @.ref"
Dim Search As String = Request.QueryString("Search")Dim cmd As New OleDb.OleDbCommand(strSQL, strConn)
cmd.Parameters.Add("@.ref", SqlDbType.Text).Value = Search' ChangedstrConn.Open()
Dim rdr As OleDb.OleDbDataReader = cmd.ExecuteReaderDataGrid1.DataSource = rdr
DataGrid1.DataBind()strConn.Close()
Response.Redirect("~/result.aspx?Search=" + TextBox1.Text)
End Sub
0 comments:
Post a Comment