can't figure it out.
Basically, I want to control the selected data in the C# code as
opposed to Crystal Reports (since SQL is truly for querying, and
Crystal Reports is more a reporting tool). The only way I've found to
do this so far is to execute my select in C#, then store to an XML
file, and then have the Crystal Report read the XSD and XML files.
However, I have a HUGE problem. I can only do this once (which works,
by the way), but then, something is locking the file, and I can no
longer access it. I can't delete it, and I can't write to it in my
code again. I close the document, but I'm not sure what else to do.
Even if I close out all applications (Visual Studio, Crystal Reports
XI, etc.), the file remains locked. The only way around it that I've
found is logging out and logging back in. Obviously, this is
unacceptable.
Ok, so here is my code:
Expand|Select|Wrap|Line Numbers
- CrystalDecisions.CrystalReports.Engine.ReportDocument doc = new
- CrystalDecisions.CrystalReports.Engine.ReportDocument() ;
- doc.Load( @"C:\Development\CrystalReports\App1\CustomerProfile.rpt" ) ;
- doc.SetDataSource( ds ) ;
- string xsdFile =
- @"C:\Development\CrystalReports\App1\CustomerProfile.xsd" ;
- string xmlFile =
- @"C:\Development\CrystalReports\App1\CustomerProfile.xml" ;
- ds.WriteXmlSchema( xsdFile ) ;
- ds.WriteXml( xmlFile ) ;
- crystalReportViewer1.ReportSource = doc ;
- crystalReportViewer1.RefreshReport() ;
- crystalReportViewer1.Visible = true ;
- doc.Close() ;
The XSD file can be written and rewritten, and it never becomes locked.
But the XML file does after running just once.
Any help is GREATLY APPRECIATED!!!