DBNull和没有找到数据是两回事,你这么做不科学。

解决方案 »

  1.   

    to: cnuninet(玉树临风胜潘安)
    还请提示
      

  2.   

    如果用 datareader, if (!da.Read())
    {
      Response.Write("No Data Found");
    }如果用 dataset,if (ds.Tables["table1"].Rows.Count == 0)
    {
      Response.Write("No Data Found");
    }
      

  3.   

    DataSet ds1;
    cn=new OleDbConnection(strConnecting);
    cn.Open();
    string strsqlsel2="select cpmc from cplrb where cpph='"+this.TxtPH.Text+"'";
    OleDbDataAdapter sda1=new OleDbDataAdapter(strsqlsel2,cn);
    ds1=new DataSet();
    sda1.Fill(ds1);
    OleDbCommand myCommand1 = new OleDbCommand(strsqlsel2,cn);
    if (ds1.Tables["cplrb"].Rows.Count==0)
    {
    this.RegisterClientScriptBlock("ph","<script>alert('无法找到数据,请重新输入产品批号!')</script>");
    return;
    }
    else 
    {
    TxtPM.Text=myCommand1.ExecuteScalar().ToString();
    }
    cn.Close();
    错在何处?
      

  4.   

    try
    {
           //do something
    }
    catch
    {
           //show message
    }
      

  5.   

    try
    {
           //do something
    }
    catch
    {
           //show message
    }
    请务必这样做,不然的话会出错