Adapting Recordset Objects to DataSet Objects

Just as any other data adapter class, OleDbDataAdapter provides a Fill method that callers can use to add tables to a DataSet object. The OleDbDataAdapter class is defined in the System.Data.OleDb namespace, and you typically use it as follows:

OleDbDataAdapter da = new OleDbDataAdapter();
⋮
DataSet ds = new DataSet();
da.Fill(ds, "MyTable");

The Fill method of the OleDbDataAdapter class has an interesting peculiarity. It can load into the target DataSet object not only the result sets created by the given command but also the contents of an existing ADO Recordset object. One of the overloads of the Fill method has the structure shown here:

 int Fill(DataSet ds, Object adodb, String srcTable); ...

Get Building Web Solutions with ASP.NET and ADO.NET now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.