请问个数据库update的问题

笨蚂蚱 2017-01-05 09:06:49
update 表 set name="a",age="b" where id=100
就是这样的查询语句

用 '" + 变量 + "' 这样传递变量就没问题

用 string.format("update 表 set name = {0} , age = {1} where id ={2}", a b ,c)
要花5分钟才能更新完数据
请问下这是什么原因呢?
...全文
80 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
笨蚂蚱 2017-01-05
  • 打赏
  • 举报
回复
感谢各位 加了引号解决了 哈哈
  • 打赏
  • 举报
回复
引用 2 楼 Chinajiyong 的回复:
[quote=引用 1 楼 xiaoguidangjiajia 的回复:] string.format()和string + string效果是一样的,和update根本没有关系 另外一个问题,name和age为字符串,好歹加上引号吧: string.format("update 表 set name =‘{0}‘ , age = ‘{1}‘ where id ={2}", a b ,c)
string.format("update 表 set name =‘{0}‘ , age = {1} where id ={2}", a b ,c) 字符串(nvarchar或者varchar)要加单引号‘’,int的不用加[/quote] string.format("update 表 set name =‘{0}‘ , age = {1} where id ={2}", a, b ,c) ;
闭包客 2017-01-05
  • 打赏
  • 举报
回复
只执行一个 SQL 语句,还是循环执行?
小鬼当家家 2017-01-05
  • 打赏
  • 举报
回复
引用 2 楼 Chinajiyong 的回复:
[quote=引用 1 楼 xiaoguidangjiajia 的回复:] string.format()和string + string效果是一样的,和update根本没有关系 另外一个问题,name和age为字符串,好歹加上引号吧: string.format("update 表 set name =‘{0}‘ , age = ‘{1}‘ where id ={2}", a b ,c)
string.format("update 表 set name =‘{0}‘ , age = {1} where id ={2}", a b ,c) 字符串(nvarchar或者varchar)要加单引号‘’,int的不用加[/quote] 楼主第一句就写的update 表 set name="a",age="b" where id=100 名摆着age是字符串啊
shoppo0505 2017-01-05
  • 打赏
  • 举报
回复
string.format出来后的语句和手工format的对比下,我觉得可能id=...这块可能出现偏差了
EnForGrass 2017-01-05
  • 打赏
  • 举报
回复
引用 1 楼 xiaoguidangjiajia 的回复:
string.format()和string + string效果是一样的,和update根本没有关系 另外一个问题,name和age为字符串,好歹加上引号吧: string.format("update 表 set name =‘{0}‘ , age = ‘{1}‘ where id ={2}", a b ,c)
string.format("update 表 set name =‘{0}‘ , age = {1} where id ={2}", a b ,c) 字符串(nvarchar或者varchar)要加单引号‘’,int的不用加
小鬼当家家 2017-01-05
  • 打赏
  • 举报
回复
string.format()和string + string效果是一样的,和update根本没有关系 另外一个问题,name和age为字符串,好歹加上引号吧: string.format("update 表 set name =‘{0}‘ , age = ‘{1}‘ where id ={2}", a b ,c)

110,524

社区成员

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

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

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