OleDbDataAdapter.Fill ignores last record

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello Experts,

after calling 'adapter.Fill(table, recordset);' or 'adapter.Fill(dataSet,
recordset, tableName);', the last record from 'recordset' is missing in
'dataSet.Tables[tableName]'.

Here's what I'm doing:

//open recordset
ADODB.Recordset recordset = new ADODB.RecordsetClass();
recordset.Open(
sql,
connection, ADODB.CursorTypeEnum.adOpenUnspecified, ADODB.LockTypeEnum.adLockReadOnly,
(int)ADODB.ExecuteOptionEnum.adOptionUnspecified);

//output count of records
Trace.WriteLine("recordset.RecordCount.Count: " +
recordset.RecordCount.ToString());

//go to the first record
if(!recordset.BOF){
recordset.MoveFirst();
}

//fill the DataSet
OleDbDataAdapter adapter = new OleDbDataAdapter();
adapter.Fill(dataSet, recordset, tableName);

//output count of records
Trace.WriteLine("dataSet.Tables[tableName].Rows.Count: "+
dataSet.Tables[tableName].Rows.Count);

The Trace file says:
recordset.RecordCount.Count: 7
dataSet.Tables[tableName].Rows.Count: 6

The missing record is always the last record that had been saved before
running the application. If I add a row to the database (an Exchange 2000
store) and run the application again, the missing row is there again and my
new row is missing.

What's going on here?!

Thanks for every hint,

corinna
 
Sorry, it works, now ;)
Here's the solution.

The count of missing records was (recordset.RecordCount -
recordset.CacheSize).
A recordset.CacheSize of 0 is not allowed, so I set recordset.CacheSize to
-1, and now I get all records:

ADODB.Recordset recordset = new ADODB.RecordsetClass();

recordset.CacheSize = -1;

recordset.Open(...
 
Back
Top