rufus Posted July 8, 2003 Posted July 8, 2003 I want to create a OleDbAdapter with commandtext as Select title,titleid from titles where title LIKE @title+'%' I want to get the title from the textbox, but If the build this query in the commandtext of the OleDbAdapter, it says error at '@', but I need this,if I type half word, then it should retirve all the titleid and title from the datasource. But Iam getting error in SQL statement at @. can anyone know how to slove. Quote Rufus
*Experts* Nerseus Posted July 8, 2003 *Experts* Posted July 8, 2003 The @ (at sign) is used to designate something as a variable in SQL Server. Since you're executing a single line SELECT, there are no variables (normally they're used in stored procedures and user defined functions). I think you just want: DA.SelectCommand = "Select title,titleid from titles where title LIKE '" + txtTitle.Text.Replace("'", "''") + "%'" I assumed your textbox was called txtTitle and that you're building this SQL string "by hand". The replace is in case the user enters anything with a single quote in it. -Nerseus Quote "I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut
rufus Posted July 8, 2003 Author Posted July 8, 2003 I tried using it says string cannot be converted to dataadapter command. Is there any way, that by using this SQL command I can create by using the controls instead "by hand". thanks. Quote Rufus
rufus Posted July 8, 2003 Author Posted July 8, 2003 I have tried also with creating a new OleDb.OleDbcommand (comm) and setting comm.commandtext="Select title,titleid from titles where title LIKE '" + txtTitle.Text.Replace("'", "''") + "%'" and DA.Selectcommand=comm, but it gives an error, the "Object reference not set to an instance of object". Quote Rufus
Leaders dynamic_sysop Posted July 8, 2003 Leaders Posted July 8, 2003 something like this should work : Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim x As New OleDb.OleDbCommand("Select title,titleid from titles where title LIKE @title+'%'") MsgBox(x.CommandText) '/// make sure it's set. End Sub Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.