October 24, 2018
Hot Topics:

ADO.NET Overview

  • November 20, 2002
  • By Karl Moore
  • Send Email »
  • More Articles »

Sample access using Data Reader:

       ' Setup connection

       Dim myConnection AsNew OleDb.OleDbConnection( _

           "Provider=Microsoft.Jet.OLEDB.4.0;" & _

           "Data Source=C:\Program Files\Microsoft Visual " & _


        ' Setup command object, specifying SELECT

       ' and connection to use

       Dim myCommand AsNew OleDb.OleDbCommand( _
         "Select * from Customers", myConnection)

       Dim myReader AsOleDb.OleDbDataReader 

       ' Open connection


       ' Execute and put results into reader

       myReader = myCommand.ExecuteReader

       ' Read through all the records

       Do UntilmyReader.Read = False



       ' Close reader connection before continuing



Sample access using Data Adapter:

       ' Setup connection

       Dim myConnection AsNew OleDb.OleDbConnection( _

           "Provider=Microsoft.Jet.OLEDB.4.0;" & _

           "Data Source=C:\Program Files\Microsoft Visual " & _


       ' We're just specifying the SELECT here.

       ' If done visually using the Server Explorer,

       ' the INSERT/UPDATE/DELETE + Parameters

       ' collection would be auto-specified for us

       Dim myDataAdapter AsNew OleDb.OleDbDataAdapter( _
         "Select * from Customers", myConnection) 

       Dim myDataSet AsNew DataSet() 

       ' Fill DataSet with table, call it 'Customers'

       myDataAdapter.Fill(myDataSet, "Customers") 

       ' Display first CompanyName field of first

       ' row in Customers table


       ' If we had specified INSERT/UPDATE/DELETE

       ' commands + Parameters collection, we could

       ' also now edit the data, then run somethinglike:

       '   myDataAdapter.Update(myDataSet) 


Sample access using XML:

       Dim myDataSet AsNew DataSet()


       ' Books.xml is file bundled with VS.NET,

       ' typically located at:

       ' C:\Program Files\Microsoft.NET\FrameworkSDK

       ' ... \Samples\quickstart\howto\samples\xml

       ' ... \xmldocumentevent\vb\books.xml

        ' Counts the number of book nodes


        ' Retrieves the last name of the first author

       MessageBox.Show(myDataSet.Tables( _

        ' Updates the last name

       myDataSet.Tables("author").Rows(0)( _
         "last-name") = "Flandadenham"

        ' Rewrites the XML file


Page 7 of 7

Comment and Contribute


(Maximum characters: 1200). You have characters left.



Enterprise Development Update

Don't miss an article. Subscribe to our newsletter below.

By submitting your information, you agree that developer.com may send you developer offers via email, phone and text message, as well as email offers about other products and services that developer believes may be of interest to you. developer will process your information in accordance with the Quinstreet Privacy Policy.


Thanks for your registration, follow us on our social networks to keep up-to-date