Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Passing Dataset to Crystal Report at RunTime.

Status
Not open for further replies.

crystalruchs

Programmer
Sep 6, 2002
11
US
Hi everybody,

I am trying to pass a Dataset to the Crystal Report at runtime, so that I can prevent the Crystal Report from making physical connection with the Data Base.

I get my Dataset from the stored procedure within C#, and same stored procedure is bound to the Crystal Report. My question is How can I prevent Crystal Report at runtime from making connection to the Database & calling the stored procedure. It should just display the data received from the Dataset.

I am generating Crystal Rpeort from C#, and DB I am conecting to is MS-SQL server.

Thanks in advance.
Ruchi
 
This is the way I do it:

You write an .xsd XML schema file to your hard drive, which contains the data types and columns of the database.

When you make the report, set its data sources as ADO.NET (XML). You pick that .xsd file you made.

Then, at runtime, you create an instance of the report and set its datasource to your dataset.

Unbind the stored procedure, and bind the report to the .xsd file.
 
Thanks for the reply. This really seems doable.

I created a temporary table with the same fields and associated it with the dataset dataset1.xsd file to create XML schema.

But when I created a report and tried to link it to dataset1.xsd via ADO.NET dataset, it is able to find dataset1.xsd, but underneath it says no items found (where it should have said the field names of the dataset).

I think I am not creating the XML schma properly. I would appreciate if you can please send me a sample XML schema file for reference.

Thanks in advance
Ruchi
 
It should have the name of the table instead of no items found.

The part that I think you might be missing is this:

"yourDataAdapter.TableMappings.Add("Table", "yourTableOrViewName");"

How did you create the schema? Did you do something like:

"yourDataSet.WriteXmlSchema("yourFileName.xsd");"?

The above is the correct way.

Another thing you might try is forgetting about the XML--if you have the report completely designed and all the field names and table names are consistent. Then you can just change the datasource and see if it works:

"yourReportName newInstanceReportName = new yourReportName();

newInstanceReportName.SetDataSource(yourDataSet);

yourReportViewerName.ReportSource = newInstanceReportName;"

 
I created the Dataset by using "Add New Item" and then dragged and dropped the temporary table which has same fields and data types.

There after I created a crystal report by saying "Add New Item". Then during the creation it asks for the datasource, this is where I faced the problem, when I try to select ADO.NET dataset

I don't know where I am supposed to add:

"yourDataAdapter.TableMappings.Add("Table", "yourTableOrViewName");"

"yourDataSet.WriteXmlSchema("yourFileName.xsd");"?

The report is not already designed. I am trying to create all new report with this new dataset.

 
I will be doing this
"yourReportName newInstanceReportName = new yourReportName();

newInstanceReportName.SetDataSource(yourDataSet);

yourReportViewerName.ReportSource = newInstanceReportName"

only after my Report "yourReportName " is ready and successfully associated with the dataset.

I guess the problem is in associating the table name to .xsd file. But I am unable to figure out, exactly what.

Please suggest.

Thanks
Ruchi
 
Oh ok, I see. I made all the connection, dataadapter, and datasets in code. Did you make a data adapter? I'm sure you did since you made a data set object from the tool box?

Where do you instantiate you connection? Place those two comments you were wondering about after you've made the connection in code.

I believe the table mappings for the dataadapter would go before the spot where you fill up the data set, and the xml schema writing would go after you have filled the data set.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top