日期:2014-05-18 浏览次数:20478 次
private void ShowReport()
        {
            using (SqlConnection cn = new SqlConnection("server=........."))
            {
                SqlCommand cmd = cn.CreateCommand();
                cmd.CommandText = "存储过程名";
                cmd.CommandType = CommandType.StoredProcedure;
                SqlParameter para = new SqlParameter("@FDate", "2008-03-01");
                cmd.Parameters.Add(para);
                SqlDataAdapter da = new SqlDataAdapter(cmd);
                DataTable dt = new DataTable();
                da.Fill(dt);
                ReportDocument rDoc = new ReportDocument();
                string path = Server.MapPath("Reports") + "\\报表名" ;
                try
                {
                    
                    rDoc.Load(path);
                    rDoc.SetDataSource(dt);
                    dt.Dispose();
                    crViewer.ReportSource = rDoc;
                }
                catch (Exception ex)
                {
                    MessageBox.Show("加载报表错误" + ex.Message, "系统提示", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }