使用Access表(CustomersTable)和两个字段(CustomerID,CustomerName)...字段#2包含" Zap":
command.CommandText = "SELECT CustomerID, CompanyName FROM CustomersTable WHERE CompanyName = @p1";
command.Parameters.Add("@p1", OleDbType.VarChar).Value = "Zap";
reader = command.ExecuteReader();
工作正常。
将参数值更改为" Za *"一无所获。什么用于"不关心"?
答案 0 :(得分:2)
因为" Zap"不等于" Za"
您需要使用Like
运算符,如下所示: -
command.CommandText = "SELECT CustomerID, CompanyName FROM CustomersTable WHERE CompanyName LIKE @p1";
command.Parameters.Add("@p1", OleDbType.VarChar).Value = "%Za%";
答案 1 :(得分:1)
我相信您想使用LIKE命令:
SELECT CustomerID, CompanyName FROM CustomersTable WHERE CompanyName LIKE 'Za%'