Solved

fill report from dataset  c#

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
ConsoleSql 1 34
c# LinkButton OnClientClick 2 34
SQL Query Producing decimal places when it shouldn;t be 8 35
Server Error 11 47
This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
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 …

932 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

13 Experts available now in Live!

Get 1:1 Help Now