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();
}
ASP.net修改多个关联的表中的某个字段的值的SQL语句是怎么写?
答案:2 悬赏:70 手机版
解决时间 2021-12-26 04:18
- 提问者网友:
- 2021-12-25 16:02
最佳答案
- 五星知识达人网友:未来江山和你
- 2021-12-25 16:46
要先修改assessment表中的值,再修改department表中的值,try下,出错回滚事务,至于触发器是要在数据库中先建好的sqlserver中有级联删除和级联修改
全部回答
- 1楼网友:廢物販賣機
- 2021-12-25 16:53
这个 错误很明显呀,就是你的sql语句有问题。
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯