DataRoutines不在Access数据库中创建数据

时间:2013-07-27 07:06:25

标签: c# asp.net session ms-access

今天,我正在尝试使用DataRoutines将一些值插入到我的Access数据库中。但是,它没有工作,因为没有创建记录。有谁知道我的代码出了什么问题?

这是我的DataRoutines(dataroutines2)文件

 public void CreateRecs(string strUserId)
{
    OleDbConnection mDB = new OleDbConnection();
    mDB.ConnectionString = "Provider = Microsoft.ACE.OLEDB.12.0;Data source="
        + Server.MapPath("~/App_Data/webBase.accdb");
    OleDbCommand cmd; OleDbDataReader rdr;
    string strSql;
    string strOFlag = "F";
    // check to see if there is an active order record
    strSql = "SELECT eStatus FROM enrolInfo WHERE eUserId = @UserId "
       + "ORDER BY eEnrolNo DESC;";
    cmd = new OleDbCommand(strSql, mDB);
    cmd.Parameters.Add("@UserId", OleDbType.Char).Value = strUserId;
    mDB.Open();
    rdr = cmd.ExecuteReader();
    Boolean booRows = rdr.HasRows;
    if (booRows) //when booRows is true, there are order records for the user
    {
        rdr.Read();
        if ((string)rdr["eStatus"] != "Ordering") //status of an active order is "Ordering"
        {
            strOFlag = "M"; //"T" means there is a need to create a new Orders record
        }
        else { strOFlag = "M"; }
        mDB.Close();
        if (strOFlag == "M")
        {
            //insert a new order record
            string strStatus = "Ordering";
            strSql = "INSERT INTO enrolInfo (eUserId, eStatus) VALUES (@UserId, @Status)";
            cmd = new OleDbCommand(strSql, mDB);
            cmd.Parameters.AddWithValue("@UserId", strUserId);
            cmd.Parameters.AddWithValue("@Status", strStatus);
            mDB.Open();
            cmd.ExecuteNonQuery();
            mDB.Close();
        }

        //get back order No - this order no is needed when the user buys an item
        strSql = "SELECT eEnrolNo FROM enrolInfo WHERE eUserId = @UserId "
            + "ORDER BY eEnrolNo DESC;";
        cmd = new OleDbCommand(strSql, mDB);
        cmd.Parameters.Add("@UserId", OleDbType.Char).Value = strUserId;
        mDB.Open();
        rdr = cmd.ExecuteReader();
        rdr.Read();
        Session["tOrderNo"] = rdr["eEnrolNo"]; //store the active order no in the sOrderNo
        mDB.Close();
        return;

    }
}

这是将解决方案路由到我的Register Page

中的DataRoutines文件的代码
               //prepare Session variables for newly register customer
            Session["sFlag"] = "M";
            Session["tUserId"] = (string)txtUserId.Text;
            Session["tName"] = (string)txtName.Text;
            Session["tAddress"] = (string)txtAddress.Text;
            Session["tTel"] = (string)txtTel.Text;
            Session["tEmail"] = (string)txtEmail.Text;
            String strUserId = (string)Session["tUserId"];
            DataRoutines2 DRObject = new DataRoutines2();
            DRObject.CreateRecs(strUserId);

感谢您的帮助

0 个答案:

没有答案