-
1 Attachment(s)
ADODB error (newbie)
Code:
Dim con As New ADODB.Connection
Private Sub Form_Load()
con.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Documents and Settings\User\Desktop\i-Analysis\Analysis.mdb;Persist "
Dim rs As New ADODB.Recordset
rs.Open "select * from IATestDetails", con, 3, 3, 1
End Sub
The table "IATestDetails" clearly exists in the database "Analysis.mdb"..
What is the problem?
:o
-
Re: ADODB error (newbie)
Either you're looking at the wrong mdb file (when you're opening the connection) or the table name is spelled wrong. Or the fact that you ended the connection string prematurely may be causing a problem - it should end "... Persist Security Info=False"
One hint, so you can read your code 6 months from now. You may remember what
rs.Open "select * from IATestDetails", con, 3, 3, 1
means now (I've been using ADO since it came out, and I couldn't guess), but
rs.Open "select * from IATestDetails", con, adOpenStatic, adLockBatchOptimistic
is much easier to read. (And adCmdText is the default for a recordset open, so you don't have to specify it.) Just pick from the choices VB's Intellisense gives you as you're typing the code.
And never Dim X as New ... There's no way to recover that memory without rebooting the computer (it's called a "memory leak"). Dim X As ADODB ..., then Set X = New ADODB .... When you're done with it, Set X = Nothing, and you'll recover the memory. (Running a program that doesn't recover memory, over and over, can cause the computer to crash, even when the program is no longer running.)
Someone named Beacon wrote a very good ADO tutorial. You should copy it and print it for future reference. Also, look in C:\Program Files\Microsoft Visual Studio\MSDN98\98VSa\1033\ for the file ADO200.CHM. It's Microsoft's help file for ADO.