469,917 Members | 1,907 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,917 developers. It's quick & easy.

using Crystal Reports to display data in my dataset correctly (display the data I selected instead of all the data in table)

JK
In my win form, I'm trying to display a Crystal report with the data in my
dataset only but, if I follow the steps in this msdn page:

http://msdn.microsoft.com/library/de...tinaviewer.asp

it always displays all the data regardless of the Select statement I run.
Here's my code:

InitializeComponent();
//my code

CrystalReport1 oRpt = new CrystalReport1(); //CrystalReport1.rpt - it
contais 3 fields from table ClientData: clientid, fname, lname

SqlConnection SQLConn = new SqlConnection("Data Source=localhost; Integrated
Security=SSPI;" +

"Initial Catalog=invoicing");

string strThisQuery = "select clientid, fname, lname from ClientData where
clientID = 4"; /it returns only one record

SqlDataAdapter MyDataAdapterClients = new SqlDataAdapter (strThisQuery,
SQLConn);

DataSet DS_MyReportsDS = new DataSet();

MyDataAdapterClients.Fill(DS_MyReportsDS, "ClientData");

oRpt.SetDataSource (DS_MyReportsDS);

crystalReportViewer1.ReportSource = oRpt;
It doesn't matter what my Select returns, it'll always display all the data
in ClientData. I posted a similar message a few days ago, and someone posted
this:
"If it contains the schema of all the columns, the CrystalReportViewer will
display all the data in the table regardless of your select." but I really
didn't understand what he meant. How would I be able to pass my Select
statement into the report?
Thanks.
Nov 15 '05 #1
1 2570
Hi.

One solution is to create a parameter in your Crystal Report (called
'ClientID') and set the properties at runtime in the code before setting the
Report Source, something like:

CrystalReport1 rpt = new CrystalReport1();
ParameterFieldDefinitions paramFieldDefs;
ParamterFieldDefinition paramFieldDef;
ParameterValues paramVal = new ParameterValues();
ParameterDiscreteValues paramDiscreteVal = new ParameterDiscreteValues();

paramDiscreteVal.Value = "4"; // the client id

paramFieldDefs = rpt.DataDefinition.ParameterFields;

paramFieldDef = paramFieldDefs.Item("ClientID");

paramVal = paramFieldDef.CurrentValues;

paramVal.Add(paramDiscreteVal);

paramFieldDef.ApplyCurrentValues(paramVal);

rpt.SetDataSource(DS_MyReportsDS);

crystalReportViewer1.ReportSource = oRpt;

crystalReportViewer1.Refresh();

---
Steven Wood
"JK" <NONE> wrote in message news:%2***************@tk2msftngp13.phx.gbl...
In my win form, I'm trying to display a Crystal report with the data in my
dataset only but, if I follow the steps in this msdn page:

http://msdn.microsoft.com/library/de...tinaviewer.asp
it always displays all the data regardless of the Select statement I run.
Here's my code:

InitializeComponent();
//my code

CrystalReport1 oRpt = new CrystalReport1(); //CrystalReport1.rpt - it
contais 3 fields from table ClientData: clientid, fname, lname

SqlConnection SQLConn = new SqlConnection("Data Source=localhost; Integrated Security=SSPI;" +

"Initial Catalog=invoicing");

string strThisQuery = "select clientid, fname, lname from ClientData where
clientID = 4"; /it returns only one record

SqlDataAdapter MyDataAdapterClients = new SqlDataAdapter (strThisQuery,
SQLConn);

DataSet DS_MyReportsDS = new DataSet();

MyDataAdapterClients.Fill(DS_MyReportsDS, "ClientData");

oRpt.SetDataSource (DS_MyReportsDS);

crystalReportViewer1.ReportSource = oRpt;
It doesn't matter what my Select returns, it'll always display all the data in ClientData. I posted a similar message a few days ago, and someone posted this:
"If it contains the schema of all the columns, the CrystalReportViewer will display all the data in the table regardless of your select." but I really
didn't understand what he meant. How would I be able to pass my Select
statement into the report?
Thanks.

Nov 15 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by airkart | last post: by
reply views Thread by Vadim Vulfov | last post: by
2 posts views Thread by aldous scotch | last post: by
1 post views Thread by cpnet | last post: by
6 posts views Thread by G. Stoynev | last post: by
1 post views Thread by Waqarahmed | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.