我不确定为什么代码不起作用。 如果rStatus = Reserve显示预订详细信息 如果rStatus = cancel show label.text和以下
什么不起作用: 当我进入例如的页面时。 user =“ben12”此用户已预订但未显示预订而是显示用户没有预订,如果用户预订状态被取消将会发生。
我已经进一步检查了在user =“ben12”下它有几个取消和保留状态,我不确定这是否是if语句不起作用的原因
此代码位于我的Reservation.aspx.cs的Page_Load
下
OleDbConnection mDB = new OleDbConnection();
mDB.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data source="
+ Server.MapPath("~/App_Data/IESDatabase.accdb");
OleDbCommand cmd;
OleDbDataReader rdr;
string strUserId = (string)Session["sUserId"];
string strSql = "SELECT rStatus FROM Reservation WHERE rUserId = @UserId "
+ "ORDER BY rStatus DESC;";
cmd = new OleDbCommand(strSql, mDB);
mDB.Open();
rdr = cmd.ExecuteReader();
rdr.Read();
Session["rsStatus"] = rdr["rStatus"]; // store the current status
mDB.Close();
if ((string)Session["srStatus"] == "Cancelled")
{
DetailsView1.Visible = false;
Label2.Visible = false;
btnBuy.Visible = false;
DropDownList1.Visible = false;
btnCancel.Visible = false;
lblReserve.Text = "There is no resevation for user " + Session["sUserId"];
}
if ((string)Session["srStatus"] == "Reserve")
{
lblReserve.Visible = false;
Label1.Visible = true;
Label2.Visible = true;
DetailsView1.Visible = true;
btnBuy.Visible = true;
DropDownList1.Visible = true;
btnCancel.Visible = true;
}
答案 0 :(得分:0)
问题是你的会话名称,在这里:
Session["rsStatus"] = rdr["rStatus"]; // store the current status
它应该是 srStatus