ado troubles with vb.net 2003

R

Rubber Steve

I am having trouble querying an Access database with ADO .NET in VB .NET. I
can get results returned using primary keys, but when using something like
LastName, nothing happens. I am not sure why this is. Here is the query
that works, and the one that doesn't:

Works:
cmd = New OleDbCommand("select * from employee where EmployeeID= " &
txtEmployeeID.Text, cn)

Does Not Work:
cmd = New OleDbCommand("select * from employee where EmpLastName like " &
txtLast.Text, cn)

Any help would be greatly appreciated,

Rubber Steve
 
P

pierrick-allusse

Do this :

cmd = New OleDbCommand("select * from employee where EmpLastName like '%" +
txtLast.Text + "%'", cn)

And try...^^ Don't forget the single quote !

Pierrick
 
R

Rubber Steve

pierrick-allusse said:
Do this :

cmd = New OleDbCommand("select * from employee where EmpLastName like '%" +
txtLast.Text + "%'", cn)

And try...^^ Don't forget the single quote !

Thank you. You were most helpful! :)

Rubber Steve
 

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