Like Operator error..

mrprogman

New Member
hI...How can i use the operator like in progress..?.. i needed filter in query buy i get this error...

ERROR [HY000] [DataDirect][ODBC OPENEDGE driver][OPENEDGE]Syntax error in SQL statement at or about "='rizo' "

this is my code

Dim MyConnection As System.Data.Odbc.OdbcConnection = New System.Data.Odbc.OdbcConnection("Driver={Progress Openedge 10.1A Driver};DSN=PROGRESS;DB=pace;UID=sysprogress;PWD=password;HOST=192.168.10.248;PORT=2580;")
Dim MyCommand As System.Data.Odbc.OdbcDataAdapter = New System.Data.Odbc.OdbcDataAdapter("SELECT arh.name FROM PUB.arh where name LIKE ='" & TextBox1.Text & "' ", MyConnection)


Dim DS As DataSet = New DataSet
MyCommand.Fill(DS, "arh")
GridView1.DataSource = DS.Tables("arh").DefaultView
GridView1.DataBind()

thanks
 
LIKE is an operator, = is an operator, you should be using both in one statement. So your query should simply be:

LIKE 'rizo'

However, this will only find records where name equals rizo since you are not using any wildcards. If you want to find all records where the name contains rizo you need to use:

LIKE '%rizo%'
 
as a side note... did you ever wonder what if the user doesn't put in that text box what do you expect it will put?

Code:
Dim MyCommand As System.Data.Odbc.OdbcDataAdapter = New System.Data.Odbc.OdbcDataAdapter("SELECT arh.name FROM PUB.arh where name LIKE ='" & TextBox1.Text & "' ", MyConnection)

should probably go ahead and look up 'sql injection' on our mighty documentation system (aka google)
 
Thanks for your answer...my really problem is the sintax of operator like and one parameter.. when the user fill the textbox with any name....the query find in the database, but i get nothing..i made changes in my query , i no get error but at the same time no get result in my grid..this is my query....i need the sintax of operator like and one parameter (textbox1) thanks

Dim MyConnection As System.Data.Odbc.OdbcConnection = New System.Data.Odbc.OdbcConnection("Driver={Progress Openedge 10.1A Driver};DSN=PROGRESS;DB=pace;UID=sysprogress;PWD=password;HOST=192.168.10.248;PORT=2580;")
Dim MyCommand As System.Data.Odbc.OdbcDataAdapter = New System.Data.Odbc.OdbcDataAdapter("SELECT arh.name FROM PUB.arh where name LIKE '% textbox1.text %' ", MyConnection)

Dim DS As DataSet = New DataSet
MyCommand.Fill(DS, "arh")
GridView1.DataSource = DS.Tables("arh").DefaultView
GridView1.DataBind()
 
You have two problems.

1. query syntax - this has been answered in my first post
2. how to get contents of a visual basic (?) textbox and put it in a string (safely)

Number 1 has been answered.
For number 2, try a 'visual basic or whatever language you are using' forum.
 
Back
Top