protected void Page_Load(object sender, EventArgs e)
{
// ConfigureCrystalReports();
string conn = ConfigurationManager.AppSettings["ConnectionString"].ToString();
string query = "select * from billwarehousebook";
SetDataSource(conn, query);
}
private void ConfigureCrystalReports()
{
ReportDocument rd = new ReportDocument();
string strFilePath = this.Server.MapPath("CrystalReport.rpt");
rd.Load(strFilePath);
// DataTable dt = DataSetConfiguration.CustomerDataSet;
// BaseAccess obase = new BaseAccess();
DataSet dataSet=new DataSet();
string conn = ConfigurationManager.AppSettings["ConnectionString"].ToString();
string query = "select * from billwarehousebook";
SqlConnection sqlConn = new SqlConnection(conn);
SqlDataAdapter SqlAdapter = new SqlDataAdapter();
SqlAdapter.SelectCommand = new SqlCommand(query, sqlConn);
SqlAdapter.Fill(dataSet);
// DataSet ds = obase.GetDataSet("select * from billwarehousebook");
rd.SetDataSource(dataSet.Tables[0]);
CrystalReportViewer1.ReportSource = rd;
CrystalReportViewer1.RefreshReport();
}
private void SetDataSource(string conn, string query)
{
// 使用 ADO.NET 对象模型设置连接
// 信息。
ReportDocument rd = new ReportDocument();
string strFilePath = this.Server.MapPath("CrystalReport.rpt");
rd.Load(strFilePath);
DataSet dataSet = new DataSet();
SqlConnection sqlConn = new SqlConnection(conn);
SqlDataAdapter SqlAdapter = new SqlDataAdapter();
SqlAdapter.SelectCommand = new SqlCommand(query, sqlConn);
// 连接到数据源、获取数据和断开与
// 数据库的连接。
SqlAdapter.Fill(dataSet, "Customer");
// 将已填充的数据集传送到报表中。
rd.SetDataSource(dataSet);
CrystalReportViewer1.ReportSource = rd;
CrystalReportViewer1.RefreshReport();
}