我有以下代码:
// personCount = 7291; correct value
int personCount = (int)new OleDbCommand("SELECT COUNT(*) AS [count] FROM [Individual]", _access).ExecuteScalar();
List<Person> people = new List<Person>();
OleDbCommand personQuery = new OleDbCommand("SELECT * FROM [Individual]", _access);
using (OleDbDataReader personReader = personQuery.ExecuteReader())
{
int curPerson;
while (personReader.Read())
{
curPerson++;
// This runs several times
if (personReader.IsDBNull(0)) continue;
// [snip] create a new Person and add it to people
}
// at this point, curPerson == 7291 but the list is empty.
}
这是我的确切代码。字段 0 是主键,因此不应为空,但从数据库返回的每一行都将所有字段设置为 DBNull!我看不出我做错了什么,任何人都可以对此有所了解吗?
我的连接字符串是:
提供者=Microsoft.Jet.OLEDB.4.0;数据源=C:\path\to\database.mdb