bhs67
bhs67

Reputation: 83

OleDbCommand, WHERE don't care

With an Access table (CustomersTable) and two fields (CustomerID, CustomerName) ... field#2 contains "Zap":

command.CommandText = "SELECT  CustomerID, CompanyName   FROM CustomersTable   WHERE  CompanyName =  @p1";
command.Parameters.Add("@p1", OleDbType.VarChar).Value = "Zap";
reader = command.ExecuteReader();

Works fine.

Changing the parameters value to "Za*" finds nothing. What is used for "don't care"?

Upvotes: 0

Views: 117

Answers (2)

Rahul Singh
Rahul Singh

Reputation: 21795

Because "Zap" is not equal to "Za"

You nee to use Like operator something like this:-

command.CommandText = "SELECT  CustomerID, CompanyName   FROM CustomersTable   WHERE  CompanyName LIKE @p1";
command.Parameters.Add("@p1", OleDbType.VarChar).Value = "%Za%";

Upvotes: 2

Dusty Lau
Dusty Lau

Reputation: 591

I believe you want to use a LIKE command:

SELECT  CustomerID, CompanyName   FROM CustomersTable   WHERE  CompanyName LIKE  'Za%'

Upvotes: 1

Related Questions