?
Solved

C# Print to Cystal Reports

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

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
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.
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Suggested Courses

741 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