Groups | Blog | Home
all groups > dotnet windows forms > march 2007 >

dotnet windows forms : Crystal Reports: displaying data from an SQL DataTable in C#


JT
3/7/2007 4:33:43 PM
This is my first Crystal Report project, using the CrystalReportViewer in
Visual Studio 2005. I want to display records in a DataTable (called
DTable) created by my C# program, taken from an SQL database. My project is
a Windows Forms project, not an ASP.NET project.

I dragged an instance of crystalReportViewer onto my form, and used the
build-in wizard to create a report, which is named CrystalReport1.rpt by
default.

I have a class that reads the SQL database and creates the DataTable. Then
I have the following code:

CrystalReport1 cr = new CrystalReport1();
cr.SetDataSource(DTable);
frm.crystalReportViewer1.ReportSource = cr;

Everything compiles. However, when I run the form, I am presented with an
input box to enter the field data. It does not take the data from the
DataTable, even though the crystalReportViewer's data source is set to
"None."

I'd like to know why it presents an input box rather than take the data from
the data source indicated.

Thanks very much for any information.

Mark Chimes
3/8/2007 12:00:00 AM
Hi JT,

Here is some code that will help you.
What you have done is try and connect your datasource to the Crystal Report
DatatSource.
What you actually need to do is pass your datasource to the Crystal Report
sand let it connect "internally".

System.Configuration.AppSettingsReader configurationAppSettings
= new System.Configuration.AppSettingsReader();
//string strServerName =
((string)(configurationAppSettings.GetValue("ServerName", typeof(string))));
//"SERVER2003/SQLEXPRESS"; //physical server name
// if (strReport == "Team")
{
DataSourceConnections dataSourceConnections =
crReportDocument.DataSourceConnections;
IConnectionInfo connectInfo = dataSourceConnections[0];
//connectInfo.SetConnection(strServerName, "WORKman",
"SQLUSerID", "password");
crViewer.ReportSource = crReportDocument;
if (strFormula != string.Empty)
crReportDocument.DataDefinition.RecordSelectionFormula =
strFormula;
}


cheers,
Mark Chimes

[quoted text, click to view]

--------------------------------------------------------------------------------
I am using the free version of SPAMfighter for private users.
It has removed 1865 spam emails to date.
Paying users do not have this message in their emails.
Try SPAMfighter for free now!

AddThis Social Bookmark Button