Question Locked

VB.NET Access DB DataSet problem

0 helpful
2 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

I'm developing a VB.NET 2005 application with an MS Access backend. The Queries for the most part are "LIKE" queries, and they will not return rows in the application when querying in Access I return rows. When I run a "=" query I return rows from the application and in Access. The query is as follows:

strSQL = "SELECT [ID], [Subject], [Body], [Received], [From] " & _
"FROM " & strTableName & " " & _
"WHERE (((Body) Like """ & strCriteria1 & """ And (Body) Like """ & strCriteria3 & """)) " & _
"ORDER BY Received DESC; "

I would love to hear from anyone that has had this problem and knows a work around. As you can see I am passing in the table name and 2 variables in the where statement. When I hardcode the table name and where criteria I still return nothing. Thanks in advance for you help.

2 replies

by tony hopkinson

but Access SQL syntax is not a speciality.

Select ... From someTable Where someField Like '%any%'

PS you don't want to make a habit of building strings like this in .NET

Use the format method of string, or if you need more control, the stringbuilder class.

I hesitite to ask, but you have considered SQL injection attacks as well?
if not you might want to look up parameterised queries.

http://www.vb-helper.com/howto_net_db_parameterized_query.html

This discussion is closed to new replies.