Creating your First Crystal Report for Use in a .NET Application
page 3 of 6
by Jeff McWherter
Feedback
Average Rating: 
Views (Total / Last 10 Days): 29094/ 63

Data Schema

After you have created the Crystal Report file, the next step is defining a data schema. After you have “informed” the Crystal Report file of the data schema, a list of fields obtained from the data schema, will appear in the field explorer. Once the fields appear in the field explorer, you can "drag" the field to the report.

Before we discuss how to "inform" the Crystal Report of the data schema, let us first discuss how to obtain the data schema.  Creating an XML data schema is as simple as calling the WriteXMLSchema method off of a DataSet Object within code (VB or C#). The code below is a working example of calling a method to retrieve a list of employees, converting the list of employees into a DataSet object, and then writing the XML schema to a file named EmployeeData.xml.

Listing 1

List<Employee> employees = GetEmployeesAsList();
DataSet employeeDataSet = ListToDataset<Employee>(employees);
employeeDataSet.WriteXmlSchema(@"C:\EmployeeData.xml");

Below is what the EmployeeData.xml contains.  You will notice each field is listed with the data type.

Listing 2

<?xml version="1.0" standalone="yes"?>
<xs:schema id="ArrayOfEmployee" xmlns="" 
 xmlns:xs="http://www.w3.org/2001/XMLSchema" 
 xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
  <xs:element name="ArrayOfEmployee" msdata:IsDataSet="true" 
   msdata:UseCurrentLocale="true">
    <xs:complexType>
      <xs:choice minOccurs="0" maxOccurs="unbounded">
        <xs:element name="Employee">
          <xs:complexType>
            <xs:sequence>
              <xs:element name="FirstName" type="xs:string" minOccurs="0" />
              <xs:element name="LastName" type="xs:string" minOccurs="0" />
              <xs:element name="Address" type="xs:string" minOccurs="0" />
              <xs:element name="City" type="xs:string" minOccurs="0" />
              <xs:element name="State" type="xs:string" minOccurs="0" />
              <xs:element name="PostalCode" type="xs:string" minOccurs="0" />
              <xs:element name="Role" type="xs:string" minOccurs="0" />
            </xs:sequence>
          </xs:complexType>
        </xs:element>
      </xs:choice>
    </xs:complexType>
  </xs:element>
</xs:schema>

To "inform" the Crystal Reports file of the data schema, click on the Database Expert option in the toolbar, click Create New Connection and select ADO.NET (XML) as shown in Figure 2, and select the data schema that was just generated.

Figure 2:  Setting the data connection to the report

Once your data schema has been defined, you should see a list of columns in the Field Explorer under Database Fields as shown in Figure 3.

Figure 3:  Crystal Reports field expert

 

You can now “drag” your fields onto to your report.


View Entire Article

User Comments

Title: Many thanks   
Name: binam
Date: 2010-10-19 3:29:41 AM
Comment:
Many Many thanks for this article .
Title: A Look at Crystal Reports   
Name: Tahir Yaqoob
Date: 2010-10-11 6:35:28 AM
Comment:
A very nice article for any beginner to crystal reports.... thank's baby!!!!!!
Title: Article   
Name: Shawpnendu
Date: 2010-05-10 8:51:42 AM
Comment:
Very nice for novice developers.
Title: General Help with Crystal   
Name: Elizabeth
Date: 2010-04-27 3:18:06 PM
Comment:
Very helpful. A get started article allowing me to use Crystal without a lot of time spent learning.
Title: Article   
Name: Junaid
Date: 2010-03-22 9:42:00 AM
Comment:
It is such a useful to us. as i am a beginner so i got a very clear idea about Crystal Report.
Title: article   
Name: dave himanshu
Date: 2010-03-22 6:55:26 AM
Comment:
such a good job!!!
Title: deploy crystal report   
Name: john
Date: 2010-03-16 8:06:24 PM
Comment:
Great article. Thanks.

Once I have created a crystal report using visual studio 2008, what do I have to deploy to my server for the report to work on a shared hosting server?

Product Spotlight
Product Spotlight 



Community Advice: ASP | SQL | XML | Regular Expressions | Windows


©Copyright 1998-2024 ASPAlliance.com  |  Page Processed at 2024-04-24 2:26:29 PM  AspAlliance Recent Articles RSS Feed
About ASPAlliance | Newsgroups | Advertise | Authors | Email Lists | Feedback | Link To Us | Privacy | Search