I have been programming vba for some time and am now starting VB.NET. I need to connect to an existing access db file (access 2003). I downloaded VS2010 and found an example on the net. Here is most of the code:
Expand|Select|Wrap|Line Numbers
- Imports System.Data.OleDb
- Public Class Form1 Inherits System.Windows.Forms.Form
- Dim cn As OleDbConnection
- Dim cmd As OleDbCommand
- Dim dr As OleDbDataReader
- Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
- End Sub
- 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:\temp\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
1 End of Statement Expected
I have tried to add a reference to System.Data.OleDb but
it doesn't appear in the add reference box. System.Data.OleDb is checked in the Imported namespaces window. I have tried changing the .NET Framework but, no help. Help would be greatly appreciated.
Thank you
John