This code:
Gives me the subject error and proceeds to load empty data onto form2. I have weeded through errors with this form and this one is killin me. I recreated the database with the exact column names listed in the SQL statement in the code and the path/filename are correct. I have set the colums to allow nulls and zero length data. What am I doing wrong?
Code:
Imports System.Data.OleDb
Public Class Form2
Global vars
Private dbData(100, 3) As String
Private dbPosition1 As Integer = 0
Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Debug.WriteLine(Application.StartupPath)
Try
Dim dbConnection As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Application.StartupPath & "\leadup1.mdb")
Const sql As String = "SELECT TB_years, TB_names, TB_battles, TB_essays FROM leadup"
Dim dbCmd As New OleDbCommand(sql, dbConnection)
Dim results As OleDbDataReader
Dim i As Integer = 0
dbConnection.Open()
results = dbCmd.ExecuteReader()
Do While results.Read()
dbData(i, 0) = results.GetString(0)
dbData(i, 1) = results.GetString(1)
dbData(i, 2) = results.GetString(2)
dbData(i, 3) = results.GetString(3)
i += 1
Loop
dbConnection.Close()
Catch ex As OleDbException
MessageBox.Show(ex.Message, "Database Error")
End Try
If dbPosition1 <= dbData.GetUpperBound(0) Then
txtYears.Text = dbData(dbPosition1, 0)
linkNames1.Text = dbData(dbPosition1, 1)
txtBattles.Text = dbData(dbPosition1, 2)
richtxtEssay.Text = dbData(dbPosition1, 3)
dbPosition1 += 1
End If
End Sub
Private Sub CloseWindow_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CloseWindow.Click
Me.Close()
End Sub
End Class
Gives me the subject error and proceeds to load empty data onto form2. I have weeded through errors with this form and this one is killin me. I recreated the database with the exact column names listed in the SQL statement in the code and the path/filename are correct. I have set the colums to allow nulls and zero length data. What am I doing wrong?