Results 1 to 3 of 3

Thread: Datareport Dumie

  1. #1

    Thread Starter
    Member
    Join Date
    Nov 2005
    Location
    Greece
    Posts
    61

    Datareport Dumie

    Hi all
    I have this code
    VB Code:
    1. Private Sub Form_Load()
    2. ' **** Create Connection and Recordset Objects ****
    3. Dim cnConn As ADODB.Connection
    4. Dim rs As ADODB.Recordset
    5. Dim strsql As String
    6.  
    7. ' **** Instantiate the new objects ****
    8. Set cnConn = New ADODB.Connection
    9. Set rs = New ADODB.Recordset
    10.  
    11. ' **** Set up connection String    ****
    12. With cnConn
    13.     .Provider = "SQLOLEDB.1"
    14.     .Properties("Data Source").Value = "www"
    15.     .Properties("User ID").Value = "clroot"
    16.     .Properties("Password").Value = "clroot"
    17.     .Properties("Initial Catalog").Value = "iosif"
    18.     .CursorLocation = adUseClient
    19.     .ConnectionTimeout = 0
    20.     .Open
    21. End With
    22.  
    23. ' **** String to pass to the connection to get records back ****
    24. strsql = "select * from salesman"
    25.  
    26. ' **** Open Records for readonly ****
    27. rs.Open strsql, cnConn, adOpenStatic, adLockReadOnly

    How I can pass values from table salesman into a datareport1?

    thank you






    Edit: Added [vbcode][/vbcode] tags for more clarity. - Hack
    Last edited by Hack; Nov 14th, 2005 at 01:22 PM.

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Datareport Dumie

    Moved to reporting section.

  3. #3
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758

    Re: Datareport Dumie

    You must set the DataField property of each control on the report equal to a field name in the recordset. This can be done at runtime or designtime.

    I added the code required to set the datareport's datasource to the recordset.

    VB Code:
    1. Private Sub Form_Load()
    2. ' **** Create Connection and Recordset Objects ****
    3. Dim cnConn As ADODB.Connection
    4. Dim rs As ADODB.Recordset
    5. Dim strsql As String
    6.  
    7. ' **** Instantiate the new objects ****
    8. Set cnConn = New ADODB.Connection
    9. Set rs = New ADODB.Recordset
    10.  
    11. ' **** Set up connection String    ****
    12. With cnConn
    13.     .Provider = "SQLOLEDB.1"
    14.     .Properties("Data Source").Value = "www"
    15.     .Properties("User ID").Value = "clroot"
    16.     .Properties("Password").Value = "clroot"
    17.     .Properties("Initial Catalog").Value = "iosif"
    18.     .CursorLocation = adUseClient
    19.     .ConnectionTimeout = 0
    20.     .Open
    21. End With
    22.  
    23. ' **** String to pass to the connection to get records back ****
    24. strsql = "select * from salesman"
    25.  
    26. ' **** Open Records for readonly ****
    27. rs.Open strsql, cnConn, adOpenStatic, adLockReadOnly
    28.  
    29. [B]'Disconnect recordset from db
    30. Set rs.ActiveConnection = Nothing
    31. db.close
    32. set db = nothing
    33.  
    34. Load DataReport1
    35. Set DataReport1.DataSource = rs
    36. DataReport1.Show
    37.  
    38. set rs = Nothing[/B]

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