Using an Access Database

Alex_W

Member
Joined
Jan 5, 2009
Messages
22
Programming Experience
Beginner
Hi guys,

I am trying to use an Access database with my vb.net program but no data appears in my text boxes. The code is from a book and I have even used the official downloaded code which still doesnt work. Stranger still I use the same code on another machine (XP) and it works.

Module level variables are set at the top:
Private m_cnADONetConnection As New OleDb.OleDbConnection()
Private m_daDataAdapter As OleDb.OleDbDataAdapter
Private m_cbCommandBuilder As OleDb.OleDbCommandBuilder
Private m_dtContacts As New DataTable
Private m_rowPosition As Integer = 0

This is the show current record subroutine:
Private Sub ShowCurentRecord()
If m_dtContacts.Rows.Count = 0 Then
txtContactName.Text = " "
txtState.Text = " "
Exit Sub
End If

txtContactName.Text = m_dtContacts.Rows(m_rowPosition)("ContactName").ToString()
txtState.Text = m_dtContacts.Rows(m_rowPosition)("State").ToString()
End Sub

And this is on the form load:
m_cnADONetConnection.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\temp\Contacts.mdb"

m_cnADONetConnection.Open()

m_daDataAdapter = New OleDb.OleDbDataAdapter("Select * From Contacts", m_cnADONetConnection)

m_cbCommandBuilder = New OleDb.OleDbCommandBuilder(m_daDataAdapter)

m_daDataAdapter.Fill(m_dtContacts)

Me.ShowCurentRecord()

This should show the first record on the program load (as it does on the XP machine), the database is deffinitly in the right place and I've even tried changin the location. I am using vista 64 and have even re-downloaded the mdb file in case Office 07 converted anything. If this works on other PC's an not mine there must be something funny going on but I have nothin abnormal setup.

Any help much appreciated!

Alex_W
 
Follow the steps outlined in the DW2 link in my signature, section Creating a Simple Data App
 
Back
Top