比如我有一条语句:
sq="select * from people where name=%s and age=%d ";
在Delphi中我可以这样处理
sq:=Format(sq,[QuotedStr('张三',20),]);
//因为传给SQL之后张三这个字符串必须加上单撇号,所以我调用了Delphi中的一个函数QuotedStr来执行这个操作
最后传到SQL Server后的语句变成
select * from people where name='张三' and age=20在C#中怎么处理?
使得 sq="select * from people where name={0} and age={1} ";
格式化之后变成
最后传到SQL Server后的语句变成
select * from people where name='张三' and age=20
sq="select * from people where name=%s and age=%d ";
在Delphi中我可以这样处理
sq:=Format(sq,[QuotedStr('张三',20),]);
//因为传给SQL之后张三这个字符串必须加上单撇号,所以我调用了Delphi中的一个函数QuotedStr来执行这个操作
最后传到SQL Server后的语句变成
select * from people where name='张三' and age=20在C#中怎么处理?
使得 sq="select * from people where name={0} and age={1} ";
格式化之后变成
最后传到SQL Server后的语句变成
select * from people where name='张三' and age=20
解决方案 »
- .NEt网络编程。报错:不支持此协议版本
- ListView有items添加或移除事件么?
- C#中汉字转十六进制和VB转十六进制转的不一样,下面是代码。
- 如何从一个文本文件读到另一个文本文件[同名]
- 高分求二维装箱算法!!!
- 用Graphics、Bitmap画的图像文件能打开修改吗? Graphics和Bitmap画的图能并保存为矢量图文件吗?
- menuStrip如何获得上一级菜单名??
- C# 使用 GIF 组件分解Gif图片时的问题
- 想实现记事本里的全文检索功能,不知道大家有没有好的办法?
- 大神快来啊,急急急
- 怎样在一个Form里对另外一个Form里的控件进行操作??
- 我有个登录form有个MainForm想在MainForm打开前,先打开登陆Form,但是我如何把登陆后的信息传给MainForm
我的SQL语句是拼凑的 最后直接传给SqlCommand执行 所以想使用C#里面的一些有关字符串格式化的功能 怎么用???
笨方法还有个
sq="select * from people where name={0} and age={1} ";
sq = sq.Replace("{0}","'张三'");
sq = sq.Replace("{1}","20");
之后也变了
select * from people where name='张三' and age=20
string tmp1=String.Format(tmp,"table1","where1");
this.Response.Write(tmp1);输出结果为
select * form table1 where where1
使得 sq="select * from people where name={0} and age={1} ";
格式化之后变成
最后传到SQL Server后的语句变成
select * from people where name='张三' and age=20