id = System.Convert.ToInt32(Request.Params["id"]);
         nid = System.Convert.ToInt32(Request.Params["nid"]);
         if (nid=="" )
         {
             string sql = "select * from info where classid=" + id + "order by id desc";
         }
         else
         {
             string sql = "select * from info where classid=" + id + "and nclassid=" + nid + " order by id desc";
         }
提示:
CS0019: 运算符“==”无法应用于“int”和“string”类型的操作数
怎么解决?谢谢!!

解决方案 »

  1.   

    if (nid.ToString()=="" )
      

  2.   

    if (Request.Params["nid"] != null && int.TryParse(Request.Params["nid"], out nid))
      

  3.   

    提示:
    输入字符串的格式不正确。 
    我的请求页这样写的:
    list.aspx?id=5&nid=12
      

  4.   

    id = System.Convert.ToInt32(Request.Params["id"]);
      nid = System.Convert.ToInt32(Request.Params["nid"]);
      if (nid.ToString()=="" )
      {
      string sql = "select * from info where classid=" + id + "order by id desc";
      }
      else
      {
      string sql = "select * from info where classid=" + id + "and nclassid=" + nid + " order by id desc";
      }
    or
    string id =Request.Params["id"]==null?0:Convert.ToInt32(Convert.Request.Params["id"]);
      

  5.   

    真是...一个整数怎么ToString都不可能是 "" 吧...
      

  6.   


    list.aspx?id=5&nid=12 
    你这个值没传过来 if(""==nid.ToString())  这样写比较好
      

  7.   

    id = System.Convert.ToInt32(Request.Params["id"]);
    int nid = 0;
    if (Request.Params["nid"] == null)
    {
        nid = 0;
    }
    else
    {
        nid = System.Convert.ToInt32();
    }
    if (nid > 0)
    {
        string sql = "select * from info where classid=" + id + "order by id desc";
    }
    else
    {
        string sql = "select * from info where classid=" + id + "and nclassid=" + nid + " order by id desc";
    }
      

  8.   

    还是不行啊?
    全部代码如下:
     string sql;
             id = System.Convert.ToInt32(Request.Params["id"]);
             nid = System.Convert.ToInt32(Request.Params["nid"]);
             if (nid.ToString() == "")
             {
                  sql = "select * from info where classid=" + id + "order by id desc";
             }
             else
             {
                  sql = "select * from info where classid=" + id + "and nclassid=" + nid + " order by id desc";
             }
            DataView dv = DB.getdataset(sql).Tables[0].DefaultView;
            PagedDataSource pds = new PagedDataSource();        AspNetPager1.RecordCount = dv.Count;
            pds.DataSource = dv;
            pds.AllowPaging = true;
            pds.CurrentPageIndex = AspNetPager1.CurrentPageIndex - 1;
            pds.PageSize = AspNetPager1.PageSize;
            this.DataList2.DataSource = pds;
            this.DataList2.DataBind();
      

  9.   

    nid.ToString() == "" 永远都是 false ,这么简单的问题都没看出来...
      

  10.   

    nid = System.Convert.ToInt32(Request.Params["nid"]);传入参数不为数字,就有异常, if (nid=="" ) 这句是多余的了应为:if (nid>0 )
      
     或 if(Request.Params["nid"]==null) return;
      

  11.   

    我跟踪了一下,发现有 nid = System.Convert.ToInt32(Request.Params["nid"]);这一句就提示输入字符串的格式不正确。
      

  12.   

    nid = System.Convert.ToInt32(Request.Params["nid"]);
    这句如果Request.Params["nid"]没获取到,这句就报错了
    应该把判断提到这里来做
    if(Request.Params["nid"]!=null)  nid = System.Convert.ToInt32(Request.Params["nid"]);