C#, Crystal Report and Stored Procedure

  • Thread starter Thread starter Lalit Parashar
  • Start date Start date
L

Lalit Parashar

Hi,
I am clueless on how to integrate stored procedure in Crystal Reports using
C#. Any pointers please?

Thanks
Lalit
 
Not sure about the Stored Proc, but you can use the proc to populate a
DataSet then use dataset.WriteXML("SomeFile.xml"). Do this once just to
generate the file. Then, you can use that first file to use the CR Report
designer. Afterward, just recreate the XML file and then call the report.
 
Just retrieve the DataSet using the stored proc and then pass that DataSet
to your document's DataSource property. Something like this:

....
ds = _currencyProcessor.GetCashLedgerReportData(CurrencySortOrder.BySlot,

dtpCurRptOptFromDate.Value,

cbCurRptOptSessionOnly.Checked).DataSet;

oRD = new Currency_CashLedger();

oRD.SetParameterValue("SessionOnly", cbCurRptOptSessionOnly.Checked);

oRD.SetParameterValue("RoomNumber", _currConfig.LocationID.ToString());

oRD.SetParameterValue("Name", _Name);

oRD.SetParameterValue("TransactionDate", dtpCurRptOptFromDate.Value);

oRD.SetDataSource(ds.Tables[0]);

crystalReportViewer2.ReportSource = oRD;

....

Scott
 
Hi William,

Hvae you tested this approach on a web escenario? I havent been able to use
this push model from the web.

Cheers,
 
No, I sure haven't. I was thinking it should work on the web as long as you
can write over the old XML file, but that could present some security
issues. Let me play around with it and see what happens b/c that's a very
good question.

Cheers,

Bill
 
Hi,

Cause I haven't been able to do so, I always get the "Logon failed" error
:(

cheers,
 
Why not design the report directly against the stored proc and then pass the
dataset directly to the report document at runtime? IOW, why not "push" the
data the report? I'm probably missing something obvious, but we have
several reports working this way with traditional and web apps.

Scott
 
This is what I did, but it gives me "Invalid report file path"
exception.Message.

myReport = new ReportDocument();

ds = MakeDataSet();

ds.WriteXml(@"C:\FileName.xml");

myReport.SetDataSource(ds);

cfsReportViewer.ReportSource = myReport;



Thanks,

Lalit



Scott Carter said:
Just retrieve the DataSet using the stored proc and then pass that DataSet
to your document's DataSource property. Something like this:

...
ds = _currencyProcessor.GetCashLedgerReportData(CurrencySortOrder.BySlot,

dtpCurRptOptFromDate.Value,

cbCurRptOptSessionOnly.Checked).DataSet;

oRD = new Currency_CashLedger();

oRD.SetParameterValue("SessionOnly", cbCurRptOptSessionOnly.Checked);

oRD.SetParameterValue("RoomNumber", _currConfig.LocationID.ToString());

oRD.SetParameterValue("Name", _Name);

oRD.SetParameterValue("TransactionDate", dtpCurRptOptFromDate.Value);

oRD.SetDataSource(ds.Tables[0]);

crystalReportViewer2.ReportSource = oRD;

...

Scott

I am clueless on how to integrate stored procedure in Crystal Reports using
C#. Any pointers please?
 
myReport = new ReportDocument();

If this isn't a typed report, you need to Load your report into your
document:

myReport.Load(@"YourReportFile.rpt");
ds = MakeDataSet();
ds.WriteXml(@"C:\FileName.xml");

There's no need to write your dataset to disk.
myReport.SetDataSource(ds);

cfsReportViewer.ReportSource = myReport;

Everything else looks good -- good luck.

Scott
 
Back
Top