0

私は新しいメンバーです。また、レコードを 2 つの異なるテーブル (顧客情報と学生情報) に追加しようとしています。私のコードは以下にありますが、テキストボックスフィールドを StudentInfo テーブルにのみ記録します。レコードを2つのテーブルに同時に入れるにはどうすればよいですか?

ありがとう

 protected void btnRegister_Click(object sender, EventArgs e)
    {
        OleDbConnection mDB = new OleDbConnection();
        mDB.ConnectionString = "Provider = Microsoft.ACE.OLEDB.12.0;Data source="
            + Server.MapPath("~/App_Data/webBase.accdb");
        mDB.Open();
        Type csType = this.GetType();
        //check to ensure that UserId keyed in is not being used by other Customers
        OleDbCommand cmd;
        OleDbCommand cmd1;
        OleDbDataReader rdr;
        OleDbDataReader rdr1;

        string strSQLSelect = "SELECT sUserId FROM studentInfo ORDER BY sUserId";
        string strSQLSelect1 = "SELECT cUserId FROM customerInfo ORDER BY cUserId";
        cmd1 = new OleDbCommand(strSQLSelect1, mDB);
        cmd = new OleDbCommand(strSQLSelect, mDB);
        rdr = cmd.ExecuteReader();
        rdr1 = cmd1.ExecuteReader();
        this.txtPassword.Attributes.Add("value", this.txtPassword.Text);

 // insert new record 
                string strSQLInsert = "INSERT INTO "
                + "studentInfo (sUserId,sPassword,sName,sAddress,sTel,sEmail,sLevel, sLevel2)"
                + "VALUES(@uid,@pw,@name,@addr,@em,@tel,@lvl,@lvl2)";
                ClientScript.RegisterStartupScript(csType, "Successful!", scriptSuccessNewAccount);
                cmd = new OleDbCommand(strSQLInsert, mDB);
                cmd.Parameters.AddWithValue("@uid", txtUserId.Text);
                cmd.Parameters.AddWithValue("@pw", txtPassword.Text);
                cmd.Parameters.AddWithValue("@name", txtName.Text);
                cmd.Parameters.AddWithValue("@addr", txtAddress.Text);
                cmd.Parameters.AddWithValue("@em", txtEmail.Text);
                cmd.Parameters.AddWithValue("@tel", txtTel.Text);
                cmd.Parameters.AddWithValue("@lvl", DropDownList1.Text);
                cmd.Parameters.AddWithValue("@lvl2", DropDownList2.Text);




                string strSQLInsert1 = "INSERT INTO "
    + "customerInfo (cUserId,cPassword,cName,cAddress,cEmail,cTel,cCountry)"
    + "VALUES(@uid,@pw,@name,@addr,@em,@tel,@country)";
                ClientScript.RegisterStartupScript(csType, "Successful!", scriptSuccessNewAccount);
                cmd1 = new OleDbCommand(strSQLInsert1, mDB);
                cmd1.Parameters.AddWithValue("@uid", txtUserId.Text);
                cmd1.Parameters.AddWithValue("@pw", txtPassword.Text);
                cmd1.Parameters.AddWithValue("@name", txtName.Text);
                cmd1.Parameters.AddWithValue("@addr", txtAddress.Text);
                cmd1.Parameters.AddWithValue("@em", txtEmail.Text);
                cmd1.Parameters.AddWithValue("@tel", txtTel.Text);
                cmd1.Parameters.AddWithValue("@country", txtCountry.Text);

                cmd.ExecuteNonQuery();
                mDB.Close();
4

1 に答える 1

1

行方不明のようです

cmd1.ExecuteNonQuery()

他のテーブルのために。

于 2013-07-25T14:54:34.590 に答える