开发者

How to find out whether SqlCe query Has rows?

开发者 https://www.devze.com 2022-12-23 19:30 出处:网络
In my simple db I use SqlCE and I cannot figure out how to correctl开发者_JS百科y find out whether the query returns rows or not. HasRows does not work. So far I have this:

In my simple db I use SqlCE and I cannot figure out how to correctl开发者_JS百科y find out whether the query returns rows or not. HasRows does not work. So far I have this:

_DbCommand.CommandText="SELECT * FROM X"
SqlCeDataReader reader=_DbCommand.ExecuteQuery();

if (reader.FieldCount!=0) //I thought it could work (O rows - 0 fields?), but its true even with 0 rows
{
    while (reader.Read())
    {
        //
    }
}

Thanks


Try this:

_DbCommand.CommandText="SELECT COUNT(*) FROM X"
Int32 count = (Int32) _DbCommand.ExecuteScalar();


int count = 0;
while (reader.Read())
{
 count++;
}
if(count==0)
{
 // no rows
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号