Results 1 to 5 of 5

Thread: changing Datasource at runtime CRXI

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Sep 2004
    Location
    Las Vegas, NV
    Posts
    29

    changing Datasource at runtime CRXI

    Hi All and thanks for the help in advance. I have been reading thread after thread trying to figure out how to change the database of a Crystal Reports XI at runtime using VS 2002.

    This is what I have so far, it seems like a simple thing to do but I keep getting an error on “crxDatabaseTables = crxReport.Database.Tables”

    The error reads,
    An unhandled exception of type 'System.InvalidCastException' occurred in PTS.exe

    Additional information: Specified cast is not valid.

    Any help would be appreciated

    Thanks Chuck from Las Vegas


    Code:
            Dim crxApp As New CRAXDDRT.Application()
            Dim crxReport As CRAXDDRT.Report
            Dim ReportName As String
            Dim crxDatabaseTable As CRAXDDRT.DatabaseTable
    
            Dim crxDatabaseTables As Tables
    
            crxApp = CreateObject("crystalruntime.application.11") 
    
            ReportName = System.Windows.Forms.Application.StartupPath & "\" & Frm1.CBReports.SelectedValue
    
            crxReport = crxApp.OpenReport(ReportName)
    
            crxDatabaseTables = crxReport.Database.Tables
    
            For Each crxDatabaseTable In crxDatabaseTables
                crxDatabaseTable.Location = System.Windows.Forms.Application.StartupPath & "\" & Frm1.FileText
            Next crxDatabaseTable
    
            CrystalReportViewer.ReportSource = crxReport

  2. #2

    Thread Starter
    Junior Member
    Join Date
    Sep 2004
    Location
    Las Vegas, NV
    Posts
    29

    Re: changing Datasource at runtime CRXI

    Can someone please help me with this it is making me crazy..

    Thanks Chuck

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

    Re: changing Datasource at runtime CRXI

    The Crystal RDC Library does not contain a Tables class, use

    Dim crxDatabaseTables As CRAXDDRT.DatabaseTables

  4. #4

    Thread Starter
    Junior Member
    Join Date
    Sep 2004
    Location
    Las Vegas, NV
    Posts
    29

    Re: changing Datasource at runtime CRXI

    Hi Brucevde,

    Thanks for the reply. I will give that a try later, when I get to my other machine.

    Chuck

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Sep 2004
    Location
    Las Vegas, NV
    Posts
    29

    Re: changing Datasource at runtime CRXI

    Thanks that solved the Tables issue. However when previewing the report using
    Code:
    CrystalReportViewer.ReportSource = crxReport
    I get the error “Invalid Report Source”. I changed the report source to
    Code:
    CrystalReportViewer.ReportSource = ReportName
    and I get the report but the database will not change. I can change the report source by supplying the entire path and “reportname.rpt”. But will not change the database.

    Any suggestions

    Thanks Chuck


    Code:
    Dim crxApp As New CRAXDDRT.Application()
            Dim crxReport As CRAXDDRT.Report
            Dim ReportName As String
            Dim crxDatabaseTable As CRAXDDRT.DatabaseTable
            Dim crxDatabaseTables As CRAXDDRT.DatabaseTables
    
            crxApp = CreateObject("crystalruntime.application.11")
    
    
            ReportName = System.Windows.Forms.Application.StartupPath & "\" & Frm1.CBReports.SelectedValue
            crxReport = crxApp.OpenReport(ReportName)
    
            crxDatabaseTables = crxReport.Database.Tables
    
            For Each crxDatabaseTable In crxDatabaseTables
                crxDatabaseTable.Location = System.Windows.Forms.Application.StartupPath & "\" & Frm1.FileText
            Next crxDatabaseTable
    
            CrystalReportViewer.ReportSource = crxReport

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