Microsoft Jet数据库引擎无法找到输入表或查询

时间:2013-01-28 10:49:49

标签: c# visual-studio-2008 oledb oledbconnection

我有一个小方法,基本上检查是否选中了复选框,或者在页面加载时取消选中。

但是,我确实得到了上面的错误消息,声明它找不到表'tblProducts',我觉得这很奇怪,因为数据库中存在表。 为什么我会得到这个OleDbException?

这就是我所做的。

public void checkedOrNot(CheckBox chk, string column, string table)
{
    string codevalue;
    Session["exeFilePath"] = Request.CurrentExecutionFilePath;
    using (OleDbConnection myOLEDBConn = new OleDbConnection(ConfigurationManager.AppSettings["conn"]))
    {
        bool value = false;

        codevalue = Request.QueryString["code"];
        myOLEDBConn.Open();
        OleDbCommand cmd = myOLEDBConn.CreateCommand();
        cmd.CommandText = "SELECT ['" + column + "'] FROM ['" + table + "'] WHERE [CODE] = '" + codevalue + "'";
        OleDbDataReader dbReader = cmd.ExecuteReader();
        if (dbReader.Read())
        {
            value = (bool)dbReader["" + column + ""];
        }
        if (value == true)
        {
            chk.Checked = true;
        }
        else
        {
            chk.Checked = false;
        }
    }

}


checkedOrNot(chkPreview, "PreviewLibraryChecked", "tblProducts");

问候

1 个答案:

答案 0 :(得分:1)

替换

cmd.CommandText = "SELECT ['" + column + "'] FROM ['" + table + "'] WHERE [CODE] = '" + codevalue + "'";

这一个

cmd.CommandText = "SELECT [" + column + "] FROM [" + table + "] WHERE [CODE] = '" + codevalue + "'";