对一张空表查询 select max() from table 时 dataReader.hasRows属性为什么为空
如题当对一张空表查询 当使用
string sqlStr ="select * from table";
SqlDataCommand cmd=new SqlDataCommand(sqlStr,conn);
SqlDataReader dataReader = cmd.ExecuteNonQuery();
时dataReader.HasRows属性为false
但是当使用
sqlStr ="select max(count) as count from table";
SqlDataCommand cmd=new SqlDataCommand(sqlStr,conn);
SqlDataReader dataReader = cmd.ExecuteNonQuery();
时dataReader.HasRows属性为true
这是为什么呢
如题当对一张空表查询 当使用
string sqlStr ="select * from table";
SqlDataCommand cmd=new SqlDataCommand(sqlStr,conn);
SqlDataReader dataReader = cmd.ExecuteNonQuery();
时dataReader.HasRows属性为false
但是当使用
sqlStr ="select max(count) as count from table";
SqlDataCommand cmd=new SqlDataCommand(sqlStr,conn);
SqlDataReader dataReader = cmd.ExecuteNonQuery();
时dataReader.HasRows属性为true
这是为什么呢
select max(count) as count from table 没有数据就返回null行
第二个用聚合函数,始终会有一个返回值,如果没有记录就会返回null