Vb 2003 and Access - Cannot load data from database


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 4 of 4

Thread: Vb 2003 and Access - Cannot load data from database

  1. #1
    Join Date
    Aug 2006
    Location
    Albuquerque
    Posts
    32

    Unhappy Vb 2003 and Access - Cannot load data from database

    Hey Everyone!

    I worked a tutorial I found online on how to retrieve records from a database but was not able to get it to work. When I click on the button to retrieve the records, the records do not load into the textboxes. Your help is appreciated. Thanks!

    Julian



    Imports System.Data.OleDb

    Dim cn As OleDbConnection
    Dim cmd As OleDbCommand
    Dim dr As OleDbDataReader

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    Try
    cn = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;_Data Source=C:\Emp.mdb;")
    'provider to be used when working with access database
    cn.Open()
    cmd = New OleDbCommand("select * from table1", cn)
    dr = cmd.ExecuteReader
    While dr.Read()
    TextBox1.Text = dr(0)
    TextBox2.Text = dr(1)
    TextBox3.Text = dr(2)
    ' loading data into TextBoxes by column index
    End While
    Catch
    End Try
    dr.Close()
    cn.Close()
    End Sub
    End Class

  2. #2
    Join Date
    Dec 2003
    Location
    South Carolina
    Posts
    72
    1. Your Try/Catch block has no code to execute in the Catch section. Change
    Catch
    End Try
    to
    Catch ex as Exception
    messagebox.show(ex.message.tostring)
    End Try
    This will give you an error message if the code is failing.

    2. Is there a database C:\Emp.mdb?
    3. Is there a table1 in the database?
    4. Are there records in the table?
    Stephen H. Stubbs
    Software Systems Engineer
    Smith Engineering, LLC

  3. #3
    Join Date
    Aug 2006
    Location
    Albuquerque
    Posts
    32
    1)Ok i corrected the error handling, thanks! The error message I am getting is "Could not find installable ISAM". I will try working on correcting that, however, if you have already encountered this and know a solution, I would be happy to know.

    2)Yes, i created a database named emp.mdb and it is stored on the c:\ with a table1 and the three fields. I also created three records.

    Thanks for any help you can offer.

  4. #4
    Join Date
    Aug 2006
    Location
    Albuquerque
    Posts
    32
    Ok I figured it out!! There was an error in the connection string.

    was
    cn = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;_Data Source=C:\Emp.mdb;")

    should read
    cn = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Emp.mdb;")

Similar Threads

  1. Shift/Enter in Access 2003
    By Laurel in forum Database
    Replies: 5
    Last Post: 02-08-2006, 11:22 PM
  2. How to delete table from Access 97 database table
    By software_develo in forum Database
    Replies: 1
    Last Post: 01-31-2006, 11:58 PM
  3. Replies: 0
    Last Post: 07-13-2005, 01:32 PM
  4. Connecting to Access Database and running Queries
    By Dazza204 in forum VB Classic
    Replies: 1
    Last Post: 02-13-2005, 08:32 PM
  5. Replies: 0
    Last Post: 01-24-2003, 12:57 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center