在我使用 asp.net 的 Web 应用程序中,我有一个带有编辑按钮的 gridview。此网格视图是通过连接两个表创建的。当我单击那些编辑按钮时,我需要更新这两个表。我的网格视图包含 3 个字段 - 名称、nric 和状态。其中表 1 中的名称和 nric 以及表 2 中的状态。更新两个表的查询将如何?请帮忙
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();
}