Solved

C# Print to Cystal Reports

Posted on 2004-03-28
5
312 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 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 500 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

856 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