string.Format(@"select Station_ID from tbStation where Station_Name='{0}',"'";
string str="select Station_ID from tbStation where Station_Name='''";
string str="select Station_ID from tbStation where Station_Name=@name"; Parameter[] pa=new Parameter[]{new Parameter("@name",dbtype.string,20)}; pa[0].value=';
只有第三个才能传进去值。其他不行。。。为什么。怎么能成功用其他的 [最优解释] 这是因为'是转义字符,需要用''两个'表示一个',而第3种传参的方式是把'当成一个整体处理,不存在转义一说 1、正确写法 string.Format(@"select Station_ID from tbStation where Station_Name='{0}',"''");
2、正确写法 string str="select Station_ID from tbStation where Station_Name=''''";(其中中间两个'起到转义成一个'的作用 [其他解释] 以后提出问题时尽量不要写一个误导别人的问题然后又说“不可以这样写”(明明是你自己先这样表达的)。
string.Format(@"select Station_ID from tbStation where Station_Name='{0}', x.Replace("'","''");
[其他解释] 用你第三种方式就ok啊,还可以有效的防止sql注入 [其他解释]
可以这样写,关键是插入的时候。也不知道什么时候是’ 不能每次都这样写吧 [其他解释]
我最后的50分。。不能这么黄了 [其他解释]
string.Format(@"select Station_ID from tbStation where Station_Name='{0}', x.Replace("'","''"))