Solved

Simple ado connection to a database

Posted on 2000-02-17
3
135 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
ID: 2531695
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
ID: 2532421
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
ID: 2532656
Thanks for the solution. I was on the right track, just got a little confused on the syntax..
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

809 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