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”类型的操作数
怎么解决?谢谢!!
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”类型的操作数
怎么解决?谢谢!!
输入字符串的格式不正确。
我的请求页这样写的:
list.aspx?id=5&nid=12
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"]);
list.aspx?id=5&nid=12
你这个值没传过来 if(""==nid.ToString()) 这样写比较好
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";
}
全部代码如下:
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();
或 if(Request.Params["nid"]==null) return;
这句如果Request.Params["nid"]没获取到,这句就报错了
应该把判断提到这里来做
if(Request.Params["nid"]!=null) nid = System.Convert.ToInt32(Request.Params["nid"]);