Click here to Skip to main content
15,891,136 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hi All,

Am trying to display a dynamic DataTable using a ReportViewer control. Need some help...

This is a snippet of my Report.rdlc file..

XML
<DataSources>
   <DataSource Name="InfoDBDataSet">
     <ConnectionProperties>
       <DataProvider>System.Data.DataSet</DataProvider>
       <ConnectString>/* Local Connection */</ConnectString>
     </ConnectionProperties>
     <rd:DataSourceID>3dc0cff0-2297-4a9f-bd01-e40733c9cea3</rd:DataSourceID>
   </DataSource>
 </DataSources>
 <DataSets>
   <DataSet Name="MyDataSet">
     <Query>
       <DataSourceName>InfoDBDataSet</DataSourceName>
       <CommandText>/* Local Query */</CommandText>
     </Query>
     <rd:DataSetInfo>
       <rd:DataSetName>MyDataSet</rd:DataSetName>
       <rd:SchemaPath>C:\Users\ng84527\Documents\Visual Studio 2010\WebSites\SampleReportsWeb\App_Code\MyDataSet.xsd</rd:SchemaPath>
       <rd:TableName>ReportTable</rd:TableName>
     </rd:DataSetInfo>
   </DataSet>
 </DataSets>
 <Body>
   <Height>0.23622in</Height>
   <Style />
 </Body>



This is the ObjectDataSource..

XML
<asp:ObjectDataSource ID="ObjectDataSource1" runat="server"
        SelectMethod="GetDataTable" TypeName="DataAccessLayer.DataLayer">
        <SelectParameters>
            <asp:Parameter Name="searchQuery" Size="100" Type="String" />
        </SelectParameters>
    </asp:ObjectDataSource>


The method GetDataTable(string searchQuery) is in my DAL. I generate the searchQuery dynamically, using another method, GetSearchQuery(). Since this is done at run time, I add the parameter value as follows..

C#
ObjectDataSource1.SelectParameters.Clear();

Parameter p = new Parameter();
p.Name = "searchQuery";
p.Size = 100;
p.ConvertEmptyStringToNull = false;
p.DbType = DbType.Object;
p.Type = TypeCode.String;
p.Direction = ParameterDirection.Input;
p.DefaultValue = query;

ObjectDataSource1.SelectParameters.Add(p);



Then I write..

C#
this.ReportViewer1.DataBind();
this.ReportViewer1.LocalReport.Refresh();



But report is not able to display the DataTable. I tried using the ObjectDataSource with a GridView and it worked properly. Any suggestions.?

P.S This is my first question in CodeProject. I guess am not in full compliance with the Rules. Am sorry about that. Would improve as I keep coming back for your help. Cheersss.. :)
Posted
Comments
Malli_S 26-Jul-12 9:18am    
Did you set the report viewer's AutoDataBind to "true"?
And did you bind the data source to report viewer properly ? (Because I didn't see that in above code.)
RookieCoder_NG 27-Jul-12 1:59am    
First of all, Thank you for the response.

Am sorry. Am not able to find the AutoDataBind property for the ReportViewer or even under ReportViewer1.LocalReport.. There is only the DataBind() method.

I was trying not to put my entire project here (as the rules said).. :)

<rsweb:ReportViewer ID="ReportViewer1" runat="server" Height="249px"

Font-Names="Verdana" Font-Size="8pt" InteractiveDeviceInfos="(Collection)"

WaitMessageFont-Names="Verdana" WaitMessageFont-Size="14pt"

AsyncRendering="False">

<LocalReport ReportPath="Reports\Report.rdlc">

<DataSources>

<rsweb:ReportDataSource DataSourceId="ObjectDataSource1" Name="MyDataSet" />

</DataSources> </LocalReport>

</rsweb:ReportViewer>


The MyDataSet.xsd is initially empty. I write the schema in my DAL after retrieving the DataTable as follows..

resultDataSet.WriteXmlSchema(@"C:\Users\ng84527\Documents\Visual Studio 2010\WebSites\SampleReportsWeb\App_Code\MyDataSet.xsd");

And I forget to mention one more thing.. When I run the app for debugging, initially report shows..

"An error occurred during local report processing.

An error has occurred during report processing. MyDataSet"

Once I select the fieds for the query and hit the button..under which I add the ObjectDataSource parameter and refresh the ReportViewer..an empty report is displayed.

Am guessing there is some problem with the Report.rdlc file. There is no ReportItems element in it.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900