Solved

Simple ado connection to a database

Posted on 2000-02-17
3
130 Views
Last Modified: 2013-11-23
I want to create a simple ado connection to a database.. I have previously used ASP to do this, now we are creating a VB application in which I never had done this..

here is my ASP code:
dim getdata

getdata = "Select ticket_number from ticketdetails"

myDSN="DSN=ardata;
set conntemp=server.createobject("adodb.connection")

conntemp.open myDSN
set rstemp=conntemp.execute(getdata)

Now I am looking at the easiest way to get this accomplished in vb without using the ADODC objects.. hopefully something similar to the way I do it above.. If you know of a better way I should be doing this other than odbc adn recordsets, I am open to suggestions..
Thanks
0
Comment
Question by:tchous
3 Comments
 
LVL 43

Accepted Solution

by:
TimCottee earned 70 total points
Comment Utility
Dim GetData As String
Dim conntemp As ADODB.Connection
Dim rstemp as ADODB.Recordset
Set conntemp = New ADODB.Connection
myDSN = "DSN=ardata"
conntemp.Open myDSN
Set rstemp = New ADODB.Recordset
rstemp.Open GetData,conntemp
'Then do your stuff
rstemp.Close
conntemp.Close
Set rstemp = Nothing
Set conntemp = Nothing

By the way, I think you have double-posted this question.
0
 
LVL 6

Expert Comment

by:Marine
Comment Utility
Here is the example where i am using OLEDB Drivers instead of ODBC DSN.whe you mean ADODC object you spcefically mentioning about its data control. Its good if you want to deal with bound data controls. It can be time saving but its limited to certain things like flexibility of use. OK My example uses OLEDB drivers and ADO objects in code.

Dim sCon as string
Dim rsUser as New ADODB.Recrodset
Dim cnUser as New ADODB.Connection

sCon = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=C:\my documents\mb.mdb;"
cnUser.Open scon
sSql = "Select * From t_user"
rsUser.Open ssql,cnUser,2,1
Ok this opens connection to your database and the creates a recordset based on your table User. for example now you want to populate listbox with some data from Field User in your database. You do this like this.
Do while not rsUser.Eof
   List1.additem rsUser("user")
loop
this will populate the listox with all the users taken from Field User in your table.

Ok the way you open your recordset is fine. The only problem with it is it READ-Only now. When you execute the connection object to create a recordset it will be read-only.
Now the other persons example will aslo create a read only recordset since he didn't specify what type of recordset he opened.
rstemp.Open GetData,conntemp
'Then do your stuff
Well i hope this helps a bit.
0
 

Author Comment

by:tchous
Comment Utility
Thanks for the solution. I was on the right track, just got a little confused on the syntax..
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now