By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,948 Members | 1,587 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,948 IT Pros & Developers. It's quick & easy.

How to connect to access db file from VS2020 (can't find System.Data.OleDb)?

P: 2
Hello
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
  1. Imports System.Data.OleDb
  2. Public Class Form1 Inherits System.Windows.Forms.Form
  3.     Dim cn As OleDbConnection
  4.     Dim cmd As OleDbCommand
  5.     Dim dr As OleDbDataReader
  6.     Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  7.     End Sub
  8.  
  9.     Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
  10.         Try
  11.             cn = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\temp\emp.mdb;")
  12.             'provider to be used when working with access database
  13.             cn.Open()
  14.             cmd = New OleDbCommand("select * from table1", cn)
  15.             dr = cmd.ExecuteReader
  16.             While dr.Read()
  17.                 TextBox1.Text = dr(0)
  18.                 TextBox2.Text = dr(1)
  19.                 TextBox3.Text = dr(2)
  20.                 ' loading data into TextBoxes by column index
  21.             End While
  22.  
I am getting this error message:
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
Dec 9 '10 #1
Share this Question
Share on Google+
1 Reply


P: 2
Hello
After taking another look I noticed that the error refered to line 2, which is:

Public Class Form1 Inherits System.Windows.Forms.Form

I erased everything from "Inherits" to the end of the line, now it is:

Public Class Form1

The example code now works. Why, I don't know. Do you?

John
Dec 13 '10 #2

Post your reply

Sign in to post your reply or Sign up for a free account.