WebForm Report 一个Demo Code

//declare conn string
            string connstr =
                "Data Source=168.10.11.3;Initial Catalog=RealWorld;Persist Security Info=True;User ID=sa;Password=111111";

            //declare conn ,command
            SqlConnection conn = new SqlConnection(connstr);
            SqlCommand cmd = new SqlCommand();
            DataSet ds = new dsReport();
            try
            {
                conn.Open();
                cmd.Connection =conn;
                cmd.CommandText = "SELECT * FROM AgedAR";
                SqlDataReader dr = cmd.ExecuteReader();
                ds.Tables[0].Load(dr);
                //=============================================
                //与winform不同
           //   ReportViewer1.LocalReport.ReportEmbeddedResource = "Report1.rdlc";
                ReportViewer1.LocalReport.ReportPath = "Report1.rdlc";

                //Report DataSource

                ReportDataSource rds = new ReportDataSource();
                rds.Name = "dsReport_dtAgedAR";
                rds.Value = ds.Tables[0];
                ReportViewer1.LocalReport.DataSources.Add(rds);

            }
            catch (Exception ex)
            {
                Response.Write(ex.Message);
            }
            finally
            {
                conn.Close();
            }

原文地址:https://www.cnblogs.com/kingwangzhen/p/1497222.html