【问题标题】:An unhandled exception of type 'System.Data.OleDb.OleDbException' occurred in System.Data.dll. String from AccessSystem.Data.dll 中出现“System.Data.OleDb.OleDbException”类型的未处理异常。来自 Access 的字符串
【发布时间】:2017-06-16 12:15:39
【问题描述】:

“System.Data.dll 中发生了“System.Data.OleDb.OleDbException”类型的未处理异常

附加信息:条件表达式中的数据类型不匹配。"

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 表中的一个是/否字段。

【问题讨论】:

    标签: c# reader oledbdatareader


    【解决方案1】:

    您的查询有问题。试试这个:

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

    【讨论】:

      【解决方案2】:

      删除single quotes

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-01-14
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多