| |
![]() |
|
| |
![]() |
|

Private Sub QueryButton_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs)Handles QueryButton.Click
'code for the query and listing the results in ResultBox goes here
End Sub
Private Sub CloseButton_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs)Handles CloseButton.Click
End Sub
Option Strict on
Option Explicit on
Public Class DBMain
Public Shared MyForm As QueryForm
Public Shared Connection As System.Data.OleDb.OleDbConnection
Public Shared Sub Main()
Dim ConnectString As String = "Provider=Microsoft.Jet.OLEDB.4.0;" + _
"Data Source=c:\temp\foo.mdb"
Connection = New System.Data.OleDb.OleDbConnection(ConnectString)
Try
Connection.Open()
Catch e As Exception
MsgBox("Problem opening database..." + e.Message)
System.Environment.Exit(1)
End Try
End Sub
Public Shared Sub Close()
Dim ConnectString As String = "Provider=Microsoft.Jet.OLEDB.4.0;" + _
"Data Source=c:\temp\foo.mdb"
Connection = New System.Data.OleDb.OleDbConnection(ConnectString)
Try
Connection.Close()
Catch e As Exception
MsgBox("Problem closing database..." + e.Message)
System.Environment.Exit(1)
End Try
'if all's well, exit with status 0
System.Environment.Exit(0)
End Sub
End Class
Private Sub QueryButtonClick(ByVal sender As System.Object, _
ByVal e As System.EventArgs)Handles QueryButton.Click
DBMain.Main()
'code for the query and listing the results in ResultBox goes here
End Sub
Private Sub CloseButtonClick(ByVal sender As System.Object, _
ByVal e As System.EventArgs)Handles CloseButton.Click
DBMain.Close()
End Sub
Private Sub QueryButtonClick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles QueryButton.Click
Dim SQLCommand As System.Data.OleDb.OleDbCommand
Dim SQLDataReader As System.Data.OleDb.OleDbDataReader
Dim result_string As String
DBMain.Main()
SQLCommand = New System.Data.OleDb.OleDbCommand("select name from foo", DBMain.Connection)
Try
SQLDataReader = SQLCommand.ExecuteReader()
Catch f As Exception
MsgBox("Problem in ExecuteReader..." + f.Message)
DBMain.Connection.Close()
System.Environment.Exit(1)
End Try
Try
Do While SQLDataReader.Read()
result_string = SQLDataReader.GetString(0)
ResultList.Items.Add(result_string)
Loop
SQLDataReader.Close()
Catch g As Exception
MsgBox("Problems reading data..." + g.Message)
DBMain.Connection.Close()
System.Environment.Exit(1)
End Try
End Sub
Private Sub ClearButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ClearButton.Click
ResultList.Items.Clear()
End Sub

Private Sub QueryButtonClick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles QueryButton.Click
Dim dt As DataTable
Dim myAdapter As OleDb.OleDbDataAdapter
Dim QueryString As String = "select name from foo"
DBMain.Main()
Try
myAdapter = New OleDb.OleDbDataAdapter(QueryString, DBMain.Connection)
Catch g As Exception
MsgBox("Problem creating dataAdapter..." + g.Message)
DBMain.Connection.Close()
System.Environment.Exit(1)
End Try
dt = New DataTable()
myAdapter.Fill(dt)
myAdapter.Dispose()
DataGrid.DataSource = dt
Refresh()
End Sub