Use OleDbDataReader to read data : OleDbDataReader « Database ADO.net « VB.Net

Home
VB.Net
1.2D
2.Application
3.Class
4.Data Structure
5.Data Types
6.Database ADO.net
7.Development
8.Event
9.File Directory
10.Generics
11.GUI
12.Language Basics
13.LINQ
14.Network Remote
15.Security
16.Thread
17.Windows Presentation Foundation
18.Windows System
19.XML
20.XML LINQ
VB.Net Tutorial
VB.Net by API
VB.Net » Database ADO.net » OleDbDataReaderScreenshots 
Use OleDbDataReader to read data
Use OleDbDataReader to read data

Imports System
Imports System.Data
Imports System.Data.OleDb
Imports System.Data.SqlClient
Imports System.Collections
Imports System.Windows.Forms
Imports System.Resources

Public Class MainClass
    Shared Sub Main()
        'Declare variables and objects
        Dim strConnectionString As String = _
            "Provider=Microsoft.Jet.OLEDB.4.0;" & _
            "Data Source=Employee.mdb;"
        Dim objConnection As New OleDbConnection(strConnectionString)
        Dim strSQL As String = "SELECT * FROM Employee"
        Dim objCommand As New OleDbCommand(strSQL, objConnection)
        Dim objDataAdapter As New OleDbDataAdapter(objCommand)
        Dim objDataTable As New Data.DataTable("Employee")
        Dim objDataRow As DataRow

        Try
            'Open the database connection
            objConnection.Open()
        Catch OleDbExceptionErr As OleDbException
            'Write the exception
            Console.WriteLine(OleDbExceptionErr.Message)
        Catch InvalidOperationExceptionErr As InvalidOperationException
            'Write the exception
            Console.WriteLine(InvalidOperationExceptionErr.Message)
        End Try



        'Declare an OleDbDataReader object
        Dim objDataReader As OleDbDataReader

        Try
            'Execute the SQL text
            objDataReader = objCommand.ExecuteReader()

            'Check to see if we have data
            If objDataReader.HasRows Then
                'Process all rows
                While objDataReader.Read()
                    'Get the data in each column
                    For intIndex As Integer = To objDataReader.FieldCount - 1
                        Console.WriteLineobjDataReader.Item(intIndex).ToString & ", ")
                    Next
                End While

            End If

            'Close the reader
            objDataReader.Close()

        Catch OleDbExceptionErr As OleDbException
            Console.WriteLine(OleDbExceptionErr.Message)
        End Try





        'Close the database connection
        objConnection.Close()

        'Clean up
        objDataRow = Nothing
        objDataTable.Dispose()
        objDataTable = Nothing
        objDataAdapter.Dispose()
        objDataAdapter = Nothing
        objCommand.Dispose()
        objCommand = Nothing
        objConnection.Dispose()
        objConnection = Nothing

    End Sub
End Class

           
       
Employee.zip( 7 k)
Related examples in the same category
1.Use OleDbDataReader to read data from 'select' commandUse OleDbDataReader to read data from 'select' command
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.