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..
<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..
<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..
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..
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.. :)