SQL LIKE and the DataAdapter

  • Thread starter Thread starter Jim Chapman
  • Start date Start date
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
 
Jim,
I believe that you need to use a % as the wildcard character using OleDb
so that would be
%Cajun%.

Ron Allen
 
Back
Top