Solved

Working with SQL

Posted on 1998-09-14
2
157 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

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

Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we 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.
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

739 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