Results 1 to 4 of 4

Thread: Using Data Report with MySQL *resolved*

  1. #1

    Thread Starter
    Member superfrog80's Avatar
    Join Date
    Aug 2003
    Location
    Ma-Lai-Xi-Ya
    Posts
    32

    Using Data Report with MySQL *resolved*

    I'm trying to make a report based on information from a database (in my case, it's MySQL)...

    I tried searching in the MSDN, and only got info about making a report from access (*.mdb) files...
    All the necessary parameters are set during design time...

    Is there another way that i can extract info from a database like MySQL?
    I'm currently using connection strings and SQL statements (which are defined during runtime) to connect to the MySQL database...

    Can anyone help me with this?

    Thanx in advance..
    ;p
    Last edited by superfrog80; Sep 30th, 2003 at 04:10 AM.

  2. #2
    Fanatic Member vb_dba's Avatar
    Join Date
    Jun 2001
    Location
    Somewhere aloft between the real world and insanity
    Posts
    1,016
    Add a DataReport to your project (Project->Add Data Report). Add label's for your captions/headers and TextBoxes for your data fields. Set the DataField property for each TextBox to it's corresponding field from the database.

    In the DataReport_Initialize method, create a recordset containing the information you wish to return from the database and set the datasource of the report to the recordset:
    VB Code:
    1. Private Sub DataReport_Initialize()
    2. On Error GoTo errHandler
    3.     Dim sSql   As String
    4.     Dim sConStr As String
    5.     Dim oCon    As Connection
    6.     Dim oRS      As Recordset
    7.    
    8.     sConStr = "Your Connection String"
    9.    
    10.     'Define your query
    11.     sSql = "Select * From MYTABLE"
    12.        
    13.     Set oConn = New Connection
    14.     With oConn
    15.         .CursorLocation = adUseClient
    16.         .CommandTimeout = 10
    17.         .Open sConStr
    18.     End With
    19.  
    20.     Set oRS = New Recordset
    21.     oRS.Open sSQL, oConn, adOpenStatic, adLockReadOnly
    22.    
    23.     If Not oRS.BOF And Not oRS.EOF Then
    24.         Set Me.Datasource = oRS
    25.     Else
    26.         MsgBox "No Records Found.", vbExclamation + vbOKOnly, "Invalid Recordset"
    27.         oRS.Close
    28.         Set oRS = Nothing
    29.         bOpen = False
    30.         oConn.Close
    31.         Set oConn = Nothing
    32.         Unload Me
    33.     End If
    34.  
    35.     Exit Sub
    36. errHandler:
    37.     Msgbox err.number & vbcrlf & vbcrlf & err.description
    38. End Sub
    Chris

    Master Of My Domain
    Got A Question? Look Here First

  3. #3

    Thread Starter
    Member superfrog80's Avatar
    Join Date
    Aug 2003
    Location
    Ma-Lai-Xi-Ya
    Posts
    32
    thanx man!!...
    jez wat i needed!!
    ;p

  4. #4
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170
    Hey, you're a frog too.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width