locked
Programmatically adding datasources to report viewer? RRS feed

  • Question

  • User1601301233 posted

    I've searched around and based on what I have found, this should work.

    when I run the aspx page, it just loads infinitely. This is how I am trying to do it:

                SqlDataSource ProjectClosedDS = new SqlDataSource();
                ProjectClosedDS.ID = "ProjectClosedDS";
                this.Page.Controls.Add(ProjectClosedDS);
                ProjectClosedDS.ConnectionString = ConfigurationManager.ConnectionStrings["FPNConnectionString"].ConnectionString;
                ProjectClosedDS.SelectCommand = "[ProjectNew].[rpt_ProjectsClosed]";
                ProjectClosedDS.SelectCommandType = SqlDataSourceCommandType.StoredProcedure;
    
                ReportViewer.LocalReport.DataSources.Clear();
                ReportDataSource DS_ProjectsClosed = new ReportDataSource("DS_ProjectsClosed", ProjectClosedDS);
                ReportViewer.LocalReport.DataSources.Add(DS_ProjectsClosed);
                ReportViewer.LocalReport.Refresh();

    When I open the .rdlc file in a text editor, this is what it shows for the dataset:

        <DataSet Name="DS_ProjectsClosed">
          <Query>
            <DataSourceName>DS_ProjectsClosed</DataSourceName>
            <CommandText>/* Local Query */</CommandText>
          </Query>
          <Fields>
            <Field Name="Month">
              <DataField>Month</DataField>
              <rd:TypeName>System.String</rd:TypeName>
            </Field>
            <Field Name="Year">
              <DataField>Year</DataField>
              <rd:TypeName>System.String</rd:TypeName>
            </Field>
            <Field Name="ActualImpDt">
              <DataField>ActualImpDt</DataField>
              <rd:TypeName>System.Int32</rd:TypeName>
            </Field>
          </Fields>
          <rd:DataSetInfo>
            <rd:DataSetName>DS_ProjectsClosed</rd:DataSetName>
            <rd:SchemaPath>C:\Users\tcolbert\Documents\FPN\FPN_SharePoint\FPN_SharePoint\DS_ProjectsClosed.xsd</rd:SchemaPath>
            <rd:TableName>rpt_ProjectsClosed</rd:TableName>
            <rd:TableAdapterFillMethod>Fill</rd:TableAdapterFillMethod>
            <rd:TableAdapterGetDataMethod>GetData</rd:TableAdapterGetDataMethod>
            <rd:TableAdapterName>rpt_ProjectsClosedTableAdapter</rd:TableAdapterName>
          </rd:DataSetInfo>
        </DataSet>

    I must be missing something but I cant figure out what. Does anybody notice any problems or have any ideas on how to do this?

    Thursday, September 29, 2016 6:44 PM

Answers