?
Solved

Simple ado connection to a database

Posted on 2000-02-17
3
Medium Priority
?
141 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 43

Accepted Solution

by:
TimCottee earned 280 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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 have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…
Suggested Courses

719 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