Since you using COUNT(*)
, using ExecuteScalar
would be better approach.
Executes the query, and returns the first column of the first row in the result set returned by the query.
int _value = (int)_query1.ExecuteScalar();
Also use using
statement to dispose your OleDbConnection
and OleDbCommand
.
using(OleDbConnection _connectMe = Utilities.OledbConnect())
using(OleDbCommand _query1 = _connectMe.CreateCommand())
{
_query1.CommandText = "SELECT count(*) FROM GIS.PERSONS where Name_Prefix = 'Dr.'";
_connectMe.Open();
int _value = (int)_query1.ExecuteScalar();
}