Jake Jake - 2 months ago 7
SQL Question

Why does a LIKE query in Access not return any records?

Is there any reason why

SELECT * FROM MyTable WHERE [_Items] LIKE '*SPI*'


does not return any records with
OleDbAdapter.Fill(DataSet)
or
OleDbCommand.ExecuteReader()
?

When I run the same SQL in MS Access directly, it returns the expected records. Also, in the same code, if I change the SQL to

SELECT * FROM MyTable


all records are returned.

Answer

Change your * to % as % is the wildcard search when using OLE DB.

SELECT * FROM MyTable WHERE [_Items] LIKE '%SPI%' 
Comments