Solved

Working with SQL

Posted on 1998-09-14
2
152 Views
Last Modified: 2011-09-20
How can I, without using controls, connect to an sql database and fetch data from there? I'm using vb enterprise edition version 5.0.
Please insert source code.
0
Comment
Question by:cybernide
  • 2
2 Comments
 
LVL 1

Accepted Solution

by:
haas090897 earned 100 total points
Comment Utility
First you need to set a which type of data access you want. That is done with the menu Projects/References
I always use Microsoft Remote Data Objects 2.0.
If you prefere some other dataaccess please let me know.

Here is the code:

Dim db As rdoConnection      'Database connection
Dim rs As rdoResultset   'The resultset with data
Dim i as integer

Set db=rdoEnvironments(0).OpenConnection("Inca", _ rdDriverComplete, False)
Set rs=db.OpenResultset("SELECT * FROM MyTableName",_ rdOpenForwardOnly) 'a forwardonly scrolling resultset,
'you may want another resultset type for writing data

Do until rs.eof
   For I = 0 to Ubound(MyTextControlArray)
      MyTextControlArray(i).text=rs(MyTextControlArray.DataField)
      'This row takes the DataField name from the textcontrol to catch the data from the resultset field with the same name
   Next
   rs.movenext
loop
rs.Close

'This code will read data from database into some text controls named MyTextControlArray, but you can do some other stuff with the data. If you like to write data back to database you can
change the resultset type to rdOpenDynamic and then use this code:

   rs.Edit ' .addNew if you want a new record
   For I = 0 to Ubound(MyTextControlArray)
      rs(MyTextControlArray.DataField)=MyTextControlArray(i).text
      'You may want to check the datatype before writing to rs
   Next
   rs.Close
0
 
LVL 1

Expert Comment

by:haas090897
Comment Utility
In my example above, please note that Inca is the name of the ODBC Datasource name which i set up in Controlpanel
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
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 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…
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…

743 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

16 Experts available now in Live!

Get 1:1 Help Now