Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ReportViewer reporting from a DataTable

I was wondering if there was a way to design a report for ReportViewer from a SQL query. So from the SQL query I'd get all the data I need to make a report and then design the report in the designer?

I am very new to ReportViewer and I am quite confused. Right now I can see I can populate the DataSet from a wizard, however as far as I can see there is no way to throw a SQL query in there and then design from that.

Is what I want even possible or will I have to use a DataGridView? I really want to use the reportviewer because of the printing/exporting support. Is there any literature available on the subject?

like image 932
David Božjak Avatar asked May 29 '26 03:05

David Božjak


1 Answers

If you are using the LocalReport Class (reportViewer.LocalReport) and not the SSRS (everything is clickable there), a sample is in the link.

ReportDataSource Class has constructor that accepts a DataTable object.

You only need to design the report and add datasets to the RDL file.

Edit: Insert datasets as xml like this:

<DataSources>
    <DataSource Name="MyDataSource">
      <ConnectionProperties>
        <ConnectString />
        <DataProvider>SQL</DataProvider>
      </ConnectionProperties>
    </DataSource>
    ...
</DataSources>

<DataSets>
    <DataSet Name="MyDataSet">
      <Query>
        <CommandText>MyDataSet</CommandText>
        <DataSourceName>MyDataSource</DataSourceName>
      </Query>
      <Fields>
        <Field Name="Id">
          <DataField>ID</DataField>
        </Field>
        <Field Name="SomeOtherField">
          <DataField>SOME_OTHER_FIELD</DataField>
        </Field>
      </Fields>
   </DataSet>
</DataSets>
like image 197
Jaroslav Jandek Avatar answered Jun 02 '26 02:06

Jaroslav Jandek



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!