日期:2014-05-16  浏览次数:20745 次

求助,当CLASSID=0时,调不出来头部
这是作为所有列表栏目的头部文件,当CLASSID=分类ID时,一切正常,但分类“全部”,就是CLASSID=0时,sys_head为空白,这是什么原因,我是新手,请大神们指点一下写法,万分感谢。

public static string sys_head()
        {


            StringBuilder builder = new StringBuilder();
            int num2 = TypeParse.ToInt<string>(pagebase.Get("cid"));
            using (IDataReader reader = Conn.ExecuteReader("select * from ov_class where id = '" + num2 + "'"))
            {
                while (reader.Read())
                {

                    builder.Append("<title>" + reader["classname"] + " </title>\r");
                    builder.Append("<meta name=\"keywords\" content=\"$$ov_sitekeyword$$\"/>\r");
                    builder.Append("<meta name=\"description\" content=\"$$ov_sitedescription$$\"/>\r");

                    builder.Append("<noscript>您的浏览器禁用了脚本运行,请打开脚本在尝试!</noscript>");

                }
            }



            return builder.ToString();

        }
------解决方案--------------------
判断一下即可

string sql=select * from ov_class;
if(num2 >0)
    sql+= " where id = '" + num2 + "'"

using (IDataReader reader = Conn.ExecuteReader(sql))