Solved

Working with SQL

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
SSRS expression Issue finding a string 10 65
MsgBox 2 47
Access 2013 combo box not working 3 38
Recommendation vb6 to vb.net or others 14 105
I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…

919 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

12 Experts available now in Live!

Get 1:1 Help Now