在我的简单数据库中我使用SqlCE,我无法弄清楚如何正确地找出查询是否返回行。 HasRows
不起作用。到目前为止,我有这个:
_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())
{
//
}
}
由于
答案 0 :(得分:2)
试试这个:
_DbCommand.CommandText="SELECT COUNT(*) FROM X"
Int32 count = (Int32) _DbCommand.ExecuteScalar();
答案 1 :(得分:1)
int count = 0;
while (reader.Read())
{
count++;
}
if(count==0)
{
// no rows
}