Click here to Skip to main content
15,920,438 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi everybody,
I have an invoice that I want to load in a crystal report,
but the problem is that every time I load an invoice,
the old data remains in the report, and the new data is added to it !!

I tried few things but it seems I can't get it right, any help please ??

This is the code loading the invoice data in the crystal report :

VB
Private Sub InvoiceReport(ByVal pInvoiceID As String)
    Dim lCryRpt As New ReportDocument
    Dim ds As New DataSet
    Dim lsql As String
    Dim lXMLPath As String
    Dim lRPTPath As String

    lXMLPath = "C:\Alumeel\Reports\InvoiceSheet.xml"
    lRPTPath = "C:\Alumeel\Reports\InvoiceSheet.rpt"

    lsql = "Select * From InvoiceItems Where InvoiceID = " & pInvoiceID
    mdb.FillMyDataSet(lsql, ds, "Invoice")
    ds.WriteXmlSchema(lXMLPath)
    lCryRpt.Load(lRPTPath)
    lCryRpt.SetDataSource(ds)
    Me.CrystalReportViewer1.ReportSource = lCryRpt
    Me.CrystalReportViewer1.Update()
    Me.CrystalReportViewer1.Refresh()
    Me.Show()
End Sub
Posted

1 solution

Check that your report doesn't have the option "Save data..." on. Otherwise the report will contain old data. Also if you like you can use DiscardSavedData method
 
Share this answer
 
Comments
saleem_deek 30-Dec-11 17:45pm    
I couldn't find this method, nor the "Save data" option :S
Maybe I had to mention that I'm using the crystal report viewer ??
Or can you tell me please why I couldn't see such option or method :S
Wendelius 30-Dec-11 18:28pm    
Currently I don't have CR to test find the option, but if I recall correctly, it was somewher in report options. SOmething like "save data with report...".
saleem_deek 31-Dec-11 21:16pm    
Yeah I found this solution on many web pages, but it seems that the version I have is different, because there is no such property or option :(
Do you any idea what can I do, I have to finish this project soon, and this is a problem for me.. But thx anyway for your help, I really appreciate it ...
Wendelius 2-Jan-12 3:35am    
That's odd. The option has been there for several years. Have a look at this instruction. Perhaps it's somewhere near in that dialog: http://www.tek-tips.com/faqs.cfm?fid=1006[^]
saleem_deek 2-Jan-12 5:09am    
Ok I found what you told me about, but a little bit different way: In the top menu (File, Edit, ...) There is a "Crystal Reports" menu, Crystal Reports->Database->Log On or Off Server, I clicked on log off, Then Crystal Reports->Design-Default Settings->Reporting Tab and I checked "Discard Saved Data When Loading Reports".. Then I run my code, loaded my report, and still, the old data is loaded with the new one !! If you want give me your email so I can upload snapshots of what I exactly did, maybe this can help in figuring out the problem.. I'm really sorry, but you're the only one that offered help !! :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900