0

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

但是,我确实收到了上述错误消息,指出它找不到表“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");

问候

4

1 回答 1

1

换行

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

有了这个

cmd.CommandText = "SELECT [" + column + "] FROM [" + table + "] WHERE [CODE] = '" + codevalue + "'";
于 2013-01-28T11:06:22.147 回答