
C# 如何同时更新多个表中相同列,求高手解答
以下是代码:if(this.radioButton3.Checked){if(textBox5.Text==""||textBox6.Text==""||textBox7...
以下是代码:
if (this.radioButton3.Checked)
{
if (textBox5.Text == "" || textBox6.Text == "" || textBox7.Text == "")
{
MessageBox.Show("不允许有空项目,请重新填写");
return;
}
conn = new OleDbConnection(strconn);
conn.Open();
string strUpdt1 = "update GERENXINXI set NAME = '" + textBox6.Text + "',SFZ = '" + textBox5.Text + " ' , BMMC = ' " + textBox7.Text + " ' where NAME='" + textBox3.Text + " '";
string strUpdt2 = "update YANGLAOXINXI set NAME = '" + textBox6.Text + "',SFZ = '" + textBox5.Text + " ' where NAME='" + textBox3.Text + " '";
string strUpdt3 = "update SHIYEXINXI set NAME = '" + textBox6.Text + "',SFZ = '" + textBox5.Text + " ' where NAME='" + textBox3.Text + " '";
string strUpdt4 = "update YILIAOXINXI set NAME = '" + textBox6.Text + "',SFZ = '" + textBox5.Text + " ' where NAME='" + textBox3.Text + " '";
string strUpdt5 = "update SHENGYUXINXI set NAME = '" + textBox6.Text + "',SFZ = '" + textBox5.Text + " ' where NAME='" + textBox3.Text + " '";
string strUpdt6 = "update GONGSHANGXINXI set NAME = '" + textBox6.Text + "',SFZ = '" + textBox5.Text + " ' where NAME='" + textBox3.Text + " '";
string strUpdt7 = "update GJJXINXI set NAME = '" + textBox6.Text + "',SFZ = '" + textBox5.Text + " ' where NAME='" + textBox3.Text + " '";
comm = new OleDbCommand(strUpdt1 + strUpdt2 + strUpdt3 + strUpdt4 + strUpdt5 + strUpdt6 + strUpdt7, conn);
}
这样写 实现不了,求高手指教应该怎么写,非常感谢
在线等啊,大神快来 展开
if (this.radioButton3.Checked)
{
if (textBox5.Text == "" || textBox6.Text == "" || textBox7.Text == "")
{
MessageBox.Show("不允许有空项目,请重新填写");
return;
}
conn = new OleDbConnection(strconn);
conn.Open();
string strUpdt1 = "update GERENXINXI set NAME = '" + textBox6.Text + "',SFZ = '" + textBox5.Text + " ' , BMMC = ' " + textBox7.Text + " ' where NAME='" + textBox3.Text + " '";
string strUpdt2 = "update YANGLAOXINXI set NAME = '" + textBox6.Text + "',SFZ = '" + textBox5.Text + " ' where NAME='" + textBox3.Text + " '";
string strUpdt3 = "update SHIYEXINXI set NAME = '" + textBox6.Text + "',SFZ = '" + textBox5.Text + " ' where NAME='" + textBox3.Text + " '";
string strUpdt4 = "update YILIAOXINXI set NAME = '" + textBox6.Text + "',SFZ = '" + textBox5.Text + " ' where NAME='" + textBox3.Text + " '";
string strUpdt5 = "update SHENGYUXINXI set NAME = '" + textBox6.Text + "',SFZ = '" + textBox5.Text + " ' where NAME='" + textBox3.Text + " '";
string strUpdt6 = "update GONGSHANGXINXI set NAME = '" + textBox6.Text + "',SFZ = '" + textBox5.Text + " ' where NAME='" + textBox3.Text + " '";
string strUpdt7 = "update GJJXINXI set NAME = '" + textBox6.Text + "',SFZ = '" + textBox5.Text + " ' where NAME='" + textBox3.Text + " '";
comm = new OleDbCommand(strUpdt1 + strUpdt2 + strUpdt3 + strUpdt4 + strUpdt5 + strUpdt6 + strUpdt7, conn);
}
这样写 实现不了,求高手指教应该怎么写,非常感谢
在线等啊,大神快来 展开
4个回答
展开全部
string whereName = textBox3.Text;
string setName = textBox6.Text;
string sfz = textBox5.Text;
string BMMC = textBox7.Text;
OleDbConnection conn = new OleDbConnection(strconn);
conn.Open();
StringBuilder strSQL = new StringBuilder();
strSQL.AppendFormat(" update GERENXINXI set NAME ='{0}',SFZ='{1}',BMMC='{2}' WHERE NAME='{3}' ", setName, sfz, BMMC, whereName);
strSQL.AppendFormat(" update YANGLAOXINXI set NAME ='{0}',SFZ='{1}' WHERE NAME={2} ", setName, sfz, whereName);
strSQL.AppendFormat(" update SHIYEXINXI set NAME ='{0}',SFZ='{1}' WHERE NAME={2} ", setName, sfz, whereName);
strSQL.AppendFormat(" update YILIAOXINXI set NAME ='{0}',SFZ='{1}' WHERE NAME={2} ", setName, sfz, whereName);
strSQL.AppendFormat(" update SHENGYUXINXI set NAME ='{0}',SFZ='{1}' WHERE NAME={2} ", setName, sfz, whereName);
strSQL.AppendFormat(" update GONGSHANGXINXI set NAME ='{0}',SFZ='{1}' WHERE NAME={2} ", setName, sfz, whereName);
strSQL.AppendFormat(" update GJJXINXI set NAME ='{0}',SFZ='{1}' WHERE NAME={2} ", setName, sfz, whereName);
OleDbCommand comm = new OleDbCommand(strSQL.ToString(), conn);
更多追问追答
追问
大哥,这样还是不行啊,更新不了,更新之后还是原来的库
追答
你把生成的SQL 语句弄出来 。然后到数据库中执行。如果数据库中也不能 UPdate .看什么原因。是不是条件有错 。
展开全部
在你每个更新语句 string 的最后一个 “ 前面加上一个 ; 试试
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
你断点试试,都连成一个语句了
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
上面的代码段,每个AppendFormat中最后加个;否则ToString后是连起来的一行,当然出错
追问
按照 suqifeng2009 给的代码写了,每个AppendFormat后面都加了;,还是不行
追答
你只写一条UPDATE语句看看是否能执行成功
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询