Solved

SQL Select with VB6

Posted on 2011-03-06
2
784 Views
Last Modified: 2012-05-11
I know this has been answered many times but can't find the exact answer I am looking forward.  I am connecting to a database from which I want to lean how to use SQL statements in VB6.  I want to be able to select records and then output them in a text file (or screen if desired).  Once I execute the SQL SELECT * FROM database name WHERE ... how do I get just those records to the text file or screen and not the whole database.  Can someone give me some sample code?
0
Comment
Question by:grandrew
2 Comments
 

Author Comment

by:grandrew
ID: 35047607
While that is a nice site, it does not show me how to integrate with VB6.
0
 
LVL 14

Accepted Solution

by:
Brook Braswell earned 500 total points
ID: 35056101
Q1.  How to get just those records ... and not the whole database..
   A1.  Seems like your example should be SQL = "Select Fields from Table where condition"
   Example:
  DIM SQL AS STRING
  Dim RS as new adodb.recordset
  Dim CN as new adodb.connection

  cn.open "connection to your database"
  SQL = "SELECT ADDRESS, NAME FROM CUSTOMERS WHERE STATE = 'Texas' "
  rs.open SQL,CN, adOpenStatic, adLockBatchOptimistic
  DO WHILE NOT RS.EOF
  ' OUTPUT AS DESIRED....
   RS.MOVENEXT
  LOOP

Q2.  output them in a text file (or screen if desired)
   A2.  So you want an example of text file out put?
    Example:
    Dim sFile as string
    Dim SQL AS STRING
    Dim RS as new adodb.recordset
    Dim CN as new adodb.connection

    sFile = app.path & "\OutPut.txt"
    open sFile for output as #1

  cn.open "connection to your database"
  SQL = "SELECT ADDRESS, NAME FROM CUSTOMERS WHERE STATE = 'Texas' "
  rs.open SQL,CN, adOpenStatic, adLockBatchOptimistic
  DO WHILE NOT RS.EOF
       Print #1, RS!NAME & ", " & RS!ADDRESS
      RS.MOVENEXT
  LOOP
 Close #1
   
 If you wish this to out put to the screen then you need a grid control or other ActiveX object..
   then bind your RS to that object...
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

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…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
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…

803 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