sthamilton
asked on
Populate Report with Data Reader
What is the proper way to populate a crystal report using a SqlDataReader? It seems simple enough to do so by simply using rpt.SetDataSource(rdr), but this doesn't appear to work for me. When executing the following code on my development machine it works perfectly. However when executing it on a production machine it gives the following error that says "login falied". Can anyone see what I am doing wrong?
CrystalDecisions.CrystalRe ports.Engi ne.ReportD ocument rpt = new CrystalDecisions.CrystalRe ports.Engi ne.ReportD ocument();
rpt.Load(rptfile);
SqlConnection conReport = new SqlConnection(SOLIMPMODULE S.ImportSQ L.strConn) ;
SqlCommand cmdReport = new SqlCommand(strReportSrc, conReport);
cmdReport.CommandType = CommandType.StoredProcedur e;
conReport.Open();
SqlDataReader rdr = cmdReport.ExecuteReader();
rpt.SetDataSource(rdr);
foreach(CrystalDecisions.C rystalRepo rts.Engine .Table tbl in rpt.Database.Tables)
{
tbl.SetDataSource(rdr);
}
rpt.Refresh();
CrystalDecisions.Shared.Di skFileDest inationOpt ions dopt = new CrystalDecisions.Shared.Di skFileDest inationOpt ions();
dopt.DiskFileName = strPDFName;
rpt.ExportOptions.ExportDe stinationT ype = CrystalDecisions.Shared.Ex portDestin ationType. DiskFile;
rpt.ExportOptions.ExportFo rmatType = CrystalDecisions.Shared.Ex portFormat Type.Porta bleDocForm at;
rpt.ExportOptions.Destinat ionOptions = dopt;
rpt.Export();
CrystalDecisions.CrystalRe
rpt.Load(rptfile);
SqlConnection conReport = new SqlConnection(SOLIMPMODULE
SqlCommand cmdReport = new SqlCommand(strReportSrc, conReport);
cmdReport.CommandType = CommandType.StoredProcedur
conReport.Open();
SqlDataReader rdr = cmdReport.ExecuteReader();
rpt.SetDataSource(rdr);
foreach(CrystalDecisions.C
{
tbl.SetDataSource(rdr);
}
rpt.Refresh();
CrystalDecisions.Shared.Di
dopt.DiskFileName = strPDFName;
rpt.ExportOptions.ExportDe
rpt.ExportOptions.ExportFo
rpt.ExportOptions.Destinat
rpt.Export();
ASKER
The code is C# using the CrystalDecisions.CrystalRe ports.Engi ne objects and the embedded version of crystal reports. I think that I figured out that it is a bad idea to use the datareader object to bind to the report. Since in the report designer I can't base the report off of the datareader object it seems to be unable to bind the tables. I have managed to work around it by converting the data reader to a dataset and generating an XML file which I can then bind the report to. Thanks for the help though!
Glad to hear you solved it. I don't know as much about C# as I should. Maybe I will find time soon to expand my horizons.
mlmcc
mlmcc
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Looks like C++ so this may be useful
http://support.businessobjects.com/communityCS/FilesAndUpdates/rdccpp85.exe.asp
Is the SQLDataReader anything like an ADO recordset?
If so this may shed some light
http://support.businessobjects.com/communityCS/FilesAndUpdates/ADO_ConnectionMethods.zip.asp
mlmcc