Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

This 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?

Posted
I fixed this problem. I'm not happy about how I fixed it, but it works. I removed the Try...Catch statements and it form loads with the correct data. Now I will just have to reformat the try-catch or use another form of error trapping.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...