none
reportviewer table and datatable RRS feed

  • Question

  • I have two forms, main and report form. On my report form i've put reportviewer, and i generated rdlc local report.

    I have one table, and public property in this namespace in form report named "test" as datatable. How i can bind this datatable property to my table on my reportviewer?

     

    Please help. I'm working on visual basic win forms.


    Ivan Markic
    • Edited by Ivan Markic Saturday, July 24, 2010 5:43 PM Lapsus lingua.
    Saturday, July 24, 2010 5:15 PM

Answers

  • Ivan,

    You can bind a datatable to your localreport as following:

    Dim dt As New DataTable("Orders")
    dt.Columns.Add(New DataColumn("OrderID", GetType(System.Int32)))
    dt.Columns.Add(New DataColumn("OrderDate", GetType(System.DateTime)))
    dt.Columns.Add(New DataColumn("OrderStatus", GetType(System.String)))
    dt.Rows.Add(New Object() {1, DateTime.Now, "Initiating"})
    dt.Rows.Add(New Object() {2, DateTime.Now.AddMonths(-1), "Executing"})
    dt.Rows.Add(New Object() {3, DateTime.Now.AddMonths(2), "Planning"})
    dt.Rows.Add(New Object() {4, DateTime.Now.AddYears(-1), "Completed"})
    dt.AcceptChanges()

    Dim strName As [String] = Me.reportViewer1.LocalReport.DataSources(0).Name
    Me.reportViewer1.LocalReport.DataSources(0) = New Microsoft.Reporting.WinForms.ReportDataSource(strName, dt)Me.reportViewer1.RefreshReport()

    But please make sure that your datatable's structure (column information) is same as the dataset defined in your local report. For this example, there is a dataset Orders in my test report with the table named Orders with the same columns OrderID, OrderDate and OrderStatus as defined in the datatable. Otherwise the unmatched columns will display nothing in your report.


    Please remember to mark the replies as answers if they help and unmark them if they provide no help
    • Marked as answer by Ivan Markic Monday, July 26, 2010 12:24 PM
    Monday, July 26, 2010 5:35 AM
    Moderator

All replies

  • Ivan,

    You can bind a datatable to your localreport as following:

    Dim dt As New DataTable("Orders")
    dt.Columns.Add(New DataColumn("OrderID", GetType(System.Int32)))
    dt.Columns.Add(New DataColumn("OrderDate", GetType(System.DateTime)))
    dt.Columns.Add(New DataColumn("OrderStatus", GetType(System.String)))
    dt.Rows.Add(New Object() {1, DateTime.Now, "Initiating"})
    dt.Rows.Add(New Object() {2, DateTime.Now.AddMonths(-1), "Executing"})
    dt.Rows.Add(New Object() {3, DateTime.Now.AddMonths(2), "Planning"})
    dt.Rows.Add(New Object() {4, DateTime.Now.AddYears(-1), "Completed"})
    dt.AcceptChanges()

    Dim strName As [String] = Me.reportViewer1.LocalReport.DataSources(0).Name
    Me.reportViewer1.LocalReport.DataSources(0) = New Microsoft.Reporting.WinForms.ReportDataSource(strName, dt)Me.reportViewer1.RefreshReport()

    But please make sure that your datatable's structure (column information) is same as the dataset defined in your local report. For this example, there is a dataset Orders in my test report with the table named Orders with the same columns OrderID, OrderDate and OrderStatus as defined in the datatable. Otherwise the unmatched columns will display nothing in your report.


    Please remember to mark the replies as answers if they help and unmark them if they provide no help
    • Marked as answer by Ivan Markic Monday, July 26, 2010 12:24 PM
    Monday, July 26, 2010 5:35 AM
    Moderator
  • HMM, EVERTHING IS OK, BUT I'VE ADDED NEW ITEM DATASET, NEW BINDING SOURCE AND AS DATAMEMBER I CHOSE THIS TABLE. IT IS OK. tHANKS.
    Ivan Markic
    Monday, July 26, 2010 12:25 PM