0

我对下面的代码有一些问题。给我一个错误的是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();
}
4

1 回答 1

0

我没有看到您在代码中添加参数。你能添加参数并检查吗?喜欢,

OleDbCommand cmd = new OleDbCommand(<your sql query>, <your sql connection>);
cmd.Parameters.Add("order_no", OleDbType.Int);
cmd.Parameters["order_no"].Value = intOrderNo;
于 2012-07-03T23:31:13.460 回答