"System.Data中发生了类型为'System.Data.OleDb.OleDbException'的未处理异常.dll
其他信息:条件表达式中的数据类型不匹配。
OleDbCommand commandmenu = new OleDbCommand();
commandmenu.Connection = oleConn;
string querymenu = "select * from AllMeals where MOTD = '1'";
commandmenu.CommandText = querymenu;
string menutype = "";
string menuitemname = "";
OleDbDataReader readermenu = commandmenu.ExecuteReader();
while (readermenu.Read())
{
menutype = readermenu.GetString(3);
menuitemname = readermenu.GetString(1);
}
我正在尝试从我的访问数据库中获取字符串,但收到此错误,我的查询文本有问题吗?MOTD 是 AllMeals 表中的"是/否"字段。
您的查询有问题。 试试这个:
string querymenu = "select * from AllMeals where MOTD ="+ true;
删除single quotes
string querymenu = "select * from AllMeals where MOTD = 1";