Results 1 to 6 of 6

Thread: Existing RPT file, different DataSorce - HOW?

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jul 2007
    Posts
    64

    Existing RPT file, different DataSorce - HOW?

    Hello,

    I am migrating a database from DB2 to SQL Server.

    There is an application that prints a very important Crystal Report, based on DB2 data. I can see one *.RPT and *.TTX file in the application folder.

    I did an ODBC trace and got the DB queries that this application uses to create the report.

    Now, I want to create a new application (VB.Net 2005) that will render this *RPT file with the very same data, but with the "SQL Server" source, instead of the old "DB2" one.

    I have downloaded a trial of Crystal Reports 2008, and opened the RPT file.

    I have never worked with crystal reports before. so, I don't know where to start...

    How do I tell Crystal that the datasource is different, preserving the existing fields?
    Then, how do I call and preview the report?

    Can you please help me?

    Thanks,
    JaVo

  2. #2

    Thread Starter
    Lively Member
    Join Date
    Jul 2007
    Posts
    64

    Re: Existing RPT file, different DataSorce - HOW?

    Well, I found a post saying that under VB.Net we could use a .XSD schema, instead of the TTX, as they basically do the same. Is that correct?

    I have already created a XSD file from the query traced from the old application.
    Is it possible to use it, without "touching" the report layout?

  3. #3
    PowerPoster
    Join Date
    Sep 2005
    Location
    Modesto, Ca.
    Posts
    5,040

    Re: Existing RPT file, different DataSorce - HOW?

    There is alot of information on setting a CR datasource already posted in this forum.
    Here is an example from one of my applications.
    Code:
            Dim rpt As New rptEmployeeRecord
            Dim frm As New frmReports
            Dim ds As New LeaveDataSet, ta As New LeaveApp.LeaveDataSetTableAdapters.employeeTableAdapter
            Dim taD As New LeaveApp.LeaveDataSetTableAdapters.daysTableAdapter
            ta.Fill(ds.employee)
            taD.Fill(ds.days)
            rpt.SetDataSource(ds)
            frm.CrystalReportViewer1.ReportSource = rpt
            frm.ShowDialog()
            rpt.Dispose()
            frm.Dispose()
    Also you can add the report to your .Net project and then edit the datasource. Select:
    Crystal Reports->Database->Set Datasource Location
    or use:
    Crystal Reports->Database->Database Expert

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Jul 2007
    Posts
    64

    Re: Existing RPT file, different DataSorce - HOW?

    Hello,

    This is what I've done so far:

    - Created a XSD schema out of the query that will fill the existing report.
    - Changed the original RPT file. Replaced the datasource (XSD OleDB, instead of the original TTX). Replaced ALL data fields to the new OleDB ones.

    In Visual Basic:

    vb Code:
    1. Private con As OdbcConnection
    2. Private da As OdbcDataAdapter
    3. Private ds As DataSet


    vb Code:
    1. Dim sql As String = "SELECT field1, field2, ... FROM mytable WHERE field1 = ..."
    2. con = New OdbcConnection("DSN=xxx;UID=xxx;PWD=xxx")
    3. da = New OdbcDataAdapter(sql, con)
    4. ds = new dataset
    5. da.Fill(ds)
    6.  
    7. Dim rpt As ReportDocument = New ReportDocument()
    8. rpt.Load("C:\reports\crystalsample.rpt")
    9. rpt.Database.Tables(0).SetDataSource(ds)
    10. CrystalReportViewer1.ReportSource = rpt

    No error, No messages, nothing.
    The report displays no data. Blank. Only header fields.
    I know my query is returning records and I can see them in a datagrid...

    Please... I am stuck on this problem for so much time, I'm desperate!

    Thanks!

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Jul 2007
    Posts
    64

    Re: Existing RPT file, different DataSorce - HOW?

    I have the above problem solved.

    I am now using a typed DataSet (typed with the same XSD that was used to build the report).

    Now I have something: An error (which is better than having nothing )


    Code:
    'my typed dataset: ds_xml
    da.Fill(ds_xml, ds_xml.Tables(0).TableName)
    
    Dim rpt As ReportDocument = New ReportDocument()
    rpt.Load("C:\reports\crystalsample.rpt")
    rpt.Database.Tables(0).SetDataSource(ds_xml.Tables(0))
    
    msgbox(rpt.Rows.Count.toString) 'this pops "44"
    
    'ERROR HERE:
    CrystalReportViewer1.ReportSource = rpt
    Error message:
    "Failed to load database information"

    There is NO WAY the source data does not fit the RPT file, since they both use the same XSD schema!
    What else can be wrong?

    Please... someone help...

  6. #6

    Thread Starter
    Lively Member
    Join Date
    Jul 2007
    Posts
    64

    Re: Existing RPT file, different DataSorce - HOW?

    I've been struggling with this for DAYS!

    Now I know the reason for this "Failed to load database information".
    This report has a SUB Report.
    If I remove the subreport, the main report renders JUST FINE!

    I did the trace again (when the original report is being build), and I coud see 2 queries.

    Already taken care of the first one (main report) - it runs from a different datasource now.

    How do I change the datasource for the Sub-Report? I don't have the 2nd RPT file... only the main report... Is there anyway of changing this sub-report datasource to an ADOnet (XML)?

    Please Help...

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