日期:2014-05-19  浏览次数:20501 次

查询结果为空时候怎么给出提示?????
User.cs页面里有
public   DataSet   getDataSet(string   SQLQuery)
{
SqlDataAdapter   da   =   new   SqlDataAdapter(SQLQuery,connStr);
DataSet   ds   =   new   DataSet();
da.Fill(ds);
da.Dispose();
da   =   null;
return   ds;
}

调用时候:


private   void   Bind(string   strModel,string   strColor)
{
User   user=new   User();
string   sql= "   select   *   from   ********* ";
this.DataList1.DataSource=user.getDataSet(sql);
this.DataList1.DataBind();
}


我想问的是,如果查询的结果为0的话,怎么来在页面上显示“没有您想要的结果”,这样的提示呢???



------解决方案--------------------
我是这样做的
if(user.getDataSet(sql).tables[0].rows.count==0)
{
label.text = "No results! ";
label.visible = true;
datalist.visible = false;
}
else
{
this.DataList1.DataSource=user.getDataSet(sql);
this.DataList1.DataBind();
label.visible = false;
datalist.visible = true;


}

但是,这样做,不管有没有结果,这个提示都存在!!!

------解决方案--------------------
DataSet ds = user.getDataSet(sql);
if(ds.Tables[0].Rows.Count > 0)
{
label1.Visible = false;
this.DataList1.DataSource = ds;
this.DataList1.DataBind();
}
else
{
label1.Visible = true;
label1.Text = "Empty ";
}