Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Working with SQL

Posted on 1998-09-14
2
Medium Priority
?
163 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 200 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

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…
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.
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

715 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