Accessing Access database using Visual Basic .NET ADO library
Posted on 2006-06-12
I am trying to write a VB command line program that can access ACCESS database to read/add/modify data into tables.
The program stops right after accessing the database. As a first step I want to just read the tables. When I run it in debug more it stops right when I call the function oRS.Open("Select * From object", oConn) with an excection.
The first question is, do I need to import the namespaces to use the library?
If I don't use it, the program compiles correctly, if I use it, VB.NET complains about a function that I use to filter the command line, Command.Split, saying that it's not a member of ADODB.Command (Why doesn it say that?)
From the command line this is the exception that it prints:
Unhandled Exception: System.Runtime.InteropServices.COMException (0x80040E14): Syntax error in FROM clause.
at ADODB.RecordsetClass.Open(Object Source, Object ActiveConnection, CursorTypeEnum CursorType, LockTypeEnum LockType
, Int32 Options)
at tas_db_interface.Module1.DBConnection() in c:\02 temporary files\tas_db_interface\tas_db_interface\Module1.vb:lin
at tas_db_interface.Module1.Main() in c:\02 temporary files\tas_db_interface\tas_db_interface\Module1.vb:line 362
Line 265 is oRS.Open("Select * From object", oConn). It seems that it doesn't like the query.
To use the ADO library I added adodb.NET (Version 7.0.3300.0) to my project.
The function that I use to read the record has everything hard coded just to get it to work for now.
This is the code
Public Sub DBConnection()
Dim oConn As New ADODB.Connection
Dim oRS As New ADODB.Recordset
oRS.Open("Select * From object", oConn) 'object is one of the tables included in db1.mdb
' or oRS = oConn.Execute("select * from object") ?
While Not oRS.EOF
oRS = Nothing
oConn = Nothing
What am I doing wrong?
Once passed this issue it would be great to know how I can query the tables in my database. Enter a new record and modify an existing one.