|
-
Aug 9th, 1999, 01:45 AM
#1
Thread Starter
Junior Member
I think I should be able to find this info, but so far I've found everything but. I need to get started with ADO. I've written DB apps with DAO in VB5, and I'm not a beginner, but I can't seem to get any traction in the mountain of VB6 information. What file do you need to add to the tool box components for ADO? How do you do all the basic stuff: make a DB object, and a recordset object...all that. If I'm just not seeing where I'm supposed to be looking, somebody please clue me in.
Thanks,
Dave
------------------
-
Aug 9th, 1999, 03:40 AM
#2
New Member
You need to add ADO reference library to your project. CLick on Project | Reference and then select Microsoft Active X Data Object library.
After that you can declare an ADODB objects. I haven't used the ADO control, but if you want to add that to your project then click on Project | Components and then select Microsoft Active X Data Object 2.1 to your project. That allows you to use the ADODC ( I don't like it)
After declaring an ADO object (Dim cn as ADODB.Connection, rs as ADODB.Recordset)
You set the connect string (I use "DRIVER=MySQL;DB=dbname;SERVER=myserver;UID=username;PWD=pwd") by cn.ADODBConnectString (though I don't use it)
then cn.Open (if you set the connect string, or cn.Open "String" if you haven't)
-
Aug 9th, 1999, 05:23 AM
#3
Thread Starter
Junior Member
OK, so far,so good. Thanks for that. I actually have simpler needs in that I'll be connecting to an Access database stored in the same directory as the application. Can you tell me how I'd do that, and then what the syntax would be for referencing fields?
Dave
-
Aug 10th, 1999, 03:35 AM
#4
New Member
Okay. Instead of using DRIVER use PROVIDER as in : "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Program Files\Microsoft Visual Studio\VB98\Biblio.mdb;Persist Security Info=False" for the connect string.
Everything else is the same.
Dim cn as ADODB.connection
Dim rs as ADODB.Recordset
set cn = New connection
cn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Program Files\Microsoft Visual Studio\VB98\Biblio.mdb;Persist Security Info=False"
rs.open "SELECT * FROM Authors", cn
to reference the fields, I use rs.fields.item(index)
I haven't used Jet at all. I would bet that it works better than MySQL. You might have to set the cursor to be able to move backwards. You might even be able to reference the fields by name. I have always just used the index though.
To fill a listbox with author names (say authors is the 3rd field)
do while not rs.eof
list1.additem rs.fields.item(2) 'the fields start with 0
rs.movenext
loop
hope that helps
[This message has been edited by thorne (edited 08-10-1999).]
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|