我在下面的代码中遇到了一些问题。给我一个错误的是rdr = cmd.ExecuteReader();
,我不明白为什么。该代码用于检查Items表中是否有任何记录。任何帮助将不胜感激。
protected void Page_Load(object sender, EventArgs e)
{
OleDbConnection mDB = new OleDbConnection();
mDB.ConnectionString = "Provider = Microsoft.Jet.OLEDB.4.0;Data source="
+ Server.MapPath("~/App_Data/Database.mdb");
OleDbCommand cmd;
OleDbDataReader rdr;
int intOrderNo = int.Parse(Session["sOrderNo"].ToString());
String strSql = "SELECT iProdID FROM Items WHERE iOrdersID = "+ intOrderNo;
cmd = new OleDbCommand(strSql, mDB);
mDB.Open();
rdr = cmd.ExecuteReader();
Boolean booRows = rdr.HasRows;
if (booRows)
{
ShoppingCartLabel.Text = "Your Shopping Cart";
if (Session["sFlag"] == "T")
{
BizCheckOutButton.Visible = true;
CusCheckOutButton.Visible = false;
}
else
{
BizCheckOutButton.Visible = false;
CusCheckOutButton.Visible = true;
}
}
else
{
ShoppingCartLabel.Text = "Your Shopping Cart is empty";
CusCheckOutButton.Visible = false;
BizCheckOutButton.Visible = false;
}
mDB.Close();
}
答案 0 :(得分:0)
我没有看到您在代码中添加参数。你能加点参数检查吗? 像,
OleDbCommand cmd = new OleDbCommand(<your sql query>, <your sql connection>);
cmd.Parameters.Add("order_no", OleDbType.Int);
cmd.Parameters["order_no"].Value = intOrderNo;