Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1683
  • Last Modified:

Help populating a Report Viewer

I am trying to populate a Report Viewer programatically but receive this error.  Please help me understand this:

"The DataSourceID of the ReportDataSource 'MyDS' of the ReportViewer 'ReportViewer1' must be the ID of a control of type IDataSource. A control with ID 'MyTable' could not be found."  

This is my code:
------------------

    protected void Button1_Click(object sender, EventArgs e)
    {
        MultiView1.ActiveViewIndex = 1;

        ObjectDataSource objDS = new ObjectDataSource("MyDataSource2", "GetData");
        objDS.ID = "MyTable";
        ReportViewer1.LocalReport.DataSources.Add(new ReportDataSource("MyDS", objDS.ID));

        // Set the path of the rdlc document
        string reportPath = "App_Code/PendingOpenShippedOrders.rdlc";

        //ReportViewer1.LocalReport.DataSources.Add(new ReportDataSource("Orders", ordersTable));
        //ReportViewer1.LocalReport.DataSources.Add(new ReportDataSource("OrdersDataSet", ds.Tables[0]));
        ReportViewer1.LocalReport.ReportPath = reportPath;

    }
    public class MyDataSource2
    {
        public DataTable GetData()
        {

            ReportDataLayerTableAdapters.WebShop_Report_OrdersPendingOpenShippedTableAdapter ordersAdapter = new ReportDataLayerTableAdapters.WebShop_Report_OrdersPendingOpenShippedTableAdapter();
            ReportDataLayer.WebShop_Report_OrdersPendingOpenShippedDataTable ordersTable = new ReportDataLayer.WebShop_Report_OrdersPendingOpenShippedDataTable();

            //DateTime beginDate = Convert.ToDateTime(txtBeginDate.Text);
            //DateTime endDate = Convert.ToDateTime(txtEndDate.Text);
            DateTime beginDate = Convert.ToDateTime("05/01/2006");
            DateTime endDate = Convert.ToDateTime("05/31/2006");

            ordersTable = ordersAdapter.GetData(beginDate, endDate);

            DataSet ds = new DataSet();
            ds.Tables.Add(ordersTable);
            ds.Tables[0].TableName = "MyTable";
            ds.DataSetName = "MyDS";

            return ds.Tables[0];
        }
    }
0
JeffDrummond
Asked:
JeffDrummond
1 Solution
 
JeffDrummondAuthor Commented:
Well, I worked it out, quite simply it seems.

I have a Multiview.  View1 has two date parameters fields.

View2 has the ReportViewer.  I created this Orders class and put it

in the App_Code folder:

public class Orders

{

public Orders()

{

//

// TODO: Add constructor logic here

//


}

public DataTable GetOrders(DateTime begindate, DateTime enddate)

{

ReportDataLayerTableAdapters.WebShop_Report_OrdersPendingOpenShippedTableAdapter ordersAdapter = new ReportDataLayerTableAdapters.WebShop_Report_OrdersPendingOpenShippedTableAdapter();

ReportDataLayer.WebShop_Report_OrdersPendingOpenShippedDataTable ordersTable = new ReportDataLayer.WebShop_Report_OrdersPendingOpenShippedDataTable();


ordersTable = ordersAdapter.GetData(begindate, enddate);

return ordersTable;

}

}

In ObjectDataSource1 properties, I entered:

SelectMethod:  GetOrders

TypeName:  Orders

SelectParameters:  the two date fields

When it ran, the parameters are passed to the get method and the datasource returned to the report.  Perfect.
0
 
NetminderCommented:
Closed, 500 points refunded.
Netminder
Site Admin
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now