3.22学习理解httpContext与where 1=1

1、HttpContext
HttpContext.Current.Session.RemoveAll();从会话状态集合中移除所有的键和值。(未过期,还存在)
HttpContext.Current.Session.Abandon();?//清空当前所有的Session (已过期)
2、where 1 = 1
where条件中1=1之后的条件是通过if块动态变化的。例如:
String sql="select * from table_name where 1=1";
if(conditon1)
    {
sql=sql+"andvar2=value2";
}
if(conditon2)
    {
sql=sql+"andvar3=value3";
}
where 1=1 是为了避免where 关键字后面的第一个词直接就是“and”而导致语法错误。1=1永真条件,一般用于构造动态SQL语句,"SELECT...FROM...WHERE 1=1"+动态构造条件子句。

posted @ 2016-03-22 17:37  寒夜美美  阅读(143)  评论(0编辑  收藏  举报