日期:2014-05-17  浏览次数:20397 次

如何对SqlDataAdapter的返回值进行判断?
protected void btnselect_Click(object sender, EventArgs e)
  {
  SqlConnection con = DB.createDB();
  con.Open();
  if (this.RadioButton1.Checked == true)
  {
  if (this.TextBox1.Text != "")//选中了其中第一个rediobutton
  {
  this.TextBox2.Text = "";
  SqlCommand cmd = new SqlCommand();
  DataSet ds = new DataSet();
  SqlDataAdapter sda = new SqlDataAdapter("select * from tb_Users where UserId=" + this.TextBox1.Text + "", con);
  想在这里对sda返回值进行判断,如果没查到,就用java脚本输出“对不起没查到用户!”
  请高手赐教教!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!




   
  sda.Fill(ds, "tb_Users");
  this.GridView1.DataSource = ds;
  this.GridView1.DataBind();
  }
  if (this.TextBox1.Text == "")
  {
  Response.Write("<script>alert('用户编号不能为空!');location='javascript:history.go(-1)'</script>");
  }

  }

------解决方案--------------------
SqlDataAdapter ad = new SqlDataAdapter();
DataSet ds = new DataSet();
ad.Fill(ds);
if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
{
//有值
}
else { 
//没值
}