1

我正在使用此代码在 VS2010 中打开水晶报告,axCRViewer1crystal report viewer control name,但在此行出现错误

axCRViewer1.ReportSource = rptDoc;

我如何解决它 ?

private void ViewR_Load(object sender, EventArgs e)
            {
                ReportDocument rptDoc = new ReportDocument();
                DataSetPatient ds = new DataSetPatient(); // .xsd file name
                DataTable dt1 = new DataTable();
                DataTable dt = DBHandling.GetPatient();//getting data using GetPatient()

                // Just set the name of data table
                dt.TableName = "Crystal Report P";
                ds.Tables[0].Merge(dt);

                // Your .rpt file path will be below
                rptDoc.Load("C:\\Users\\Monika\\Documents\\Visual Studio 2010\\Projects\\SonoRepo\\SonoRepo\\Reports\\CrystalReportP.rpt");

                //set dataset to the report viewer.
                rptDoc.SetDataSource(ds);
                axCRViewer1.ReportSource = rptDoc;//getting error at this line 
                // code to get data from the DB           
            }

获取患者()代码

public static DataTable GetPatient()
        {
            DataTable patientTable = new DataTable();
            using (OleDbConnection con = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=sonorepo.mdb"))
            {
                using (OleDbDataAdapter da = new OleDbDataAdapter(@"SELECT PatientID,PFirstName FROM Patient_Registration", con))
                    da.Fill(patientTable);
            }
            return patientTable;
        }
4

2 回答 2

0

此消息来自数据。检查DataTable dt 的结构是否与DataSetPatient 中第一个表的结构相同。

您也可以尝试替换 DataSetPatient 的代码。

DataSetPatient ds = new DataSetPatient(); // .xsd 文件名 .... ds.Tables[0].Merge(dt);

DataSet ds = new Dataset() ds.Tables.Add

于 2013-09-27T16:57:43.087 回答
0

这对我有用:

如果您在 64 位计算机上安装,请确保“构建”选项卡下的应用程序属性将“任何 CPU”作为平台目标,如果有选项,请取消选中“首选 32 位”复选框。Crystal 对 32/64 位程序集非常敏感,并且做出了一些非常违反直觉的假设,这些假设非常难以解决。

于 2016-03-11T17:19:51.123 回答