SQL LIKE and the DataAdapter

J

Jim Chapman

I'm having problems with the SelectCommandText of the Data Adapter. I
suspect that I'm misusing the SQL LIKE command or am caught in some kind of
gotcha.



If I pass the Data Adapter this:

SELECT * FROM Products WHERE SupplierID = 2;

It works fine.



But if I pass it this:

SELECT * FROM Products WHERE ProductName LIKE '*Cajun*';

No rows are returned. I know that Chef Anton's Cajun Seasoning is in fact
in the table.



This is what I'm doing:



Dim strSQL As String = "SELECT * FROM Products WHERE ProductName LIKE
'*Cajun*';"

Dim daNW As OleDbDataAdapter

Dim dsNW As DataSet



daNW = New OleDbDataAdapter(strSQL, conNW)

daNW.FillSchema(dsNW, SchemaType.Source, "Products")

daNW.Fill(dsNW, "Products")



If dsNW.Tables("Products").Rows.Count > 0 Then

....



If I use a LIKE in the sql string, rows.count always returns 0. Either sql
string works fine in Access (jet 4.)



Any insight appreciated,

Jim Chapman
 
R

Ron Allen

Jim,
I believe that you need to use a % as the wildcard character using OleDb
so that would be
%Cajun%.

Ron Allen
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top