帮帮忙~

ziqiao_1988 2009-12-14 10:21:41
private void btnAdd_Click(object sender, EventArgs e)
{
SqlConnection conn =new SqlConnection("Data Source=JIAO\\SQL2005;Initial Catalog=SalaryMS;User ID=sa;pwd=123");
conn.Open();
string insertSql = "insert into users where userName="+textBox1.Text+"";
SqlCommand comm = new SqlCommand(insertSql,conn);
int updCount = comm.ExecuteNonQuery();
conn.Close();
}

提示异常:where子句附近有错误
...全文
63 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
我姓区不姓区 2009-12-14
  • 打赏
  • 举报
回复
提高你的结贴率
ziqiao_1988 2009-12-14
  • 打赏
  • 举报
回复
错误改了,谢啦!
我姓区不姓区 2009-12-14
  • 打赏
  • 举报
回复
看错了,楼主是要insert啊……那value呢?
string insertSql = "insert into users(userName) values('"+textBox1.Text+"')";
wuyq11 2009-12-14
  • 打赏
  • 举报
回复
string insertSql = "insert into users where userName='"+textBox1.Text.Replace("'","''")+"'";
pt1314917 2009-12-14
  • 打赏
  • 举报
回复

string insertSql = "insert into users where userName="+textBox1.Text+"";
------
insert into users where username=某值

这是个什么SQL语句,楼主你到底想干嘛?到底是插入还是干什么?
sirBUAA 2009-12-14
  • 打赏
  • 举报
回复
UP
我姓区不姓区 2009-12-14
  • 打赏
  • 举报
回复
单引号少了
string insertSql = "insert into users where userName='"+textBox1.Text+"'";
lijing3333 2009-12-14
  • 打赏
  • 举报
回复
......差字段...汗...表不能随便插得....

111,120

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Creator Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

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