string strConnection = ConfigurationManager.ConnectionStrings["ConnectionString2"].ToString();
DataSet myDs = new Report1();
using (SqlConnection conn = new SqlConnection(strConnection))
{
conn.Open();
string strSQL = "select * from XXXX";
using (SqlCommand cmd = new SqlCommand(strSQL, conn))
{
SqlDataReader myDr = cmd.ExecuteReader();
myDs.Tables["statlist"].Load(myDr);
myDr.Close();
myDr.Dispose();
}
}
//將ReportViewer1的DataSources集合清除
ReportViewer1.LocalReport.DataSources.Clear();
//匯出檔案名稱
ReportViewer1.LocalReport.DisplayName = "XXX彙總表";
//為查看器提供本地報表數據
ReportViewer1.LocalReport.ReportPath = Server.MapPath("Report1.rdlc");
ReportViewer1.LocalReport.DataSources.Add(
new Microsoft.Reporting.WebForms.ReportDataSource("Report1_statlist", myDs.Tables["statlist"]));
//參數
//ReportParameter param = new ReportParameter("Title", "嗚嗚");
//ReportParameter[] p ={ param };
ReportParameter[] p ={ new ReportParameter("UserName", "Lawrence"),
new ReportParameter("SDate", "2009/09/01"),
new ReportParameter("EDate", "2009/09/30")};
ReportViewer1.LocalReport.SetParameters(p);
留言
張貼留言
您好,我是 Lawrence,這裡是我的開發筆記的網誌,如果你對我的文章有任何疑問或者有錯誤的話,歡迎留言讓我知道。