为什么数据不能更新。。。。。?答对给分。。。。

qaqaqa 2001-11-11 08:48:48
private void button1_Click(object sender, System.EventArgs e)
{
this.oleDbConnection1.Open ( ) ;
// 打开数据连接oleDbCommand1.CommandText
string udstr="UPDATE Persons set name='"
+textBox2.Text+"', HomePhone='"
+textBox3.Text+"', WorkPhone='"
+textBox4.Text+"', City='"
+textBox5.Text+"',Address='"+textBox6.Text+"',Email='"+textBox7.Text+"' WHERE (id="+textBox1.Text+")";
//string newstr="update persons set name="+textBox2.Text+" where id ="+textBox1.Text+"";
OleDbCommand cmd = new OleDbCommand (udstr, oleDbConnection1) ;
this.oleDbConnection1.Close();
MessageBox.Show("数据存储成功!"+udstr,"系统提示:");
}
...全文
80 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
netcar 2001-11-23
  • 打赏
  • 举报
回复
arfeiz(凌飞)说的有道理,改为如下:
WHERE (id='"+textBox1.Text+"')" //单引号将textBox1.Text括起
doubleclick 2001-11-15
  • 打赏
  • 举报
回复
要执行cmd.ExecuteNonQuery方法才可以的
arfeiz 2001-11-15
  • 打赏
  • 举报
回复
如果没有忘记cmd.execute,那么建议检查WHERE子句:WHERE (id="+textBox1.Text+")"
iambusy 2001-11-13
  • 打赏
  • 举报
回复
好像cmd没有execute

1,979

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 其他语言讨论
社区管理员
  • 其他语言社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧