[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

C# Print to Cystal Reports

Posted on 2004-03-28
5
Medium Priority
?
319 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 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

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…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Suggested Courses

873 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