在visual stduio 2008中
SqlCommand myComm2 = new SqlCommand("select * from kc where pm='"+pm+"'and xh='"+xh+"'",myConn);
如何判断查询的结果是否为空值(没任何符合记录)??
还有一个整数变量如何与数据库中的相加并更细数据库?求语句
在这先谢过各位大哥大姐!
SqlCommand myComm2 = new SqlCommand("select * from kc where pm='"+pm+"'and xh='"+xh+"'",myConn);
如何判断查询的结果是否为空值(没任何符合记录)??
还有一个整数变量如何与数据库中的相加并更细数据库?求语句
在这先谢过各位大哥大姐!
"slect count(*) from from kc where pm='"+pm+"'and xh='"+xh+"'"结果为0就是没有符合的记录或者用你原来的方法,判断取回的数据中的记录条数,为0条,就是没有符合的结果
SqlDataReader myReader = myComm2.ExecuteReader();
if (!myReader.Read())
{
//数据为空!!
}
SqlCommand myComm2 = new SqlCommand("update kc set 整型字段 = 整型字段+"+整数变量名+" where 条件",myConn);
SqlDataReader dr= myComm2.ExecuteReader();
if(dr.HasRows)
{}
或select count(*) from kc where pm='"+pm+"'and xh='"+xh+"'
update kc set 字段=值
int i=0;
while (dr.Read())
{
i++;
}
if(i==0)
{
"查询结果为空!"
}
使用SqlDataReader读出来。、if(dr.HasRows) //判断是否有存在的行
{
while(dr.Read()) //存在读出来
{
txtName.text=dr["name"].ToString();
}
}
……省略关闭………………
2查询某个值是否为空。
…………查询操作……if(StuID is not null)
SqlDataReader dr= myComm2.ExecuteReader();
if(dr.HasRows)
{}
或select count(*) from kc where pm='"+pm+"'and xh='"+xh+"'
update kc set 字段=值