在visual stduio 2008中
SqlCommand myComm2 = new SqlCommand("select * from kc where pm='"+pm+"'and xh='"+xh+"'",myConn);
       如何判断查询的结果是否为空值(没任何符合记录)??
还有一个整数变量如何与数据库中的相加并更细数据库?求语句
在这先谢过各位大哥大姐!

解决方案 »

  1.   

    更新:"update biao set fieldname=(isnull(fieldname,0)+"+整数变量+") where 条件"
      

  2.   

    如何判断查询的结果是否为空值(没任何符合记录)??
    "slect count(*) from from kc where pm='"+pm+"'and xh='"+xh+"'"结果为0就是没有符合的记录或者用你原来的方法,判断取回的数据中的记录条数,为0条,就是没有符合的结果
      

  3.   

    如果使用SqlDataReader则:
    SqlDataReader myReader = myComm2.ExecuteReader();
    if (!myReader.Read())
    {
        //数据为空!!
    }
                            
      

  4.   

    更新也可以这样:
    SqlCommand myComm2 = new SqlCommand("update kc set 整型字段 = 整型字段+"+整数变量名+" where 条件",myConn);
      

  5.   

    SqlCommand myComm2 = new SqlCommand("select * from kc where pm='"+pm+"'and xh='"+xh+"'",myConn);
    SqlDataReader dr= myComm2.ExecuteReader();
    if(dr.HasRows)
    {}
    或select count(*) from kc where pm='"+pm+"'and xh='"+xh+"'
    update kc set 字段=值
      

  6.   

    SqlDataReader dr = myComm2.ExecuteReader();
    int i=0;
     while (dr.Read())
    {
      i++;
    }
    if(i==0)
    {
        "查询结果为空!"
    }
      

  7.   

    同上
    使用SqlDataReader读出来。、if(dr.HasRows)  //判断是否有存在的行
    {
       while(dr.Read())  //存在读出来
       {
          txtName.text=dr["name"].ToString();
       }
    }
    ……省略关闭………………
    2查询某个值是否为空。
    …………查询操作……if(StuID is not null)
      

  8.   

    SqlCommand myComm2 = new SqlCommand("select * from kc where pm='"+pm+"'and xh='"+xh+"'",myConn);
    SqlDataReader dr= myComm2.ExecuteReader();
    if(dr.HasRows)
    {}
    或select count(*) from kc where pm='"+pm+"'and xh='"+xh+"'
    update kc set 字段=值