Solved

fill report from dataset  c#

Posted on 2009-05-15
5
919 Views
Last Modified: 2012-05-07
Hi all,

I have to make some reports and going to use the Microsoft Reports.
Now I want to fill the reports from a dataset that I create at runtime but how can I first make a report for data I don't have at the moment?
I'll be a mixed dataset with data from severall tables joined in one dataset.

How do I do this?

Basicly, want to run my code, create a dataset, add it to a report, then open the report OR save it as PDF without even opening the report.

Greetings



0
Comment
Question by:Pit76
  • 3
  • 2
5 Comments
 
LVL 2

Expert Comment

by:phead_2
ID: 24399740
You need to create a dummy datasource(s) in the report to generate the field names. You can then add the dataset while running (and go straight to PDF if you like).

Open your .rdlc file by right clicking it in the solution explorer and pick open with. open with 'XML Editor'. In the top section add your datasets:
  <DataSources>

    <DataSource Name="DummyDataSource1">

      <rd:DataSourceID>c649d533-64c3-42b6-9805-19adbfccd468</rd:DataSourceID>

      <ConnectionProperties>

        <DataProvider>SQL</DataProvider>

        <ConnectString />

      </ConnectionProperties>

    </DataSource>

  </DataSources>

Open in new window

0
 
LVL 2

Accepted Solution

by:
phead_2 earned 500 total points
ID: 24399804
Didn't finish my post... After adding the datasource you need to create the dataset(s)"


  <DataSets>
    <DataSet Name="DataSet1">
      <Fields>
        <Field Name="StringField1">
          <DataField>StringField1</DataField>
          <rd:TypeName>System.String</rd:TypeName>
        </Field>
        <Field Name="StringField2">
          <DataField>StringField2</DataField>
          <rd:TypeName>System.String</rd:TypeName>
        </Field>
      </Fields>
      <Query>
        <DataSourceName>DummyDataSource1</DataSourceName>
        <CommandText />
        <rd:UseGenericDesigner>true</rd:UseGenericDesigner>
      </Query>
      <rd:DataSetInfo>
        <rd:TableName>DataTable1</rd:TableName>
      </rd:DataSetInfo>
    </DataSet>
    <DataSet Name="DataSet2">
      <Fields>
        <Field Name="StringField1">
          <DataField>StringField1</DataField>
          <rd:TypeName>System.String</rd:TypeName>
        </Field>
        <Field Name="StringField2">
          <DataField>StringField2</DataField>
          <rd:TypeName>System.String</rd:TypeName>
        </Field>
      </Fields>
      <Query>
        <DataSourceName>DummyDataSource1</DataSourceName>
        <CommandText />
        <rd:UseGenericDesigner>true</rd:UseGenericDesigner>
      </Query>
      <rd:DataSetInfo>
        <rd:TableName>DataTable2</rd:TableName>
      </rd:DataSetInfo>
    </DataSet>


You can then use the fields defined in the datasets in the report.

To populate the datasets make data tables (I named them table1 and table2) that match the datasets (table names, column names and datatypes). Create report datasources, load the report and export to pdf:



                            ReportDataSource DS1 = new ReportDataSource("DataTable1", table1);

                            ReportDataSource DS2 = new ReportDataSource("DataTable2", table2);

                            LocalReport report = new LocalReport();

                            report.ReportPath = path to your .rdlc file...

                            report.DataSources.Add(DS1);

                            report.DataSources.Add(DS2);
 

            string deviceInfo =

              "<DeviceInfo>" +

              "  <OutputFormat>PDF</OutputFormat>" +

              "  <PageWidth>8.5in</PageWidth>" +

              "  <PageHeight>11in</PageHeight>" +

              "  <MarginTop>0.1in</MarginTop>" +

              "  <MarginLeft>0.1in</MarginLeft>" +

              "  <MarginRight>0.1in</MarginRight>" +

              "  <MarginBottom>0.1in</MarginBottom>" +

              "</DeviceInfo>";
 

            Stream CreateStream = new FileStream(pathtofileyouwanttocreate, FileMode.Create);
 
 

            report.Render("PDF", deviceInfo, CreateStream,

               out warnings);

Open in new window

0
 

Author Comment

by:Pit76
ID: 24403017
thx for that info!

Now I changed my mind and will generate teh report from an object ( a class). I have at that time a class with all the needed data, so it would be dumb of me to send a query to the db for data I allready have.

Below a codesnippet. How can I add my class as the datasource for the report? It is done in the report designer when I drag al the fields to my report, but when I fill my class at runtime the report doesn't take the new values I provide...

Thx for any help..


 ReportDocumentBLL _localReport = new ReportDocumentBLL();

      try

      { 

        // testdata

        _localReport.Type = "test";

        _localReport.StructureleMededeling="+++105/2009/11289+++";

        _localReport.Nummer = 1052009;

    

          // fill report with data from _localReport

          // ???

Open in new window

0
 

Author Comment

by:Pit76
ID: 24403050
K, found it!

Had to bind the datasource to the class:

ReportDocumentBLLBindingSource.DataSource = _localReport;
reportViewer1.RefreshReport();

Thx for the help with the datasets, will come in handy later... :)
0
 

Author Closing Comment

by:Pit76
ID: 31581921
thx
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Bit flags and bit flag manipulation is perhaps one of the most underrated strategies in programming, likely because most programmers developing in high-level languages rely too much on the high-level features, and forget about the low-level ones. Th…
In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now