string sql = "select * from Article where 1=1";if(BlogID!=0)sql+= " and BlogID = " + BlogID;
if(CategoryID!=0)sql+= " and CategoryID = " + CategoryID;
if(key!="")sql += " and (Subject like '%" + key + "%' or Content like '%" + key + "%'";
if(time!="")sql += " and [time] like '%" + time + "%'";sql += " order by ArticleID desc";第一行的where 1=1 是什么意思啊
if(CategoryID!=0)sql+= " and CategoryID = " + CategoryID;
if(key!="")sql += " and (Subject like '%" + key + "%' or Content like '%" + key + "%'";
if(time!="")sql += " and [time] like '%" + time + "%'";sql += " order by ArticleID desc";第一行的where 1=1 是什么意思啊
比如说,如果a=1,那么就是1=1咯,说明这条语句一定会被执行,如果a为1以外其他的数,比如是2,那么where 1=a就成了where 1=2,显然,这是不相等的,所以得出的结果就是空的咯,大概是这样吧.
===
if(BlogID!=0)sql+= " and BlogID = " + BlogID;
if(CategoryID!=0)sql+= " and CategoryID = " + CategoryID;
if(key!="")sql += " and (Subject like '%" + key + "%' or Content like '%" + key + "%'";
if(time!="")sql += " and [time] like '%" + time + "%'";如果不用“where 1=1”,你怎么知道上面的四个if中哪个该写上“where”呢?