Solved

Simple ado connection to a database

Posted on 2000-02-17
3
136 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 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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Delphi Yen format 3 61
TT Auto Dashboard 13 101
CheckListBox usage 3 81
I need help using System.Web.HttpUtility.HtmlEncode in my VB.Net application 3 110
Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
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…
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…

749 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