Link to home
Start Free TrialLog in
Avatar of Vaughn Whitehead
Vaughn WhiteheadFlag for United States of America

asked on

Crystal Reports - Always saving data

Greetings,

My Crystal Report  saves data and then on the next run, the data doubles.  Below is my code:

Try
            With crConnectionInfo
                .DatabaseName = dbase
                .UserID = ""
                .Password = ""
            End With
            CrTables = cryRpt.Database.Tables
            For Each CrTable In CrTables
                crtableLogoninfo = CrTable.LogOnInfo
                crtableLogoninfo.ConnectionInfo = crConnectionInfo
                CrTable.ApplyLogOnInfo(crtableLogoninfo)
            Next
            cryRpt.SetDatabaseLogon("", "")
   
           crViewerStats.ReportSource = cryRpt
           cryRpt.Refresh()
           crViewerStats.Refresh()
           crViewerStats.PrintReport()
           
        Catch ex As Exception
                        MessageBox.Show("Problem printing reports: " & ex.Message, "",        MessageBoxButtons.OK, MessageBoxIcon.Error)
        End Try

I refresh the report and viewer, but the report adds the new data to the previous data.  It's obviously storing the data in the report.

Thanks

VW
Avatar of Mike McCracken
Mike McCracken

Do you have the SAVE DATA WITH REPORT option set?
If so turn it off

Try using this line before the refresh
  cryRpt.DiscardSavedData

mlmcc
Avatar of Vaughn Whitehead

ASKER

Yes, I have the Save Data with Report unchecked .   This is what makes no sense.  With the Save data report unchecked, why would the data be reused.  I checked the database to be sure that the data was not being doubled, but but it is being erased and then rewritten.

The   cryRpt.DiscardSavedData  command gives me the cannot resolve symbol error. ??

VW
Try using only 1 refresh or remove both refreshes.

If there is no saved data then there is no need to refresh.

mlmcc
The problem has taken another turn. The process dumps exam scores to the database and then the CR generates standard  stats (mean, median, mode, sd, reliability, etc.    mimcc (above response) got me to thinking about the saved data.  My first stat is a count of the records.  

Count ({ExamGrades.Score})  

This field keeps incrementing, but the other stats are being computed correctly.  So, why would the count not correctly indicate the correct number or records?

Actually, I guess this may be a second question.  

VW
Does the process clear the database/table before adding records?

mlmcc
Yes, I delete all the records before I write to the table.   When the report is stating that there are 400 records, i can pull up the database and only have 148
What SQL is the report running when it shows 400?

mlmcc
If you refresh the report does it show the correct amount?

mlmcc
I am using a Select All query.  I had the refresh reports in, but will try putting them in again.  The really strange part is if I run the report; open the database and manually adjust some of the scores, and then refresh the report, the stats are correctly changed, but the number of records is still incorrect.

One other point.  I originally create the report in the IDE, but have occassionally used Crystal Reports 2008 to view the report and sometimes make minor changes to the formatting.  Could this be a problem?

Thanks for your input and time.

VW
How are you getting the number of records?

The editting in CR2008 is possibly the issue but CR4VS2010 was supposed to be CR v13 which I would think included all of CR2008 (v12)

mlmcc
I am using the CR Count{} funtion.
Can you upload the report?

mlmcc
The report and db did not upload.  Will do it again tonight.
I don't see anything in the report that would cause the issue.

what code do you use to update the data?

mlmcc
I use oledb. I use a delete all before the insert into.  After the insert there are only 148  records.  How the count function returns there increasing number, is strange. Could the fact that the functions are in the header cause a problem?
ASKER CERTIFIED SOLUTION
Avatar of Mike McCracken
Mike McCracken

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I delete with code.  I will modify to see the records.  I delete the records and then open the report.
I display the records in the report and there are approx 1200. ) It keeps incrementing each time.)  While the report is being displayed, I open the database and there are 89 records.

???
Now for the strange part.  If I print the scores in the detail section of the report and place the data in the Report Footer, everything prints correctly.   I guess I will stay with this.  I appreciate the input and time from mimcc and am going to award the points  

Thanks again