Solved

fill report from dataset  c#

Posted on 2009-05-15
5
922 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

822 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