Dim con as New ADODB.Connection
Dim rec as New ADODB.Recordset
con.ConnectionString = "Driver={Microsoft Access Driver (*.mdb)}; Dbq=C:\database.mdb; Uid=Admin; Pwd=;"
con.Open
rec.Open "select myfield1, myfield2 from mytable", con
Do While Not Rec.EOF
MsgBox("Record returned: " & rec("myfield1") & ", " & rec("myfield2)
Rec.MoveNext
Loop
rec.Close
con.Close
2007-01-30 00:05:11
·
answer #1
·
answered by MinstrelInTheGallery 4
·
2⤊
0⤋
Add a reference to your VB project to "Microsoft ActiveX Data Object 2.x Library"
The lastest version is 2.8, I think, at least that's my most recent version.
This is an example of a DSNless connection.
You don't have to setup an ODBC connection in the ODBC Data Source Administrator.
Then add the following code:
Dim conn As ADODB.Connection
Dim cmd As ADODB.Command
Dim rs As ADODB.Recordset
Dim sConnString As String
Dim iCtr As Integer
set conn = new adodb.connection
set cmd = new adodb.command
'MAKE SURE YOU HAVE LATEST VERSION OF
'OLE DB PROVIDERS, WHICH YOU CAN GET AT
'http://www.microsoft.com/data
'BE SURE TO INCLUDE A REFERENCE TO MICROSOFT
'ACTIVE X DATA OBJECTS IN YOUR PROJECT
' IF SQL SERVER USE SOMETHING LIKE THIS
'Data Source = Server Name
'Initial Catalog = Database
'Use your own user names and password
sConnString = "Provider=SQLOLEDB.1;User ID=sa;password=mypassword;Initial Catalog=MyDatabase;Data Source = MySQLServer;Use Procedure for Prepare=1;Auto Translate=True;Packet Size=4096"
'IN ACCESS USE SOMETHING LIKE THIS:
'Change Data Source to full path of database
sConnString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\MyDatabase.mdb"
conn.Open sConnString
Set cmd.ActiveConnection = conn
'REPLACE MYTABLE WITH YOUR OWN TABLE
cmd.CommandText = "SELECT * FROM MYTABLE"
cmd.CommandType = adCmdText
Set rs = cmd.execute
Do While Not rs.EOF
For iCtr = 0 To rs.fields.Count - 1
'OutPuts Name and Value of each field
Debug.Print rs.Fields(iCtr).Name & ": " & _
rs.Fields(iCtr).Value
Next
rs.MoveNext
Loop
Set rs = Nothing
Set cmd = Nothing
conn.Close
Set conn = Nothing
ta-daaa!
tc
2007-01-30 00:08:28
·
answer #2
·
answered by timc_fla 5
·
1⤊
0⤋
even if the blunders is coming in yet another person of an same computer OR yet another person of yet another computer. Plz verify It. even if that's the second one one attempt to Create a DSN also in his computer and artwork on the using. i imagine the first wil no longer create any difficulty. finally, replace DSN to Direct Connection utilizing ADODB
2016-12-03 05:46:50
·
answer #3
·
answered by ? 4
·
0⤊
0⤋
Get help here : http://www.thesoftwareobjects.com
2007-02-01 03:53:01
·
answer #4
·
answered by ponga 1
·
0⤊
0⤋