Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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.

Rufus
  • *Experts*
Posted

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

"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
Posted

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.

Rufus
Posted

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".

Rufus
  • Leaders
Posted

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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...