C#中 sb.Append(" 能具体说说嘛?
来源:学生作业帮助网 编辑:作业帮 时间:2024/06/18 16:40:59
![C#中 sb.Append(](/uploads/image/z/12794496-24-6.jpg?t=C%23%E4%B8%AD+sb.Append%28%22+%E8%83%BD%E5%85%B7%E4%BD%93%E8%AF%B4%E8%AF%B4%E5%98%9B%3F)
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