rdlc

2020年以及过了几天,把之前随性而发的随笔,发布一下,也没太多整理。

https://stackoverflow.com/questions/4652347/dynamically-binding-of-dataset-to-rdlc-reports

 

 

protected void Page_Load(object sender, EventArgs e)
{
    DataSet ds = GetDataSet();
    ReportDataSource rds = new ReportDataSource("Orders", ds.Tables[0]);
    ReportViewer1.LocalReport.DataSources.Clear();
    ReportViewer1.LocalReport.DataSources.Add(rds);
    ReportViewer1.LocalReport.Refresh();

    GridView1.DataSource = ds;
    GridView1.DataBind();
}

private DataSet GetDataSet()
{
    var conString = ConfigurationManager.ConnectionStrings["dotnetConnectionString"];
    string strConnString = conString.ConnectionString;

    SqlConnection conn = new SqlConnection(strConnString);
    conn.Open();
    string sql = "Select * FROM Orders";

    SqlDataAdapter ad = new SqlDataAdapter(sql, conn);
    DataSet ds = new DataSet();        
    ad.Fill(ds);

    return ds;
}

 https://blogs.msdn.microsoft.com/sqlforum/2011/04/27/walkthrough-assign-dataset-dynamically-created-in-code-to-your-local-report-with-reportviewer/

private void Form1_Load(object sender, EventArgs e)

        {

            SqlConnection con = new SqlConnection("Data Source=.; Initial Catalog=AdventureWorksDW2008R2; Integrated Security=True");

            SqlDataAdapter da = new SqlDataAdapter("SELECT ProductCategoryKey, EnglishProductCategoryName FROM DimProductCategory", con);

            DataSet ds = new DataSet();           

            da.Fill(ds);

            ds.Tables[0].TableName = "DataTable1";

           

            this.DataTable1BindingSource.DataSource = ds;

            this.reportViewer1.RefreshReport();

        }

 

这个不错 

https://www.aspsnippets.com/Articles/RDLC-Report-in-Windows-Forms-WinForms-Application-using-C-and-VBNet.aspx

posted @ 2020-01-04 09:14  landv  阅读(347)  评论(0编辑  收藏  举报