首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

怎么对SqlDataAdapter的返回值进行判断

2012-09-20 
如何对SqlDataAdapter的返回值进行判断?protected void btnselect_Click(object sender, EventArgs e){Sql

如何对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 { 
//没值
}

热点排行