1

asp.net を使用する Web アプリケーションには、編集ボタンのあるグリッドビューがあります。このグリッドビューは、2 つのテーブルを結合して作成されます。これらの編集ボタンをクリックしたときに、これらの 2 つのテーブルを更新する必要があります。私のグリッドビューは、名前、nric、およびステータスの 3 つのフィールドで構成されています。両方のテーブルを更新するクエリはどうなりますか? 助けてください

 protected void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
{
    GridView1.EditIndex = -1;
}
protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
{
   GridView1.EditIndex = e.NewEditIndex;
}
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
    GridViewRow row = (GridViewRow)GridView1.Rows[e.RowIndex];

    TextBox id = (TextBox)row.FindControl("s_id");
    TextBox name = (TextBox)row.FindControl("s_name");
    TextBox nric = (TextBox)row.FindControl("s_nric");
    TextBox status = (TextBox)row.FindControl("s_status");
    SqlConnection con = obj.getcon(); 
    con.Open();
    SqlCommand cmd = new SqlCommand("update e.student_details ,f.student_vs_testsession_details  set e.student_id='" + id.Text+ "',e.student_name='" + name.Text + "',e.student_nric='" + nric.Text + "',f.testsession_status='" + status.Text + "' where e.student_id=f.student_id", con);
    cmd.ExecuteNonQuery();
    con.Close();


}
4

3 に答える 3

0

@Divya Hari: このタスクはストア プロシージャで実現できます。

 protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
 {
    GridViewRow row = GridView1.Rows[e.RowIndex];

    TextBox txtName = (TextBox)row.FindControl("txtName");
    TextBox txtstatus = (TextBox)row.FindControl("txtstatus");

    //     From here you can fire Update query on database.
    // Here you write code for store procedure.


 }

ストア プロシージャ。

 in SP you need to write update query for both table. Something like this.


 SET ANSI_NULLS ON
 GO
 SET QUOTED_IDENTIFIER ON
 GO
 CREATE PROCEDURE UpdateBothTable 
    @ID int,
    @Name varchar(50),
    @Status varchar(10)
 AS
 BEGIN
    -- SET NOCOUNT ON added to prevent extra result sets from
    -- interfering with SELECT statements.
    SET NOCOUNT ON;

     -- Insert statements for procedure here
    Update table1 set Name=@Name where ID=@ID

    Update Table2 set Status=@Status where ID=@ID


 END
 GO

これがあなたを助けることを願っています.... :)

于 2013-04-16T05:31:07.447 に答える
0

Divya、これは可能です。その時点で更新ボタンをクリックすると、gird変数は更新されたデータをデータベースに渡しますが、ここでは別の更新ステートメントを実行する必要があります。さらに質問がある場合はお知らせください....これを試してみてください....!

于 2013-04-16T04:49:03.803 に答える