我有这段代码用于从表中获取 Count 值:
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;
}
它有效,但我正在寻找一种方法来避免循环并简单地一举返回计数,例如:
. . .
using (OleDbDataReader oleDbD8aReader = cmd.ExecuteReader())
{
if (oleDbD8aReader != null && oleDbD8aReader.Read())
{
i = oleDbD8aReader.Value;
}
}
return i;
. . . // 2B ||! 2B this. es la Frage
...但是(对我而言)如何获得该值并不明显。当然有可能,但是怎么做呢?