OleDbCommand,WHERE

时间:2014-12-12 17:22:38

标签: c# oledbcommand

使用Access表(CustomersTable)和两个字段(CustomerID,CustomerName)...字段#1是数字,字段#2是文本:

command.CommandText = "SELECT CompanyName FROM CustomersTable WHERE CompanyName 'Zap'";
command.ExecuteReader();

在查询表达式' CompanyName' Zap'

中导致错误(缺少运算符)。

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

在查询表达式' CompanyName VALUES(?)中导致错误(缺少运算符)。

我怀疑ExecuteReader()可能不正确。

1 个答案:

答案 0 :(得分:3)

您缺少=标志。

command.CommandText = "SELECT CompanyName FROM CustomersTable WHERE CompanyName =  @p1";