Tuesday, March 6, 2012

ADODB.Command Question

How to using Adodb.command to get Access file data?
i using this script:

dim connection as new adodb.connection
dim command as new adodb.command
dim recordset as new adodb.recordset

connection.open("connectionstring")
command.activeconnection=connection
command.commandtext="querystring"
recordset=command.execute

but,the Recordset is empty.how to using to get data on Microsoft Access database?

thank!!!!

Dim cn As New ADODB.Connection
Dim cmd As New ADODB.Command
Dim rs As New ADODB.Recordset

cn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Testdb.mdb;"
cmd.ActiveConnection = cn
cmd.CommandText = "select * from sampletbl"
Set rs = cmd.Execute

Do While Not rs.EOF
For i = 0 To rs.Fields.Count - 1
MsgBox rs.Fields(i).Value
Next
rs.MoveNext
Loop

No comments:

Post a Comment