当前位置: 动力学知识库 > 问答 > 编程问答 >

c# - 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"?

网友答案:

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%";
网友答案:

I believe you want to use a LIKE command:

SELECT  CustomerID, CompanyName   FROM CustomersTable   WHERE  CompanyName LIKE  'Za%'
分享给朋友:
您可能感兴趣的文章:
随机阅读: