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;