Results 1 to 5 of 5

Thread: CR & VB Not returning expected results?

  1. #1

    Thread Starter
    Hyperactive Member Pozzi's Avatar
    Join Date
    Feb 2001
    Location
    The Stones!
    Posts
    507

    Question CR & VB Not returning expected results?

    I'm running a report within a VB wrapper. However the data returned isn't what's expected.

    Attached is what I get returned when running the following code: -

    VB Code:
    1. Option Explicit
    2.  
    3. Dim crxApp As New CRAXDRT.Application
    4. Dim CRXRpt As CRAXDRT.Report
    5. Dim CRXDB As CRAXDRT.Database
    6. Dim CRXTbl As CRAXDRT.DatabaseTable
    7.  
    8.  
    9. Private Sub Form_Load()
    10.  
    11. Dim rs As ADODB.Recordset
    12. Dim cn As ADODB.Connection
    13. Dim crxReport As CRAXDRT.Report
    14. Dim crxApp As CRAXDRT.Application
    15. Dim crxTable As CRAXDRT.DatabaseTable
    16. Dim sql As String
    17.  
    18. Set cn = New ADODB.Connection
    19. Set rs = New ADODB.Recordset
    20. Set crxApp = New CRAXDRT.Application
    21. Set crxReport = crxApp.OpenReport("C:\Test.rpt", 1)
    22.  
    23. sql = "SELECT TB_CASHREGS.DESCRIPTION, TB_TRANS_CARDS.LOAD_CASH, TB_TRANS_CARDS.SALDO_CASH, " & _
    24.                 "TB_CUSTOMERS.CARD_NUM, TB_CUSTOMERS.DESCRIPTION " & _
    25.                 "FROM TB_TRANSACTIONS, TB_CASHREGS, TB_CUSTOMERS, TB_TRANS_CARDS " & _
    26.                 "WHERE  TB_TRANSACTIONS.CASHREG_ID = TB_CASHREGS.ID " & _
    27.                 "AND TB_TRANSACTIONS.CARD_NUM = TB_CUSTOMERS.CARD_NUM " & _
    28.                 "AND TB_TRANSACTIONS.ID = TB_TRANS_CARDS.TRANSACTION_ID " & _
    29.                 "AND TB_TRANSACTIONS.CARD_NUM = '1052'"
    30.  
    31. cn.Open "Provider=OraOLEDB.Oracle; Data Source=tcpos; User Id=lyons; Password=matrix;"
    32.  
    33. rs.Open sql, cn, adOpenKeyset
    34.  
    35. 'now verify all tables within the report
    36.  For Each crxTable In crxReport.Database.Tables
    37.       With crxTable.ConnectionProperties
    38.         .Item("Provider") = "OraOLEDB.Oracle"
    39.         .Item("Data source") = "tcpos"
    40.         '.Item("Initial Catalog") = " " 'if none, use ""
    41.         .Item("User ID") = "lyons"
    42.         .Item("Password") = "matrix"
    43.       End With
    44. Next
    45.  
    46.     crxReport.DiscardSavedData
    47.     crxReport.Database.SetDataSource rs
    48.      
    49.     CRViewer91.ReportSource = crxReport
    50.     CRViewer91.ViewReport
    51.    
    52. End Sub

    This isn't the same as when run through crystal or when the query is run directly against the DB.

    As can be clearly seen the records are just the first repeated.

    Any idea what I've missed?

    I've looked through the Crsytal help, but nothing, to be honest not the best on-line help

    Any help would be appreciated.

    Regards
    Attached Images Attached Images  
    Last edited by Pozzi; Jun 3rd, 2004 at 06:06 AM.
    VB.Net (VS 2010)

  2. #2
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758
    No idea why you are getting duplicate records but for starters comment out all the code that deals with the ADO recordset. The report will connect to Oracle on its own. Does setting the Datasource to a Recordset over-ride the retrieving data directly from Oracle? Or will Crystal link both?

  3. #3

    Thread Starter
    Hyperactive Member Pozzi's Avatar
    Join Date
    Feb 2001
    Location
    The Stones!
    Posts
    507
    Thanks for the reply.

    The reason I've got the ADO in the code is because I want to develope the report so that the user can select different Card Numbers (CRAD_NUM) and then run the report, rather than having it as static.

    This is possible isn't it?

    Regards
    VB.Net (VS 2010)

  4. #4
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758
    Usually its one or the other. IE the report does all (or most of the work) by connecting to the database or your VB code connects and passes the data source to the report.

    Create a Parameter in your report. You can then prompt for and pass the parameter value from VB to the report.

  5. #5
    Hyperactive Member ARPRINCE's Avatar
    Join Date
    Mar 2003
    Location
    Pinoy in NJ
    Posts
    381
    Try this one if it works.

    VB Code:
    1. Set crxReport = crxApp.OpenReport("C:\Test.rpt")
    2.      .
    3.      .
    4.      .
    5.      crxReport.Database.SetDataSource rs, 3, 1

    BTW, I would rather use SPROC rather than using a dynamic recordset populating the report. Once you access your report in your VB program, it CR automatically prompts for the parameter that the end user needs to type in.

    I guess if the report is a simple one it is OK. However, I later found out that this was totally challenging and inflexible when the report gets more complex especially when you have sub-reports. So basically, I droped this method (ADO - dynamic rs) of populating my CR report.

    Or as Bruce pointed out, instead of a SPROC, create a parameter in your report inside CR instead.
    Last edited by ARPRINCE; Jun 3rd, 2004 at 06:18 PM.

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