Simple (?) DB Connection problem

M

Meissa

Hi all,

I am trying to connect to an Access database on my local machine which
has a table named lastupdate, from this table I want to return the
value to a messagebox of a field named last update which contains the
date that the database was last updated.

I have tried to accomplish this as follows:

Imports System
Imports System.Data

Module Module1


Sub main()
Dim sConnectionString, sSQL As String
sConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=C:\Documents and Settings\Derek\My Documents\Seaton
JFC.mdb;Persist Security Info=False"
sSQL = "SELECT last update FROM lastupdate"

Dim connUP As New OleDb.OleDbConnection(sConnectionString)
Dim cmdUP As New OleDb.OleDbCommand(sSQL, connUP)
Dim drUP As OleDb.OleDbDataReader
connUP.Open()
drUP = cmdUP.ExecuteReader
Do While drUP.Read
MsgBox(drUP.Item("last update"))
Loop
drUP.Close()
connUP.Close()

End Sub
End Module

When I try to run this, I get the following error:

An unhandled exception of type 'System.Data.OleDb.OleDbException'
occurred in system.data.dll

When I break, the error is at the line : drUP = cmdUP.ExecuteReader

What am I doing wrong here, this is driving me insane.

TIA

Del.
 
C

Cor Ligthert

Hi Meissa,

On first sight I think it is your the name of your table
"lastupdate"

In your program you say "last update"

I do not know if it is possible, however the name update will probably for
sure give you problems.

And than it has to be enclosed with [last update]

I hope this helps?

Cor
 
G

Guest

Hi Meissa

Use try catch block like thi

tr

catch ex as exceptio
msgbox ex.stackTrac
end tr

See what message it is giving, if you see the message you can solve the problem by urself, if you are not mail the message which u are getting

I will tell u a solution. U can mail me at (e-mail address removed)

With regards

Sadha Sivam S
 
M

Meissa

Hi Cor,

Thanks for your help; I renamed the table and this worked fine.

I appreciate your help.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top