C#中 sb.Append(" 能具体说说嘛?

来源:学生作业帮助网 编辑:作业帮 时间:2024/05/07 19:49:39
C#中 sb.Append(

C#中 sb.Append(" 能具体说说嘛?
C#中 sb.Append(" 能具体说说嘛?

C#中 sb.Append(" 能具体说说嘛?
你这个sb是一个SQL语句吗?如果是sql语句的话·你加上 sb.Append(" 1=1")应该是 永真的意思.
select * from a where 1=1
当where 后面的条件不确定会出现多少个的时候一般是可以考虑在后面加上一个 1=1 永真的

StringBuilder sb= new StringBuilder("select * from a where ");
if(id!="")
sb.Append(" id='1' and ");
if(name!="")
sb.Append(" name='小明' and ");
sb.Append(" 1=1 ");
上面这里如果不加上
sb.Append(" 1=1 ");
那么sb = select * from a where id = 1 and name = '小明' and
很明显这语法就会出现问题.
但加上sb.Append(" 1=1 ");
那么sb = select * from a where id = 1 and name = '小明' and 1=1