Web Service + DataSet + Crystal Report?

  • Thread starter David P. Donahue
  • Start date
D

David P. Donahue

Maybe this is an easy thing to do, but I'm just not seeing how it's done
(or at least how it's done properly). I have a web service running on a
remote machine which returns a DataSet. I can easily write an xsd file
to define that DataSet, if need be. Now, on a local Windows Forms
application, I need to have a CrystalReportViewer open up a Crystal
Report which needs to get its data from that Web Service.

How would this be done? It's really the first time I've used Crystal
Reports while learning .NET and everything I see online seems to rely on
directly connection to a database, which isn't the case here.

I tried writing the xsd file and opening that in Visual Studio and using
it to generate a DataSet. I then created a DataSet object on my form
which inherits its structure from that generated one. I used this
DataSet to create the Crystal Report file (very simple report) and put
the right fields in the right places. But now how do I hook in the data
from the web service at runtime and then show the report in the
CrystalReportViewer?


Regards,
David P. Donahue
(e-mail address removed)
http://www.cyber0ne.com
 
M

Michael Nemtsev

Hello David,

As I remember, Crystal has DataSource where you can point your DataSet from
webService

DD> Maybe this is an easy thing to do, but I'm just not seeing how it's
DD> done (or at least how it's done properly). I have a web service
DD> running on a remote machine which returns a DataSet. I can easily
DD> write an xsd file to define that DataSet, if need be. Now, on a
DD> local Windows Forms application, I need to have a
DD> CrystalReportViewer open up a Crystal Report which needs to get its
DD> data from that Web Service.
DD>
DD> How would this be done? It's really the first time I've used
DD> Crystal Reports while learning .NET and everything I see online
DD> seems to rely on directly connection to a database, which isn't the
DD> case here.
DD>
DD> I tried writing the xsd file and opening that in Visual Studio and
DD> using it to generate a DataSet. I then created a DataSet object on
DD> my form which inherits its structure from that generated one. I
DD> used this DataSet to create the Crystal Report file (very simple
DD> report) and put the right fields in the right places. But now how
DD> do I hook in the data from the web service at runtime and then show
DD> the report in the CrystalReportViewer?
DD>
DD> Regards,
DD> David P. Donahue
DD> (e-mail address removed)
DD> http://www.cyber0ne.com
---
WBR,
Michael Nemtsev :: blog: http://spaces.msn.com/laflour

"At times one remains faithful to a cause only because its opponents do not
cease to be insipid." (c) Friedrich Nietzsch
 
B

Bruce Wood

Funny you should mention that... I'm just now working on our code that
does something similar. Here is a snippet from our code that does
something similar to what you want to do. You will have to write some
C# "glue" to mediate between the Web Service and Crystal, but this
should get you started:

private bool LoadUpCrystal()
{
if (this.crystalDoc == null)
{
try
{
if (!ReadCrystalInformation(out this.data, out this.reportName, out
this.templateName))
{
return false;
}
else
{
this.crystalDoc = GetEmptyReport(this.templateName,
this.reportName);
this.crystalDoc.SetDataSource(this.data);
}
}
catch (Exception ex)
{
MessageBox.Show("Crystal ReportDocument " +
"would not accept/print the XML data in " +
"the file '" + this.printFileName + "' (" +
reportName + ")\n" +
"There is probably a mismatch between this " +
"data and the report template '" +
templateName + "'\n" +
ex.ToString(),
WindowsReportPrinter.ErrorMessageTitle,
MessageBoxButtons.OK, MessageBoxIcon.Error);
return false;
}
}
return true;
}

private static ReportDocument GetEmptyReport(string
reportTemplateFileName, string defaultReportName)
{
ReportDocument crystalDoc = new ReportDocument();
try
{
crystalDoc.Load(reportTemplateFileName,
OpenReportMethod.OpenReportByTempCopy);
}
catch (Exception ex)
{
throw new ArgumentException("Unable to load Crystal Report '" +
reportTemplateFileName + "'.", ex);
}
if (crystalDoc.SummaryInfo.ReportTitle == null ||
crystalDoc.SummaryInfo.ReportTitle.Length == 0)
{
crystalDoc.SummaryInfo.ReportTitle = defaultReportName;
}
return crystalDoc;
}
 
D

David P. Donahue

Ah. I never did see a DataSource property, but when you said it's there
it got me looking a little harder and I found a SetDataSource() method.
Your push in the right direction helped me find the page:

http://www.vbcity.com/forums/topic.asp?tid=10205

(which was easy enough to translate into C#) and that made it as simple
as can be. Now it works great, thanks!


Regards,
David P. Donahue
(e-mail address removed)
http://www.cyber0ne.com
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top