1. Home
  2. Computing & Technology
  3. Visual Basic
Using ADO .NET - Access and OleDB Part 2
6 - The Application Example Code
 More of this Feature
• 1 - Starting at the beginning ...
• 2 - The OleDbDataReader Object
• 3 - Coding A DataReader Application
• 4 - Try-Catch Error Processing
• 5 - Finishing the Application
 
 Join the Discussion
Is this the kind of article that helps you?
Let us know!
 
 Related Resources
• VB .NET Books!
• New to VB .NET?
  Learn It Here!
 
 Elsewhere on the Web
• About.Com DATABASES
 

Download the code

Example Program
'Imports OleDb namespace
Imports System.Data.OleDb

Public Class frmAboutVBSpotlights
    Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

    Dim I As Integer = 0
    Dim dteAboutVBDate(10000) As Date
    Dim strAboutVBDesc(10000) As String
    Dim blnAboutVB6(10000) As Boolean
    Dim blnAboutVBNet(10000) As Boolean
    Dim urlAboutVBURL(10000) As String

    Private Sub frmAboutVBSpotlights_Load( _
        ByVal sender As System.Object, _
        ByVal e As System.EventArgs) _
        Handles MyBase.Load

        Dim strAboutVBConn As String = _
            "Provider=Microsoft.Jet.OLEDB.4.0;" _
            & "User ID=Admin;" _
            & "{path}\"AboutVB.mdb"
        Dim ocmdAboutVBCommand As OleDbCommand
        Dim odtrAboutVBDataReader As OleDbDataReader
        Try
            ocmdAboutVBCommand = New OleDbCommand()
            With ocmdAboutVBCommand
                .Connection = New _
                    OleDbConnection(strAboutVBConn)
                .Connection.Open()
                .CommandText = "Select * From Articles"
                odtrAboutVBDataReader = .ExecuteReader()
            End With

            With lstAboutVBData
                .Items.Clear()
                .BeginUpdate()
                Do While odtrAboutVBDataReader.Read
                    .Items.Add(odtrAboutVBDataReader.GetString(1))
                    dteAboutVBDate(I) = _
                        odtrAboutVBDataReader.GetDateTime(2)
                    strAboutVBDesc(I) = _
                        odtrAboutVBDataReader.GetString(3)
                    blnAboutVB6(I) = _
                        odtrAboutVBDataReader.GetBoolean(4)
                    blnAboutVBNet(I) = _
                        odtrAboutVBDataReader.GetBoolean(5)
                    urlAboutVBURL(I) = _
                    Mid(odtrAboutVBDataReader.GetString(6), 2, _
                        Len(odtrAboutVBDataReader.GetString(6)) - 2)
                    I += 1
                Loop
                .EndUpdate()
            End With

        Catch oexpData As OleDb.OleDbException
            lblDesc.Text = oexpData.Message
            Exit Sub
        End Try
        odtrAboutVBDataReader.Close()
        ocmdAboutVBCommand.Connection.Close()
        ReDim Preserve urlAboutVBURL(I - 1)
        lstAboutVBData.SelectedIndex = 0
        lblDate.Text = dteAboutVBDate(0)
        lblDesc.Text = strAboutVBDesc(0)
        lblVB6.Text = blnAboutVB6(0)
        lblVBNET.Text = blnAboutVBNet(0)
        lblURL.Text = urlAboutVBURL(0)
    End Sub

    Private Sub lstAboutVBData_SelectedIndexChanged( _
        ByVal sender As System.Object, _
        ByVal e As System.EventArgs) _
        Handles lstAboutVBData.SelectedIndexChanged
        I = lstAboutVBData.SelectedIndex
        lblDate.Text = dteAboutVBDate(I)
        lblDesc.Text = strAboutVBDesc(I)
        lblVB6.Text = blnAboutVB6(I)
        lblVBNET.Text = blnAboutVBNet(I)
        lblURL.Text = urlAboutVBURL(I)
    End Sub
End Class
First page > Starting at the beginning ... > Page 1, 2, 3, 4, 5, 6
Explore Visual Basic
By Category
About.com Special Features

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

Easy ways to connect two computers for networking purposes. More >

  1. Home
  2. Computing & Technology
  3. Visual Basic

©2009 About.com, a part of The New York Times Company.

All rights reserved.