I have this code for getting a Count value from a table:
string connStr =
@"Provider=Microsoft.ACE.OLEDB.12.0;User ID=NRBQBO;Password=NRBQCP;Data Source=C:\CCRWin\DATA\CCRDAT42.MDB;Jet OLEDB:System database=C:\CCRWin\Data\NRBQ.mdw";
using (var conn = new OleDbConnection(connStr))
{
using (OleDbCommand cmd = conn.CreateCommand())
{
cmd.CommandText = @"SELECT Count(*) FROM platypi";
cmd.CommandType = CommandType.Text;
conn.Open();
int i = 0;
using (OleDbDataReader oleDbD8aReader = cmd.ExecuteReader())
{
while (oleDbD8aReader != null && oleDbD8aReader.Read())
{
i++;
}
}
return i;
}
It works, but I'm looking for a way to avoid the loop and simply return the count in one fell swoop, such as:
. . .
using (OleDbDataReader oleDbD8aReader = cmd.ExecuteReader())
{
if (oleDbD8aReader != null && oleDbD8aReader.Read())
{
i = oleDbD8aReader.Value;
}
}
return i;
. . . // 2B ||! 2B this. es la Frage
...but it's not obvious (to me) how to get that value. Surely it's possible, but how?