programmatically adding ADO dataset to crystal report in .NET 
Author Message
 programmatically adding ADO dataset to crystal report in .NET

Can someone help me out? I can't figure out how to do this.

Thanks!



Wed, 25 Aug 2004 03:50:41 GMT  
 programmatically adding ADO dataset to crystal report in .NET
Start off by creating and xsd file (xml schema) that matches your stored
procedure call of table that you are querying.  If you are lucky then you
can use your server explorer to drag and drop the item onto the xsd, thus
autocreating it.  Even if you have to do it by hand it's not that hard.
Just make sure that your xsd matches the column order and data types that
the intended dataset tables will contain.

Once you've done this you can link your Crystal Report to the xsd, allowing
you to design it on the designer.  Use SetDataSource to pass your dataset
into an instance of your report.

HTH

Cheers

--
Robert Chapman, MCSD
Manager, Applications Development
prairieFyre Software Inc.
http://www.prairiefyre.com

Quote:
> Can someone help me out? I can't figure out how to do this.

> Thanks!



Wed, 25 Aug 2004 05:10:25 GMT  
 programmatically adding ADO dataset to crystal report in .NET

Quote:

> Can someone help me out? I can't figure out how to do this.

> Thanks!

I have done this with C#, but it shouldn't be hard to translate.  I am
also a beginner with Crystal, so be warned.

1. Add a dataset to the project.  Log on to the server with the
database, and drag-n-drop the tables you want.  For my example, the
Benefits, Employer, and Employee tables.  The Visual linker will come
up, and you just drag the little arrows around.  For my tables, each
record has a uniqueidentifier (UID), and holds the UID of a record in
one of the other tables (Benefit record has its own UID and an
EmployeeUID, Employee has an EmployerUID).  This establishes a
relationship between tables.  For instance, I drag the arrow from
EmployeeUID in Benefits to UID in Employee.

2. Add a Crystal Report.  Log on server (right-click menu for Database
fields) to the ADO.NET DataSets, and select your added dataset.  Close
that window, and look at your Field Explorer.  Expand Databse Fields,
and you will see the fields from the tables added.  Drag-n-drop them
onto the report.

3. Add a form.  Add the Crystal Viewer control.  In the code behind
the form, I create an instance of the .rpt object, then I create a
DataSet.  I set the data source of the report instance as the dataset,
then I set the ReportViewer control's report source as the local
report instance.

4. I fill the dataset from a separate data access class, which handles
all the communications with the database.  In this project, I create
an instance of my dataAccess class, then call a function which returns
a dataset:
"DataSet ds = (new ReportDB()).GetConfirmationOfBenefitsDataSet();"

In the ReportDB dataAccess class, I connect to SQL, call three
separate stored procedures on three separate tables, and add the
tables one by one to a local dataset which is then returned:

"public DataSet GetConfirmationOfBenefitsDataSet()
                {
                        DataSet result = new DataSet("ConfirmationOfBenefits");
                        DataTable benefits = new DataTable("Benefits");
                        DataTable employee = new DataTable("Employee");
                        DataTable employer = new DataTable("Employer");

                        SqlConnection myConnection  = new
SqlConnection(ConfigurationSettings.AppSettings["ConnectionString"]);
                        SqlCommand myCommand  = new SqlCommand();
                        myCommand.CommandType = CommandType.StoredProcedure;
                        myCommand.Connection = myConnection;

                        myCommand.CommandText = "GetAllBenefits";
                        SqlDataAdapter daa = new SqlDataAdapter(myCommand);
                        daa.Fill(benefits);
                        result.Tables.Add(benefits);

                        myCommand.CommandText = "GetAllEmployees";
                        SqlDataAdapter dab = new SqlDataAdapter(myCommand);
                        dab.Fill(employee);
                        result.Tables.Add(employee);

                        myCommand.CommandText = "GetAllEmployers";
                        SqlDataAdapter dac = new SqlDataAdapter(myCommand);
                        dac.Fill(employer);
                        result.Tables.Add(employer);

                        return result;
                }"

5. There have to be stored procs in the database.  These I have are
just simple ones that return all fields of all records in that table.

I hope this gets you started.  I had a terrible time with this, as
every example and help page I could find only dealt with Access or
ODBC.  Again, I am new to Crystal, so please don't take my example as
the gospel truth.  Good luck!

Pete



Wed, 25 Aug 2004 06:09:14 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Crystal Report based on ADO.Net dataset prompts for database login

2. Adding a Relationship between Tables (ADO.NET Dataset)

3. Passing Dataset to Crystal Report in VB.Net

4. Using DataSet In the Crystal report.NET

5. Sorting in Vb.net crystal reports dataset

6. Missing some steps in creating a report to use a ADO.net dataset

7. Crystal Reports 8.5 (VB6) to Crystal Reports NET (VB.NET) conversion

8. Report with untyped DataSet (ADO.NET)

9. Help in Reporting off ADO.NET DataSet

10. Crystal Reports from ASP.NET without compiling VB.NET on SQL/ADO changes

11. Setting Custom parameters programmatically in crystal reports.net

12. Hierarchical ADO recordset -> ADO.NET Dataset Fill

 

 
Powered by phpBB® Forum Software