Home   |   QuickStart Welcome   |   ASP.NET   |   Web Services   |   How Do I...?   
  |   I want my samples in...      

How Do I...? Common Tasks QuickStart Tutorial

ADO.NET: Loading a native ADO recordset into a DataSet

This sample illustrates using ADO recordsets with managed Datasets. To provide access to ADO Recordset and Record objects from ADO.NET, the OLE DB .NET Data Provider overloads the Fill method of the OleDbDataAdapter to accept an ADO Recordset object or an ADO Record object. Filling a DataSet with the contents of an ADO object is a one-way operation. That is, data can be imported from the ADO Recordset or Record into the DataSet, but any updates to the data must be handled explicitly by either ADO.NET or ADO.

The Fill operation will append rows to the existing DataTables in the DataSet if no primary key information is available. If primary key information is available for the DataTable, then the Fill operation will update rows with matching primary keys.

In this sample the same basic procedures that were used with old ADO Recordset method of getting data are followed. First a connection to the database is created and then a SQL command is executed on the connection or the Recordset.

VB adorstodataset.aspx
Run Sample View Source

To consume a COM component that returns an ADO Recordset or Record object using .NET COM Interop services and ADO.NET, it is required to first import the type library information for the COM component and ADO using TlbImp.exe. For example, an existing COM component with a ProgId of ADOComponent.DataClass is compiled into ADOComponent.dll. It has methods that return objects of type ADODB.Recordset. To consume this object from .NET, both ADOComponent.dll, and msado15.dll would have to be imported, which contain the ADODB.Recordset and ADODB.Record objects. The following commands would need to be issued to import the COM type libraries to .NET:

TlbImp "C:\Program Files\Common Files\System\Ado\msado15.dll" /out:ADODB.dll TlbImp ADOComponent.dll /out:ADOCOM.dll

The resulting .NET libraries, ADODB.dll and ADOCOM.dll, would then be passed as library references when compiling a .NET program as shown below.

csc MyCS.cs /r:system.dll /r:system.data.dll /r:system.xml.dll /r:ADODB.dll /r:ADOCOM.dll


  1. The Fill method on the OleDbDataAdapter provides access to ADO Recordset and Record objects.
  2. Filling a DataSet with the contents of an ADO object is a one-way operation.
  3. ADO.NET provides access to ADO via the .NET COM Interop services.

Microsoft .NET Framework SDK QuickStart Tutorials Version 2.0
Copyright � 2004 Microsoft Corporation. All rights reserved.