ASP.net修改多个关联的表中的某个字段的值的SQL语句是怎么写?
department表:depid、department、depinfo;主键是depidassessment表:assid、staname、department;主键是...
department表:depid、department、depinfo;主键是depid
assessment表:assid、staname、department;主键是assid。这两个表的department字段值是关联的。我想要修改主表department的department的值时,怎么实现同步修改assessment的该字段值?假如用触发器又怎么写?
下面是一段代码:
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{//更新
string id =GridView1.DataKeys[e.RowIndex].Value.ToString();//获取主键值
string depid = ((TextBox)GridView1.Rows[e.RowIndex].Cells[0].Controls[0]).Text;//部门编号
string depname = ((TextBox)GridView1.Rows[e.RowIndex].Cells[1].Controls[0]).Text;//部门名称
string num =((TextBox)GridView1.Rows[e.RowIndex].Cells[2].Controls[0]).Text;//部门人数
string info=((TextBox)GridView1.Rows[e.RowIndex].FindControl("TextBox1")).Text;//获取部门简介
string sqlUpdate = "update department set depid='" + depid + "',department='" + depname + "',depcount='" + num + "',depinfo='" + info + "' where depid='" + id + "'";
myc.sqlUpdate(sqlUpdate);//执行修改
GridView1.EditIndex = -1;
getDepartment();
} 展开
assessment表:assid、staname、department;主键是assid。这两个表的department字段值是关联的。我想要修改主表department的department的值时,怎么实现同步修改assessment的该字段值?假如用触发器又怎么写?
下面是一段代码:
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{//更新
string id =GridView1.DataKeys[e.RowIndex].Value.ToString();//获取主键值
string depid = ((TextBox)GridView1.Rows[e.RowIndex].Cells[0].Controls[0]).Text;//部门编号
string depname = ((TextBox)GridView1.Rows[e.RowIndex].Cells[1].Controls[0]).Text;//部门名称
string num =((TextBox)GridView1.Rows[e.RowIndex].Cells[2].Controls[0]).Text;//部门人数
string info=((TextBox)GridView1.Rows[e.RowIndex].FindControl("TextBox1")).Text;//获取部门简介
string sqlUpdate = "update department set depid='" + depid + "',department='" + depname + "',depcount='" + num + "',depinfo='" + info + "' where depid='" + id + "'";
myc.sqlUpdate(sqlUpdate);//执行修改
GridView1.EditIndex = -1;
getDepartment();
} 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询