我很确定我在这里做了所有的事情,而且这个问题背后有一些棘手的错误,希望有人能指出我做错了什么。
我所要做的就是选择符合我的标准的行数。
我的Access数据库中有一列是这样的-
Product Reference
AHD12
OSI133
SO-ERT1
..
..
..这是我的代码片段-
using (conn)
{
OdbcCommand command = new OdbcCommand("SELECT COUNT(*) FROM Product, conn)
int recordCount = (int)command.ExecuteScalar();
}recordCount = 4572
然后我试着做以下的-
using (conn)
{
OdbcCommand command = new OdbcCommand("SELECT COUNT(*) FROM Product where 'Product Reference' ='AHD12' ", conn);
int recordCount = (int)command.ExecuteScalar();
}recordCount = 0
正如您所看到的,产品引用AHD12确实存在于数据库中,但它似乎没有找到它。
有什么想法吗?
发布于 2015-03-23 11:39:31
在这里,双引号可能会帮助您(在SQL server中测试)
"SELECT COUNT(*) FROM Product where \"Product Reference\" ='AHD12'";或者尝试使用反勾号
"SELECT COUNT(*) FROM Product where `Product Reference` ='AHD12';发布于 2015-03-23 11:25:37
带有空格的字段名访问的正确语法是:
"SELECT COUNT(*) FROM Product where [Product Reference] ='AHD12'";https://stackoverflow.com/questions/29208965
复制相似问题