PDA

Click to See Complete Forum and Search --> : How to use LIKE statement in the SQL Query for an ADO control


csingeu
Jun 15th, 2000, 03:42 PM
I have this ado data control and a datagrid

The SQL Statement is something like this
SQLString = "SELECT * FROM Main WHERE Name LIKE ('*John*')"

when the display button is clicked, the following statements are executed,

frmDBGrid.Adodc1.CommandType = adCmdText
frmDBGrid.Adodc1.RecordSource = SQLString
frmDBGrid.Adodc1.Refresh
frmDBGrid.DataGrid1.SetFocus

But it seems like the ado data control has no record in it, when there should be.

Chris
Jun 15th, 2000, 03:54 PM
Your SQl should look like this:

SQLString = "SELECT * FROM Main WHERE Name LIKE '*John*';"


and it will search for all record that have any character either before or after John.

csingeu
Jun 15th, 2000, 04:17 PM
I've tried the following SQL statement..
but it's still not working.
the ado data control is greyed out. (meaning no recordset?)

Chris
Jun 17th, 2000, 03:26 AM
Just make sure there is a data with "John" in the Name field. If yes, then try to change the field name Name to other like MyName. Because i affraid it conflict with the system reserve word.

csingeu
Jun 17th, 2000, 09:34 PM
heh
thanks Chris and others who have helped me out..

btw, I can't remember who's that..
but someone posted the solution on the forum..

i should have change the wildcard * to %
as in "Name LIKE ('*John*')" to "Name LIKE ('%John%')"

think maybe it's becoz I used adodc ...
if i've used coding instead... think * will work as well..
coz it actually worked in the first place...

anyway, thanks..
btw, how do I close a thread?