Question about data filtering in Crystal Report

  • Thread starter Thread starter Ray
  • Start date Start date
R

Ray

Hi all,
While I use the ReportDocument of vb.net to set filter to the data to the
Crystal Report, it is successful for the first time while running the
program. However, for the second time while running the program, when I set
filter to other set of data, all the data is lost.

Please help.
Thanks a lot,
Ray
 
Dear Bernie,
Here is the code.

## Code for define the Report Document
Dim ReportDoc As New ReportDocument
Dim pfieldname As String = "abc"
Dim StrReport As String = ""
StrReport = "E:\test.rpt"
ReportDoc.Load(StrReport)
For Each table In ReportDoc.Database.Tables
logoninfo = table.LogOnInfo
With logoninfo.ConnectionInfo
.ServerName = "SERVER"
.DatabaseName = "Sea"
.UserID = "admin"
.Password = "abcd3"
End With
table.ApplyLogOnInfo(logoninfo)
Next table
ReportDoc.RecordSelectionFormula = "{TableName.fieldname} = """ &
pfieldname & """"
Dim Form As New frmPrintForm(temp, ReportDoc, blnPrintsw)
Form.Show()
###################################

I have created another form and put the crystalreportviewer on it. I pass
the ReportDocument defined by the code above to this form and the code is
Me.CRViewer.ReportSource = ReportDoc

Thanks a lot,
Ray
 
Hi Ray,

OK, looked at the code. When you call the report the second time, what is
the value of pfieldname and what code calls the report? It must be
different code, because if you called this code again, pfieldname would have
to be the same (ie, abc).

Bernie
 
Dear Bernie,
I use the text box to input the data name should be filtered and then
pass to the ReportDocument.
So I use the same code in the second time also. For the first time, I
call the report by input a data name to the text box while running the
program, then I close the report, then I input another data name to the text
box and call the report again. For this time, the necessary data cannot be
filtered out.
It seems that the report's data has been filtered to the data in the first
time, and since the data in the second time is not within the data in the
first time, so the data in the second time cannot be filtered out.
Is there any problems for my code?
Thanks a lot,
Ray
 
Hi Ray,

No, the code looks fine.

Does the report use a physical table, a view, an sp or a dataset to report.
I understand your point about it having been already filtered - that could
only happen, I think (since the report is closed and then again opened), if
the report is using a dataset/datatable as its source.

Try this: in the second pass, use the same pfieldname; if it works, then you
are correct and the data is filtered and has remained filtered. But that
would mean that the report is using a dataset/datatable. Once we know this,
we should be able to fix it.

Bernie
 
Dear Bernie,
Yes, if the same pfieldname is used. The same data will be filtered. How
to fix the problem?
Thanks,
Ray
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top