Solved

C# Print to Cystal Reports

Posted on 2004-03-28
5
309 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
  • 3
5 Comments
 
LVL 69

Expert Comment

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

Author Comment

by:jvoros1
Comment Utility
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
Comment Utility
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 500 total points
Comment Utility
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
Comment Utility
Thanks so much i got it working with your help Simion
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Introduction                                                 Was the var keyword really only brought out to shorten your syntax? Or have the VB language guys got their way in C#? What type of variable is it? All will be revealed.   Also called…
This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
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…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

771 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

15 Experts available now in Live!

Get 1:1 Help Now