problem in creating OleDbAdapter

rufus

Active member
Joined
Jul 7, 2003
Messages
28
Location
Arlington,TX
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.
 
The @ (at sign) is used to designate something as a variable in SQL Server. Since youre executing a single line SELECT, there are no variables (normally theyre 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 youre building this SQL string "by hand". The replace is in case the user enters anything with a single quote in it.

-Nerseus
 
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.
 
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".
 
something like this should work :
Code:
    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 its set.
    End Sub
 
Back
Top