一个SqlCommand 写法问题

skusk 2010-10-06 05:37:14
string a = Request.QueryString["v"].ToString();

//跟值
// SqlCommand mycom = new SqlCommand("update shipping_detail set carrier=Text.text() where container_id='" + a + "'", con);



这样写法有问题吗?
carrier=Text.text() 这个地方
...全文
88 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
superpxl 2010-10-06
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 yoyo_fan_503 的回复:]
string strText = Text.text();
SqlCommand mycom = new SqlCommand("update shipping_detail set carrier=" + strText + "
where container_id='" + a + "'", con);
[/Quote]

正解
wuyq11 2010-10-06
  • 打赏
  • 举报
回复
SqlCommand mycom = new SqlCommand("update shipping_detail set carrier=@carrier where container_id='" + a + "'", con);

SqlCommand mycom = new SqlCommand("update shipping_detail set carrier'"+变量+"' where container_id='" + a + "'", con);
troy2012 2010-10-06
  • 打赏
  • 举报
回复
应该用参数吧,用这个好像不太合适吧。
建议使用变量赋值比较好。
天下如山 2010-10-06
  • 打赏
  • 举报
回复
建议采用参数 而不是拼接字符串 !
yoyo_fan_503 2010-10-06
  • 打赏
  • 举报
回复
刚才上面的漏了引号

string strText = Text.text();
SqlCommand mycom = new SqlCommand("update shipping_detail set carrier='" + strText + "'
where container_id='" + a + "'", con);
yoyo_fan_503 2010-10-06
  • 打赏
  • 举报
回复
string strText = Text.text();
SqlCommand mycom = new SqlCommand("update shipping_detail set carrier=" + strText + "
where container_id='" + a + "'", con);
xxiaobirds 2010-10-06
  • 打赏
  • 举报
回复
可以这样写,里面的数据库字段我都默认为是varchar的了。
string a = Request.QueryString["v"].ToString();
SqlCommand mycom = new SqlCommand(String.Format("update shipping_detail set carrier='{0}'where container_id='{1}'",Text.text(),a), con);
skusk 2010-10-06
  • 打赏
  • 举报
回复
string strText = Text.text();
SqlCommand mycom = new SqlCommand("update shipping_detail set carrier="strText"
where container_id='" + a + "'", con);


这样吗?
yoyo_fan_503 2010-10-06
  • 打赏
  • 举报
回复
楼主一个贴都没结过……
yoyo_fan_503 2010-10-06
  • 打赏
  • 举报
回复
有问题的吧……。
string strText = Text.text();
"carrier=Text.text()" 改成 "strText"

111,129

社区成员

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

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

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