Imports System
Imports System.Data
Imports System.Data.OleDb
Module OleDbProvider
Sub Main()
Dim ConnString As String = "provider=sqloledb;" & _
"data source=(local)\SQLEXPRESS;" & _
"integrated security=sspi;" & _
"database=MyDatabase"
Dim CmdString As String = "SELECT * FROM Employee"
Dim Conn As OleDbConnection
Dim Reader As OleDbDataReader
Try
Conn = New OleDbConnection(ConnString)
Conn.Open()
Dim Cmd As New OleDbCommand(CmdString, Conn)
Reader = Cmd.ExecuteReader()
Console.WriteLine("Querying database {0} with query {1}" & _
ControlChars.NewLine, Conn.Database, Cmd.CommandText)
Console.WriteLine("FirstName" & ControlChars.Tab & "LastName")
While (Reader.Read())
Console.WriteLine(Reader("FirstName").PadLeft(9) & _
ControlChars.Tab & Reader(1))
End While
Catch ex As Exception
Console.WriteLine("Error: {0}", ex)
Finally
Reader.Close()
Conn.Close()
End Try
End Sub
End Module
|