VS C# 使用UPTATE 时出错了。请高手帮忙看一下哪里出问题拉

来源:百度知道 编辑:UC知道 时间:2024/05/24 18:19:46
sbFriends.Groups[1].Items.Add(sbFriends.SeletedItem);

sbFriends.Groups[0].Items.Remove(sbFriends.SeletedItem);

string sqla = string.Format("update friend set stranger={0},friendid={1} where hostid={2} and friendid={0}",id,null,Idinformation.id);

SqlCommand commandd = new SqlCommand(sqla, DBHelper.connection);
DBHelper.connection.Open();
int result = commandd.ExecuteNonQuery();
if (!(result < 1))
{
MessageBox.Show("添加成功");
}
DBHelper.connection.Close();

提示说 关键值 where附近有语法错误。。我郁闷了 难道不能用 null

如果是 那应该怎么 设置数据为 null呢 ?

改成下面的,加引号当成字符串传进去
string sqla = string.Format("update friend set stranger={0},friendid={1} where hostid={2} and friendid={0}",id,"null",Idinformation.id);

你上面的sql语句将生成类似下面的语句
update friend set stranger=1,friendid= where hostid=2 and friendid=1

是不是有明显的错误,你可以调试看看

一楼 二楼都正解 看来我又只能混分了

其实null可以直接写 ''