Solved

Working with SQL

Posted on 1998-09-14
2
159 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
[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
  • 2
2 Comments
 
LVL 1

Accepted Solution

by:
haas090897 earned 100 total points
ID: 1434691
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
ID: 1434692
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

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

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

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
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…
Suggested Courses
Course of the Month3 days, 17 hours left to enroll

630 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