水晶报表关键代码

 private void crystalReportViewer1_Load(object sender, EventArgs e)
        {
            DataSet1TableAdapters.DataTable1TableAdapter Adt = new CrystalReportsApplication1.DataSet1TableAdapters.DataTable1TableAdapter();
            DataSet1.DataTable1DataTable dt = Adt.GetData();
            
            ReportDocument rptDoc = new ReportDocument();
            string dataDir = AppDomain.CurrentDomain.BaseDirectory;
            if (dataDir.EndsWith(@"\bin\Debug\")
            || dataDir.EndsWith(@"\bin\Release\"))
            {
                dataDir = System.IO.Directory.GetParent(dataDir).Parent.Parent.FullName ;
                AppDomain.CurrentDomain.SetData("DataDirectory", dataDir);
            }
            string reportFileName = dataDir + "\\CrystalReport1.rpt";
            rptDoc.Load(reportFileName);
            rptDoc.SetDataSource(dt.DefaultView);

            this.crystalReportViewer1.ReportSource = rptDoc;
            
        }


你可能感兴趣的:(水晶报表关键代码)