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

  • Thread starter Thread starter JT
  • Start date Start date
J

JT

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.
 
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
 
Hola Mark, yo tengo el mismo problema de JT, la diferencia es que el mio
está creado en VS.NRET 2005...

Agradecería cualquier comentario..

Saludos

Pedro
Peru

Mark Chimes said:
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

JT said:
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.

--------------------------------------------------------------------------------
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!
 
Back
Top