using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Data.SqlClient;
using CrystalDecisions.Shared;
using CrystalDecisions.CrystalReports;
using CrystalDecisions.Windows.Forms;
using CrystalDecisions.CrystalReports.Engine;
public report1()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();
string strSel="select * from department";
//MyCr为自己设计的crystalReport报表模版
CR1 MyCr = new CR1();
//DataSet2为已填充的数据集
DataSet2 ds = new DataSet2();
//frmMain.str为数据库连接字符串
BindReport(crystalReportViewer1,ds,frmMain.str,strSel,"department",MyCr);
}
//动态绑定报表
public static void BindReport(CrystalReportViewer crv,DataSet ds,string strConn,string strSel,string tabName,ReportDocument MyCr)
{
SqlConnection MyConn = new SqlConnection(strConn);
MyConn.Open();
SqlDataAdapter MyAdapter = new SqlDataAdapter(strSel,MyConn);
MyAdapter.Fill(ds,tabName);
MyCr.SetDataSource(ds.Tables[tabName]);
crv.ReportSource =MyCr;
MyConn.Close();
}