[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

C# Print to Cystal Reports

Posted on 2004-03-28
5
Medium Priority
?
318 Views
Last Modified: 2010-08-05
Hello Expert, I have a windows form and I would like to send to crystal reports the infomation that is in the textboxs. And I need it to print to the printer without  it actually opening the Crystal Reports Viewer. Is there anyway you can help me.
Thanks
0
Comment
Question by:jvoros1
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
5 Comments
 
LVL 70

Expert Comment

by:Éric Moreau
ID: 10699526
Have a look in the free ebook: http://www.crystalreportsbook.com
0
 

Author Comment

by:jvoros1
ID: 10699637
I tried but I can't seem to find what i need the book is not finished from what i can see
0
 

Author Comment

by:jvoros1
ID: 10699836
I tried  but it says invalid field name on my pir.rpt I have a Formula Field called Proj, do you know why i get this error?
 Reportpir =new pir();
                  ParameterDiscreteValue aParamDisVal = new ParameterDiscreteValue();
                  ParameterValues aParamVals = new ParameterValues();
                  aParamVals = myReport.DataDefinition.ParameterFields["@Proj"].CurrentValues;
                  aParamDisVal.Value = "Testing";
                  aParamVals.Add(aParamDisVal);
                  Reportpir.DataDefinition.ParameterFields["@Proj"].ApplyCurrentValues(aParamVals);
                  crystalReportViewer1.ReportSource = Reportpir;
0
 
LVL 1

Accepted Solution

by:
simion_tishler earned 2000 total points
ID: 10700277
Hey dude

I don't know how much you know so I'II tell you from the start to finish.

You have to create a dataSet and attach it to your project. This should not be connected to a form. So go add new item/dataset to project. Or you can create one using xml if you know how to do this I have a sample below.

<?xml version="1.0" encoding="utf-8" ?>
<xs:schema id="Duplicate_Letters_DataSet" targetNamespace="http://tempuri.org/Duplicate_Letters_DataSet.xsd"
      elementFormDefault="qualified" attributeFormDefault="qualified" xmlns="http://tempuri.org/Duplicate_Letters_DataSet.xsd"
      xmlns:mstns="http://tempuri.org/Duplicate_Letters_DataSet.xsd" xmlns:xs="http://www.w3.org/2001/XMLSchema"
      xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
      <xs:element name="Duplicate_Letters_DataSet" msdata:IsDataSet="true">
            <xs:complexType>
                  <xs:choice maxOccurs="unbounded">
                        <xs:element name="vis_APP_DUPLICATE_LETTERS">
                              <xs:complexType>
                                    <xs:sequence>
                                          <xs:element name="DATESENT" type="xs:dateTime" minOccurs="0" />
                                          <xs:element name="APPLICANT_NBR" type="xs:string" minOccurs="0" />
                                          <xs:element name="LETTER_CONTENT" type="xs:string" minOccurs="0" />
                                          <xs:element name="SUBURB" type="xs:string" minOccurs="0" />
                                          <xs:element name="STREET" type="xs:string" />
                                          <xs:element name="STATE" type="xs:string" minOccurs="0" />
                                          <xs:element name="POSTCODE" type="xs:string" minOccurs="0" />
                                          <xs:element name="PIN_NBR" type="xs:string" minOccurs="0" />
                                          <xs:element name="GIVEN_NAME" type="xs:string" />
                                          <xs:element name="SURNAME" type="xs:string" />
                                          <xs:element name="SEX_CODE" type="xs:string" minOccurs="0" />
                                    </xs:sequence>
                              </xs:complexType>
                        </xs:element>
                  </xs:choice>
            </xs:complexType>
      </xs:element>
</xs:schema>

Okay so the idea is too create this dataset bases on what you want to see on the crystal report. So it may not be a copy of some table in a database.

Then what I did was to create a crystal report based on the dataset. Use the wizards.

Then when the program is running you collect the data from the form create a dataset on the fly during runtime. Then you make the dataset the datasource of the crystal report and then open the crystal report.

Heres some code on the above.

DataSet DuplicateLettersSet;
                  
                  this.Cursor = Cursors.WaitCursor;

                  DuplicateLettersSet = DuplicateObj.Get_Refund_Duplicate_Letters();

                  if(DuplicateLettersSet.Tables["vis_app_duplicate_letters"].Rows.Count>0)
                  {
                        Print_Duplicates_Letters PrintDupLettersFrm = new Print_Duplicates_Letters(DuplicateLettersSet);

                        PrintDupLettersFrm.MdiParent = this;
                        PrintDupLettersFrm.Show();

                        
                  }
                  else
                        MessageBox.Show("There are no 'Refund' duplicate letters in the queue","Print Refund Duplicate Letters",MessageBoxButtons.OK,MessageBoxIcon.Information);

In my case I didn't have to create the dataset on the fly I got it from the database and passed it to the constructor of a class that opened the crystal report.

Heres the code to open the crystal report

private void Print_Duplicates_Letters_Load(object sender, System.EventArgs e)
            {                  
                  Duplicate_Letter DupLetters = new Duplicate_Letter();
 
                  DupLetters.SetDataSource(DuplicateLetterSet);

                  crystalReportViewer1.ReportSource = DupLetters;
            }

Sorry if that is a alot to look at and I hope it helps.

Regards

Simion
0
 

Author Comment

by:jvoros1
ID: 10701030
Thanks so much i got it working with your help Simion
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
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…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…

656 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