类型' System.Data.OleDb.OleDbException'的未处理异常发生在System.Data.dll中。来自Access的字符串

时间:2017-01-31 06:38:46

标签: c# reader oledbdatareader

"未处理的类型' System.Data.OleDb.OleDbException'发生在System.Data.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表中的是/否字段。

2 个答案:

答案 0 :(得分:0)

您的查询存在问题。试试这个:

    string querymenu = "select * from AllMeals where MOTD ="+ true;

答案 1 :(得分:0)

删除single quotes

string querymenu = "select * from AllMeals where MOTD = 1";