读书人

一个简单得吓死你的有关问题

发布时间: 2013-08-01 15:23:18 作者: rapoo

一个简单得吓死你的问题。
在.net 环境下(我用的是vb,估计c#也差不多。)
怎样用多行来描述一个字符段。

比如
dim a as string
a="select *
from xxxx as a
where xxxxx
"

原因就是我要写sql语句,如果不用多行来写,可读性太差。



[解决办法]


//是这样么
string a="";
a+="select * from xxxx as a ";
a+="where xxxxx ";

[解决办法]
using System.Text;

StringBuilder str = new StringBuilder();
str.Append("1");
str.Append("2");

str.ToString()
[解决办法]
引用:
Quote: 引用:


//是这样么
string a="";
a+="select * from xxxx as a ";
a+="where xxxxx ";




我的意思是,一个字符串的赋值命令能分成几行来写吗,只要在他每行的后面加上一个什么继续的符号,
让他知道下一行仍然是这个字符串的一部分。
主要是想让我的sql语句可读性高一点,不是字符串的合并。




string s = @"select *
from xxxx as a
where xxxxx";

string s = "select * " +
"from xxxx as a"
+ "where xxxxx";


[解决办法]

"aaaa" _
& "bbbb" _
& "cccc"

------解决方案--------------------


var strSql = @"select *
from abc
where .....
order by...";

读书人网 >C#

热点推荐