我有一个小方法,基本上检查是否选中了复选框,或者在页面加载时取消选中。
但是,我确实得到了上面的错误消息,声明它找不到表'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");
问候
答案 0 :(得分:1)
替换
行cmd.CommandText = "SELECT ['" + column + "'] FROM ['" + table + "'] WHERE [CODE] = '" + codevalue + "'";
这一个
cmd.CommandText = "SELECT [" + column + "] FROM [" + table + "] WHERE [CODE] = '" + codevalue + "'";