Reputation: 249
I need to get the SQL query from the rdlc file to run on my database and add a datasource for Microsoft.Reporting.WebForms.LocalReport with results of the query.
I used the code from here to work with the report data. But
Microsoft.Reporting.WinForms.LocalReport
doesn't have dataset getters.
rdlc file contains DatasetInfo for DataSet in DataSets section
<DataSets>
<DataSet Name="DataSet1">
<Query>
<DataSourceName>Dataset1</DataSourceName>
<CommandText>/* Local Query */</CommandText>
</Query>
<Fields> Some Fields description here
</Fields>
<rd:DataSetInfo>
<rd:DataSetName>Dataset1</rd:DataSetName>
<rd:SchemaPath>c:\Dataset1.xsd</rd:SchemaPath>
<rd:TableName>bAPCD</rd:TableName>
<rd:TableAdapterFillMethod>Fill</rd:TableAdapterFillMethod>
<rd:TableAdapterGetDataMethod>GetData</rd:TableAdapterGetDataMethod>
<rd:TableAdapterName>bAPCDTableAdapter</rd:TableAdapterName>
</rd:DataSetInfo>
</DataSet>
</DataSets>
The .xsd file contains the SQL query I need
<DbSource ConnectionRef="DBConnection (Web.config)" DbObjectName="dbconnect.dbo.bAPCD" DbObjectType="Table" FillMethodModifier="Public" FillMethodName="Fill" GenerateMethods="Both" GenerateShortCommands="true" GeneratorGetMethodName="GetData" GeneratorSourceName="Fill" GetMethodModifier="Public" GetMethodName="GetData" QueryType="Rowset" ScalarCallRetval="System.Object, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" UseOptimisticConcurrency="false" UserGetMethodName="GetData" UserSourceName="Fill">
<SelectCommand>
<DbCommand CommandType="Text" ModifiedByUser="false">
<CommandText>SELECT * FROM dbo.ttable</CommandText>
<Parameters />
</DbCommand>
</SelectCommand>
</DbSource>
How can I get the SQL query from this file in the code ?
Upvotes: 2
Views: 1860
Reputation: 148
If you want to get the select sql :
var dataset = new MyDataTable(); //RPTDatasets.MySet.MyDataTable
var adapter = new bAPCDTableAdapter(); //RPTDatasets.MySet.MySet.Designer
string commandText = adapter.Adapter.SelectCommand.CommandText.ToString();
//or change command
adapter.Adapter.SelectCommand.CommandText = "SELECT * FROM FOO";
adapter.Fill(dataset.MyTable);
Upvotes: 2