Microsoft Knowledge Base Email Alertz

KBAlertz.com: (310349) - This step-by-step article demonstrates how to use the OleDbDataAdapter class to obtain rows from an ADO Recordset object and insert them into a DataSet object. Note that you cannot do the reverse; that is, you cannot obtain rows from a DataSet object...

Receive Microsoft Knowledge Base articles by E-Mail?

Every night we scan the Microsoft Knowledge Base. If technologies you're interested in are updated, we'll send you an e-mail. You only get one e-mail a day, and only when new articles are added.

Click here to create a
FREE account
Already have an account?
[Click here to Login]

Search KbAlertz

Advanced Search

Webmasters
Put kbAlertz on your website.
[ Click Here for more! ]





ASP.NET 3.5 Web Hosting with Windows 2008 and SQL 2008: Click Here!
Discount ASP.NET Hosting
ASP.NET 2.0 and 3.5
Windows2008 and SQL2008
US and UK Hosting
The ad says 3 - but KBAlertz referrals get
** SIX MONTHS FREE **


Bug Tracking Software
For bug tracking software or defect tracking software or issue tracking software, visit Axosoft.


Community Site



We Send hundreds of thousands of emails using ASP.NET Email



Expert Web Design & Graphic Design
Design44.com

ASP.NET 3.5 Web Hosting with Windows 2008 and SQL 2008: Click Here!
Discount ASP.NET Hosting
ASP.NET 2.0 and 3.5
Windows2008 and SQL2008
US and UK Hosting
The ad says 3 - but KBAlertz referrals get
** SIX MONTHS FREE **




Mentioned In








Microsoft Knowledge Base Article

This article contents is Microsoft Copyrighted material.
©2005-©2007 Microsoft Corporation. All rights reserved. Terms of Use | Trademarks




Article ID: 310349 - Last Review: June 15, 2006 - Revision: 3.1

How to use the OleDbDataAdapter to fill a DataSet object from an ADO Recordset object in Visual Basic .NET

This article was previously published under Q310349
Caution ADO and ADO MD have not been fully tested in a Microsoft .NET Framework environment. They may cause intermittent issues, especially in service-based applications or in multithreaded applications. The techniques that are discussed in this article should only be used as a temporary measure during migration to ADO.NET. You should only use these techniques after you have conducted complete testing to make sure that there are no compatibility issues. Any issues that are caused by using ADO or ADO MD in this manner are unsupported. For more information, see the following article in the Microsoft Knowledge Base:
840667   (http://kbalertz.com/Feedback.aspx?kbNumber=840667/ ) You receive unexpected errors when using ADO and ADO MD in a .NET Framework application

On This Page

SUMMARY

This step-by-step article demonstrates how to use the OleDbDataAdapter class to obtain rows from an ADO Recordset object and insert them into a DataSet object. Note that you cannot do the reverse; that is, you cannot obtain rows from a DataSet object and insert them into an ADO Recordset object.

Requirements

The following list outlines the recommended hardware, software, network infrastructure, and service packs that are required:
  • Microsoft Windows XP Professional, Microsoft Windows 2000 Professional, Microsoft Windows 2000 Server, Microsoft Windows 2000 Advanced Server, or Microsoft Windows NT 4.0 Server
  • Microsoft Visual Studio .NET
  • Microsoft OLE DB Provider for Jet

Create the Project

  1. Follow these steps to create a new Windows Application project in Visual Basic .NET:
    1. Start Visual Studio .NET.
    2. On the File menu, point to New, and then click Project.
    3. In the New Project dialog box, click Visual Basic Projects under Project Types, click Windows Application under Templates, and then click OK.
  2. Follow these steps to add a reference to ADODB in your project:
    1. On the Project menu, click Add Reference.
    2. In the Add Reference dialog box, click the .NET tab.
    3. Click adodb from the Component Name list, click Select, and then click OK.

      NOTE: This adds a reference to a primary interop assembly (PIA) so that you can use earlier versions of Microsoft ActiveX Data Objects (ADO) in a Visual Studio .NET application. For more information, see the REFERENCES section.
  3. Add a Button control and a DataGrid control to the form.
  4. Switch to the Code window, and then add the following code to the top of the Code window:
    Imports System.Data.OleDb
    					
  5. Add the following code to the Button1_Click event:
            'This code uses the Northwind.mdb database to create an ADODB Recordset. 
            'You must modify the path so that it points to the database on your system.
            'You can also use a Recordset that is returned from another location or component.
    
            Dim MyRs As New ADODB.Recordset()
            Dim MyCn As New ADODB.Connection()
            MyCn.Open("Provider=Microsoft.jet.oledb.4.0;data source=d:\northwind.mdb")
    
            MyRs.Open("Select * from Customers", MyCn, ADODB.CursorTypeEnum.adOpenStatic, ADODB.LockTypeEnum.adLockOptimistic)
    
            'Create and fill the DataSet from the Recordset. Populate the grid from the DataSet. 
            Dim myDA As OleDbDataAdapter = New OleDbDataAdapter()
            Dim myDS As DataSet = New DataSet()
            myDA.Fill(myDS, MyRs, "MyTable")
            DataGrid1.DataSource = myDS.Tables(0)
    
            'Close ADODB objects.
            'Note that the OleDbDataAdapter.Fill overload that takes
            'a DataTable and an ADO object implicitly calls Close on 
            'the ADO object when the Fill operation is complete.
    
            MyRs = Nothing
            MyCn.Close()
            MyCn = Nothing
    					
  6. Make sure to change the location of the Northwind database in the code to point to the Northwind database on your system.
  7. Press F5 to run the code.

REFERENCES

For additional information about the ADODB primary interop assembly, click the article number below to view the article in the Microsoft Knowledge Base:
318559  (http://kbalertz.com/Feedback.aspx?kbNumber=318559/EN-US/ ) INFO: Using the Primary Interop Assembly for ADO (ADODB) in Visual Studio .NET
For more information, see the following topic in the Visual Studio .NET Help documentation:
OleDbDataAdapter.Fill Method
http://msdn.microsoft.com/en-us/library/system.data.oledb.oledbdataadapter.fill.aspx (http://msdn.microsoft.com/en-us/library/system.data.oledb.oledbdataadapter.fill.aspx)
For general information about ADO.NET or Visual Basic .NET, see the following MSDN newsgroups:
microsoft.public.dotnet.framework.adonet (http://go.microsoft.com/fwlink/?linkid=5819)

microsoft.public.dotnet.languages.vb (http://go.microsoft.com/fwlink/?linkid=5820)

APPLIES TO
  • Microsoft ADO.NET 1.1
  • Microsoft ADO.NET 1.0
  • Microsoft Visual Basic .NET 2003 Standard Edition
  • Microsoft Visual Basic .NET 2002 Standard Edition
  • Microsoft ActiveX Data Objects 2.6
  • Microsoft ActiveX Data Objects 2.7
Keywords: 
kbhowtomaster kbsystemdata KB310349
       

Community Feedback System

Very often, it takes hours to solve a problem. Very often, you've looked high and low, and have tried a lot of solutions. When you finally found it, chances are, it was because someone else helped you. Here's your chance to give back. Use our community feedback tool to let others know what worked for you and what didn't.

Please also understand that the community feedback system is not warranted to be correct, it's simply a system that we've built to let people try and help each other. If something in a feedback response doesn't make sense to you, or you're not comfortable making changes that the feedback talks about (like registry edits), please consult a professional.

Thank you for using kbAlertz.com Feedback System.

-- Scott Cate

Be the first to leave feedback, to help others about this knowledge base article.

(Optional) Name

(Optional) Public URL Or Email

Comments
No HTML -- Text Only Please