简体   繁体   中英

Crystal Report With Visual Studio 2017 WPF

How can I pass data to my crystal report viewer. From My MainWindow.cs. I am using Visual Studio 2017. My Crystal Report file name is CrystalReport1.rpt. My DataSet is Id and Description.

private void CrystalReport_Load(object sender, EventArgs e)
    {
        CrystalReport1 crystalReport = new CrystalReport1();

        string LotNumber = "78545755";

        DataSet1 dataSet1 = new DataSet1();
        DataTable reportDataTable = dataSet1.DataTable1;
        DataRow lotRow = reportDataTable.NewRow();
        lotRow["Id"] = 1;
        lotRow["Description"] = LotNumber;

        reportDataTable.Rows.Add(lotRow);



        dataSet1.BeginInit();

        crystalReport.SetDataSource(dataSet1);

        var cystalWindow = new CrystalReportsViewer();

        cystalWindow.ViewerCore.ReportSource = crystalReport;
    }

After the SetDataSource() step pass a parameter value like this:

myReportObject.SetParameterValue("MyParameterName", StringValueforParameter);

You obviously need to have a parameter as part of the design of the report. To create a parameter, right-click the 'Parameter Fields' node in Crystal's field explorer and select 'New...'.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM