INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Reflection

Easy way to write Crystal Reports with coded DataSets by RiverGuy
Posted: 26 Sep 02

The way I prefer to set up my datasources in the .Net environment for Crystal Reports is via way of my dataSets.

Now if you have dataSet objects in the designer, you can set your report's source to use a dataSet that you have create.

But what if you have all of your dataSets created through your code itself?

The method I like to use is to write the XML schema to a file and then use the report designer, with the .XSD file as the data source.

After you have envoked the fill method of your dataAdapter to fill your dataSets, such as:

dataAdapter1.Fill(dataSet1);

You can then write the schema to an .XSD File, such as:

dataSet1.WriteXmlSchema("Filename.xsd");

Now, during the creation of your report, choose Other Sources for the data source, and ADO.Net (XML).  Browse to find your .XSD file.  This will give you all of the tables, columns, and data types that your data set contains.  You can go about creating your report as you would like.

To populate the report with actual data, here is what you do:

1.  Run your program, being sure to envoke the command to write the XSD file.
2.  Create a Crystal Report viewer.
3.  Create an instance of your report class:
    yourCrystalReport cr = new yourCrystalReport();
4.  Set the data source for your report instance:
    cr.SetDataSource(dataSet1);


That's all there is too it.  There are other ways of course.  You could probably get away with designing the report from another type of datsource, such as ODBC or Jet, or ADO or whatever, and then changing the dataSource.  I haven't tried any of the latter methods, but the XML schema method works well for me.  An advantage would be that the schema would remain static, and reusable, and you would not have to go through a larger process of selecting say a SQL Server, and a database, then the tables, etc.

By creating the instance of the report, instead of assigning the actual report class, or .rpt file to the report source of the viewer, you can manipulate the report.  An example would be to change the text of formula fields.

This is accomplished by:
cr.DataDefinition.FormulaFields["FieldName"].Text = " CrystalSyntaxHere".

Substituting the name of your report instance for 'cr'.

Back to C# (C sharp): Microsoft FAQ Index
Back to C# (C sharp): Microsoft Forum

My Archive

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close