到时候直接赋值给
(1)数据库连接字符串
(2)查询语句
(3)有子报表参照工艺用水的,这个有两个子报表
public GridppReport Report = new GridppReport();
public GridppReport SonReport1 = new GridppReport();//子报表1
public GridppReport SonReport2 = new GridppReport();//子报表2
string ReportStr = "";
string ReportStr1 = "";//子报表1查询语句
string ReportStr2 = "";//子报表2查询语句
public void ReportMain()//主报表
{
Report.DetailGrid.Recordset.ConnectionString = "Provider=SQLNCLI10.1;" + mycon.connect.constr;//报表sql数据库字符串,NativeClient和oledb方式均可
//Report.DetailGrid.Recordset.ConnectionString = "Provider=SQLOLEDB.1;" + mycon.connect.constr;//报表sql数据库字符串
//声明是OLEDB方式,不然报错“未能用指定连接串 "连接字段"连接到数据源,连接串中的用户名和密码已隐藏”
Report.DetailGrid.Recordset.QuerySQL = ReportStr;//查询语句字符串
// Report.ParameterByName("custinfo").AsString = custinfo;//报表参数
}
private void ReportWithSonReport1()//子报表1
{
//用推模式为报表提供数据,将按条件生成的SQL设置到报表上
SonReport1.DetailGrid.Recordset.QuerySQL = ReportStr1;
}
private void ReportWithSonReport2()//子报表2
{
//用推模式为报表提供数据,将按条件生成的SQL设置到报表上
SonReport2.DetailGrid.Recordset.QuerySQL = ReportStr2;
}
private void button6_Click(object sender, EventArgs e)
{
try
{
axGRPrintViewer1.Stop();
if (comboBox9.Text == "成品报告")//成品报告:法定标准
{
ReportStr = "SELECT checkitem,legalstandard,legal from d_CheckData where suid='"+label27.Text+"'";
Report.LoadFromFile(Application.StartupPath + "\\reports\\成品检验报告书.grf");
Report.FetchRecord += new _IGridppReportEvents_FetchRecordEventHandler(ReportMain);//报表显示
}
else if (comboBox9.Text == "工艺用水")//工艺用水:内控标准
{
//1.查询语句及报表
ReportStr1 = "SELECT top 12 checkitem,legalstandard,legal from d_CheckData where suid='" + label27.Text + "'";
ReportStr2 = "SELECT top 12 checkitem,legalstandard,legal from d_CheckData where suid='" + label27.Text + "'";
Report.LoadFromFile(Application.StartupPath + "\\reports\\工艺用水检验报告书.grf");
//2.报表数据调用
Report.ControlByName("SubReport1").AsSubReport.Report = SonReport1;
SonReport1.DetailGrid.Recordset.ConnectionString = "Provider=SQLNCLI10.1;" + mycon.connect.constr;
Report.ControlByName("SubReport2").AsSubReport.Report = SonReport2;
SonReport2.DetailGrid.Recordset.ConnectionString = "Provider=SQLNCLI10.1;" + mycon.connect.constr;
Report.FetchRecord += new _IGridppReportEvents_FetchRecordEventHandler(ReportMain);
SonReport1.FetchRecord += new _IGridppReportEvents_FetchRecordEventHandler(ReportWithSonReport1);
SonReport2.FetchRecord += new _IGridppReportEvents_FetchRecordEventHandler(ReportWithSonReport2);
}
//Report.PrintPreview(true);
axGRPrintViewer1.Report = Report;
axGRPrintViewer1.Start();
}
catch (System.Exception ex)
{
}
}