Submitted on: 6/20/2000 4:36:27 PM
By:
Level: Intermediate

Compatibility:VB 5.0, VB 6.0, ASP (Active Server Pages)

 

 
     This code will show you how to use RDO and SQL. It is very simple to understand. You will need to learn SQL statements your self, this only shows you how to use SQL with RDO. This can be implemented into a platform, or server side application.
 
 
code:
 
Terms of Agreement:   
By using this code, you agree to the following terms...   
1) You may use this code in your own programs (and may compile it into a program and distribute it in compiled format for langauges that allow it) freely and with no charge.   
2) You MAY NOT redistribute this code (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   
3) You may link to this code from another website, but ONLY if it is not wrapped in a frame. 
4) You will abide by any additional copyright restrictions which the author may have placed in the code or code's description.

						
'**************************************
' Name: an Example of how to use RDO and
'     SQL
' Description:This code will show you ho
'     w to use RDO and SQL. It is very simple 
'     to understand. You will need to learn SQ
'     L statements your self, this only shows 
'     you how to use SQL with RDO. This can be
'     implemented into a platform, or server s
'     ide application.
' By: 
'
' Inputs:refrence to Microsoft Remote Da
'     ta Object 2.0
refrence To ODBC Driver & data source name functions
'
'This code is copyrighted and has
' limited warranties.Please see http://w
'     ww.Planet-Source-Code.com/xq/ASP/txtCode
'     Id.9085/lngWId.1/qx/vb/scripts/ShowCode.
'     htm
'for details.
'**************************************

Dim EN As rdoEnvironment
Dim CN As rdoConnection
Dim CL As rdoColumn
Public mySQL As String


Public Sub RegisterDataSource()


    'What this sub does is registers a datas
    '     ource in the
    'ODBC object in Control Panel. This is s
    '     o the RDO can
    'Talk to the SQL server.
    On Error Goto Handle
    Dim strAttribs As String
    Dim x
    'This will build a string containing the
    '     attributes
    'Description - Just a general desc. of t
    '     he server
    'OemToAnsi - Just keep it on NO
    'Server - The name of the server your co
    '     nnecting to
    'Network - Type of connection. DBMSSOCN 
    '     = TCP/IP. The only other one
    ' you should use would be Named Pipes, b
    '     ut only if your on a Lan
    'Database - Name of the database to conn
    '     ect to
    strAttribs = "Description=" _
    & "Description of server" _
    & vbCrLf & "OemToAnsi=No" _
    & vbCrLf & "SERVER=Server_Name" _
    & vbCrLf & "Network=DBMSSOCN" _
    & vbCrLf & "Database=database_name" _
    & vbCrLf & "Address=255.255.255.255"
    
    ' Create new registered DSN.Leave this
    rdoEngine.rdoRegisterDataSource "Table_name", "SQL Server", True, strAttribs
    'only thing you should change in this wo
    '     uld be the Table_Name, and Read Only
    Exit Sub
    Handle:
    MsgBox Err.Number & vbCrLf & Err.Description
End Sub




Private Sub Form_Load()


    'We will set up everything we need here
    Dim max As Long
    'Set the environment for the rdo engine
    Set EN = rdoEngine.rdoEnvironments(0)
    'Define the cursor driver
    EN.CursorDriver = rdUseOdbc
    'Open a connection to the SQL database
    Set CN = EN.OpenConnection("Table_Name", dbDriverNoPrompt, False, "driver=SQLServer; database=Database_Name; uid=User_ID; pwd=PASSWORD;")
    'Set the SQL command - For now, we will 


    '     select all of the fields
        'from the record if the UserID field is 
        '     equal to 'Dustin'
        mySQL = "SELECT * FROM Users WHERE UserID='Dustin'"
        'Users = The table name
        'This will query the database with the S
        '     QL command you gave above.
        Set RS = CN.OpenResultset(mySQL, rdOpenKeyset, rdConcurReadOnly, rdAsyncEnable + rdExecDirect)
        'this will get the total # of records it
        '     found.
        max = CInt(CN.LastQueryResults.RowCount)
        'The results are stored in the CL variab
        '     le. We will have to set them
        Set CL = RS.rdoColumns(0)
        text1.Text = CL.Value
        Set CL = RS.rdoColumns(1)
        text2.Text = CL.Value
        '...
        'easy huh?
        CN.Close 'Close connection With DB
        EN.Close 'Close the environment
        Exit Sub 'gotta Do this so it wont go streight through and Error out
        'if there was no err.
        Err:


        If Err.Number = 40006 Then 'this will popup if nothing was found
            MsgBox "No records Found"
        Else
            MsgBox Err.Description
        End If


    End Sub


Shades | Carton Netvork Games | Black Jack Game | Effective Weight Loss Pill | Discount Window Shades