Question How do I customise a SELECT WHERE statement in an OleDbDataAdapter?

geor68

New member
Joined
Nov 6, 2011
Messages
4
Programming Experience
Beginner
Hi,

How do I customise a SELECT WHERE statement in an OleDbDataAdapter so the WHERE clause is taken from a session variable called Employer? eg instead of

Dim daExcel As New OleDb.OleDbDataAdapter("SELECT * FROM [Sheet1$] WHERE Employer='EmployerA'", cnExcel) I want to replace the hardcoded EmployerA with the value of the session variable Employer. the problem is with the single and double quotes!!!!!

Thanks in advance, Any advice would be more than welcome.

geor68
 
You should ALWAYS use parameters to insert values (other than literals) into SQL code, no matter where those values come from. To learn why and how to use parameters, follow the Blog link in my signature and check out my post on Parameters In ADO.NET. You'll be pleased to hear that using parameters eradicates any issues with quotes.
 
Back
Top