cancel
Showing results for 
Search instead for 
Did you mean: 

Dynamic XML as Datasource - View in .NET CrystalReportViewer

Former Member
0 Kudos

I have Crystal Reports XI R2 Developer Edition, Visual Studio 2008. I have an XML File that has sections structured in a relational way within the file. From this file, I've built a basic schema.

First problem: Building the proper RPT file. I think using the ADO.NET (XML) connection is the best way to go here, how do I get the RPT file to recognize the schema..? Here are the options in my head:

1. Select ADO.NET(XML) connection and when it asks for file, point it to the XSD file. This loads the fields in the field explorer, with the correct datatypes. But how then do I run a preview?

2. Link the schema file inside the XML file (and every XML file that will be called dynamically). Then Select ADO.NET (XML) and point it to the XML file, I can preview, but how do I switch XML files later (see problem 2).

Second Problem: Launching CrystalReportViewer with dynamic XML datasource. What needs to be done here.. ? Do I need a Dataset in my visual studio project? Can I just use the XML / XSD / RPT combination? How to I flip the RPT to use different XML files..?

There are zero examples of this it seems. Anything will help me. Thanks.

Accepted Solutions (1)

Accepted Solutions (1)

former_member183750
Active Contributor
0 Kudos

I'd recommend using datasets at runtime. I suppose you could go off of XML directly, but I find the crdb_adoplus.dll dataset driver much more stable and reliable than the XML driver, or ODBC. Essentially, once you have a dataset do:

crReportDocument.Database.Tables(0).SetDataSource(dataSet.Tables("NAME_OF_TABLE"))

or, you can try to go as:

crReportDocument.SetDataSource(dataSet) or crReportDocument.SetDataSource(dataSe.Tables(0))

Following link is to a great White paper on how best to work with datasets and Crystal Reports:

https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/401c4455-a31d-2b10-ae96-fa57af5a...

Ludek

Former Member
0 Kudos

That does help one of my problems, but the other is this.. Let me draw up a simple example.

Here is my XSD created in Visual Studio automatically from the XML files below:

<?xml version="1.0" encoding="utf-8"?>

<xs:schema xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">

<xs:element name="Movies">

<xs:complexType>

<xs:sequence>

<xs:element maxOccurs="unbounded" name="Movie">

<xs:complexType>

<xs:sequence>

<xs:element name="Title" type="xs:string" />

<xs:element name="Sales" type="xs:decimal" />

</xs:sequence>

<xs:attribute name="movieID" type="xs:decimal" use="required" />

</xs:complexType>

</xs:element>

</xs:sequence>

</xs:complexType>

</xs:element>

</xs:schema>

Here is XmlFile1

<?xml version="1.0" encoding="utf-8" ?>

<Movies xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="TheXML.xsd">

<Movie movieID="1">

<Title>Terminator</Title>

<Sales>100</Sales>

</Movie>

<Movie movieID="2">

<Title>Terminator 2</Title>

<Sales>200</Sales>

</Movie>

<Movie movieID="3">

<Title>Terminator 3</Title>

<Sales>300</Sales>

</Movie>

<Movie movieID="4">

<Title>Terminator 4</Title>

<Sales>400</Sales>

</Movie>

</Movies>

And XML File 2

<?xml version="1.0" encoding="utf-8" ?>

<Movies xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="TheXML.xsd">

<Movie movieID="1">

<Title>Terminator</Title>

<Sales>100</Sales>

</Movie>

<Movie movieID="2">

<Title>Terminator 2</Title>

<Sales>200</Sales>

</Movie>

<Movie movieID="3">

<Title>Terminator 3</Title>

<Sales>300</Sales>

</Movie>

<Movie movieID="4">

<Title>Terminator 4</Title>

<Sales>400</Sales>

</Movie>

<Movie movieID="5">

<Title>Terminator 5</Title>

<Sales>500</Sales>

</Movie>

</Movies>

Now I open CR 11 XI, create a new report, Report1.rpt. Use ADO.NET (XML) connection, select the XSD file, and I see my three fields (movieID, Title, and Sales) with correct Datatypes (Number and String). I put the three fields in the details section.

I can switch in code which XML I want to launch, and it works good. But my problem is, while designing the report, how do I preview it within Crystal to make sure things are looking good, without launching my app from Visual Studio? My goal is for clients to customize their own RPT based off this schema file, but it won't work well for them without being able to see whats going on from within CR.

Edited by: Kurtas BB on Sep 19, 2008 8:12 PM

Former Member
0 Kudos

(edit - not really .net related)

Edited by: Kurtas BB on Sep 22, 2008 2:00 PM

former_member183750
Active Contributor
0 Kudos

Umm, not sure I understand. I have test.xml and test.xsd in the same folder. I create a report using the ADO (.NET) XML driver, pointing it at the XML. Throw a few fields on the report, hit refresh and the data comes in from the xml. Type of the fields will be the same as specified in the xsd of the same name as the xml. I can update the xml and I'll get the new data. I can change the filed types in the xsd and on Verify Database (database menu), the field types will be updated in the CR designer. I suspect I am not answering your question, but let me know...

Ludek

Former Member
0 Kudos

For me, when I point the ADO source at the .XML file, all of the datatypes are String. When I point the ADO source at the .XSD file, I get the datatypes of string and Number as I expect.

I'm using Crystal 11 R2, product version 11.5.8.826

former_member183750
Active Contributor
0 Kudos

I believe, you are seeing this in the CR designer? If that is the case, i'd recommend posting the query to the Report Design Forum will be the way to go:

Ludek

Answers (1)

Answers (1)

Former Member
0 Kudos

I've been reading that VS 2008 is not directly compatible with CR XI R2, but I also have VS 2005, so my questions remain with either IDE.

Edited by: Kurtas BB on Sep 19, 2008 4:58 PM