cancel
Showing results for 
Search instead for 
Did you mean: 

C# VS2008 Change Report And Data Set

Former Member
0 Kudos

Hi,

Now that I am correctly populating my dataset and report with the code below I have another need.

DataSet ds = new DataSet();

//ReportDocument rd = new ReportDocument();

//rd.Load("Payments.rpt");

HollandMHP.HollandMHPDataSet.LedgerDataTable ldt = new HollandMHP.HollandMHPDataSet.LedgerDataTable();

HollandMHP.HollandMHPDataSet.CustDataTable cdt = new HollandMHP.HollandMHPDataSet.CustDataTable();

HollandMHP.HollandMHPDataSetTableAdapters.CustTableAdapter custdat = new HollandMHP.HollandMHPDataSetTableAdapters.CustTableAdapter();

HollandMHP.HollandMHPDataSetTableAdapters.LedgerTableAdapter ledgdat = new HollandMHP.HollandMHPDataSetTableAdapters.LedgerTableAdapter();

custdat.Fill(cdt);

ledgdat.Fill(ldt);

ds.Tables.Add(cdt);

ds.Tables.Add(ldt);

//ds.Tables[0].Select("NextDue < '" + DateTime.Now.Date.ToString() + "'");

Payments1.SetDataSource(ds);

//crystalReportViewer1.ReportSource = rd;

Notice the comented code. This is an attempt to change the report in code so that I do not need to create a new report form for each of my reports. My goal is to load the daaset and report based on the specific report selected. Can someone help in this attempt?

Accepted Solutions (1)

Accepted Solutions (1)

former_member183750
Active Contributor
0 Kudos

Not sure I understand:

My goal is to load the daaset and report based on the specific report selected.

But, use a case statement? If statement?

Ludek

Follow us on Twitter http://twitter.com/SAPCRNetSup

Got Enhancement ideas? Try the [SAP Idea Place|https://ideas.sap.com/community/products_and_solutions/crystalreports]

Former Member
0 Kudos

I guess that detail is a bit important. I have no problems using IF (since there are only two reports in this program) but I am having trouble with the correct code to load the dataset and report. As the report is designed it works with the Payments1 report loaded and saved in the screen. I want to chahge the dataset (which should be possible by uncommenting the SELECT code) and the report. The report load was attempted and failed. I believe that is the biggest issue that I am having.

former_member183750
Active Contributor
0 Kudos

Something like this?




Dim crRpt as new ReportDocument
.
'Some condition
.
crReportDocument.Load("C:\MyReport_A.rpt")
.
.
crReportDocument.SetDataSource(dataSet_A)
.
.
crReportDocument.Close
crReportDocument.Dispose
.
'Some condition
.
crReportDocument.Load("C:\MyReport_B.rpt")
.
.
crReportDocument.SetDataSource(dataSet_B)
.
.
crReportDocument.Close
crReportDocument.Dispose


- Ludek

Former Member
0 Kudos

Thanks. My final code is

DataSet ds = new DataSet();

DataRow[] fds;

ReportDocument rd = new ReportDocument();

if (Form1.selrpt == "Payments")

{

rd.Load("c:
Payments.rpt");

HollandMHP.HollandMHPDataSet.LedgerDataTable ldt = new HollandMHP.HollandMHPDataSet.LedgerDataTable();

HollandMHP.HollandMHPDataSet.CustDataTable cdt = new HollandMHP.HollandMHPDataSet.CustDataTable();

HollandMHP.HollandMHPDataSetTableAdapters.CustTableAdapter custdat = new HollandMHP.HollandMHPDataSetTableAdapters.CustTableAdapter();

HollandMHP.HollandMHPDataSetTableAdapters.LedgerTableAdapter ledgdat = new HollandMHP.HollandMHPDataSetTableAdapters.LedgerTableAdapter();

custdat.Fill(cdt);

ledgdat.Fill(ldt);

ds.Tables.Add(cdt);

ds.Tables.Add(ldt);

rd.SetDataSource(ds);

}

else

{

rd.Load("c:
LatePay.rpt");

HollandMHP.HollandMHPDataSet.CustDataTable cdt = new HollandMHP.HollandMHPDataSet.CustDataTable();

HollandMHP.HollandMHPDataSetTableAdapters.CustTableAdapter custdat = new HollandMHP.HollandMHPDataSetTableAdapters.CustTableAdapter();

custdat.Fill(cdt);

ds.Tables.Add(cdt);

fds = ds.Tables[0].Select("NextDue < '" + DateTime.Now.Date + "'");

rd.SetDataSource(fds);

}

crystalReportViewer1.ReportSource = rd;

Answers (0)