简体   繁体   中英

rdr = cmd.ExecuteReader() giving Data type mismatch in criteria expression

I have some problems with the codes below. The one that is giving me an error is rdr = cmd.ExecuteReader(); and I have no idea why. The code is suppose to check if there is any records in the Items table. Any help would be appreciated.

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();
}

I don't see you adding parameters in your code. Can you please add parameters and check? Like,

OleDbCommand cmd = new OleDbCommand(<your sql query>, <your sql connection>);
cmd.Parameters.Add("order_no", OleDbType.Int);
cmd.Parameters["order_no"].Value = intOrderNo;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM