0

下面的代码来自res.aspx.cs 我无法从该代码行导致我的错误的字段中读取任何内容:

  strStatus = rdr["rStatus"].ToString();

protected void Page_Load(object sender, EventArgs e)
        {

                OleDbConnection mDB = new OleDbConnection();
                mDB.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data source="
                + Server.MapPath("~/App_Data/Database.accdb");
                OleDbCommand cmd; OleDbDataReader rdr;
                string strUserId = (string)Session["sUserId"];
                string strStatus;
                string strSql = "SELECT rStatus FROM Reservation WHERE rUserId =" + strUserId
               + " ORDER BY rStatus DESC;";
                cmd = new OleDbCommand(strSql, mDB);
                cmd.Parameters.Add("@UserId", OleDbType.Char).Value = strUserId;
                mDB.Open();
                rdr = cmd.ExecuteReader();
                strStatus = rdr["rStatus"].ToString();
            while (rdr.Read() == true)




                //  string strRStatus = (string)Session["srStatus"];
                //   while (rdr.Read() == true) 

                if (strStatus == "-1")
                {


                    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"];

                }
                else
                {
                    lblReserve.Visible = false;
                    Label1.Visible = true;
                    Label2.Visible = true;
                    DetailsView1.Visible = true;
                    btnBuy.Visible = true;
                    DropDownList1.Visible = true;
                    btnCancel.Visible = true;

                }
            }
4

1 回答 1

4

尝试移动

strStatus = rdr["rStatus"].ToString();

在你打电话后

rdr.Read()

编辑:如果要读取 SQL 位值,可以使用GetBoolean阅读器上的方法:

bool myBoolean;
if (!rdr.IsDBNull(columnIndex))
    myBoolean = rdr.GetBoolean(columnIndex);
于 2013-01-19T16:50:42.613 回答