Error in crystal report

Posted by Klbaiju under Others on 3/31/2011 | Points: 10 | Views : 1210 | Status : [Member] | Replies : 5
Hi,
following is my code for display crystal report.
I want to display only a particular report based on the condition.
ie I want to display only one record.but when i run run ,all records are showing .condition is not working.
what i have to do.
Regards
K L BAIJU

protected void Button1_Click(object sender, EventArgs e)
{
SqlDataAdapter da = new SqlDataAdapter("select * from customers where customerid='" + TextBox1.Text + "'", con);
DataSet ds = new DataSet();
da.Fill(ds);
ReportDocument report = new ReportDocument();
string reportpath = Server.MapPath("CrystalReport5.rpt");
report.Load(reportpath);
report.SetDataSource(ds);
CrystalReportViewer1.ReportSource = report;

}




Responses

Posted by: Prabhakar on: 3/31/2011 [Member] [MVP] Starter | Points: 25

Up
0
Down
Hi Klbaiju

i think u want one record to ur crystel report so u set ur SQL Query


SqlDataAdapter da = new SqlDataAdapter("select TOP 1(*) from customers where customerid='" + TextBox1.Text + "'", con);

Best Regard's
Prabhakar

Klbaiju, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Klbaiju on: 3/31/2011 [Member] Starter | Points: 25

Up
0
Down
If i enter alfki on textbox ,i need the record of alfki

Klbaiju, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Prabhakar on: 3/31/2011 [Member] [MVP] Starter | Points: 25

Up
0
Down
Hi Klbaiju

ur condition is right . . so why many record come in ur datset . . chek it ur Dataset on runtime . .

Best Regard's
Prabhakar

Klbaiju, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sheeba on: 4/1/2011 [Member] Starter | Points: 25

Up
0
Down
Hi Klbaiju

Did you gave the dataset name correct?

That dataset name should come under the name ahich you create..for ex:Dataset1 is my dataset means u should use this name for dataset like this

Dataset1 ds=new Dataset1();
got it?


Try like this

DataSet1 ds = new DataSet1();
DataTable dt = new DataTable();
dt = ds.Tables["Getdetails"];
da.Fill(dt);
ReportDocument report = new ReportDocument();
string reportpath = Server.MapPath("CrystalReport.rpt");
report.Load(reportpath);
report.SetDataSource(dt);
CrystalReportViewer1.ReportSource = report;
Reply me.....

Klbaiju, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Klbaiju on: 4/2/2011 [Member] Starter | Points: 25

Up
0
Down

this is my code .still it has showing all records in customers table
protected void Button1_Click(object sender, EventArgs e)
{
SqlDataAdapter da = new SqlDataAdapter("select * from customers where customerid='" + TextBox1.Text + "'", con);
DataSet ds = new DataSet();
da.Fill(ds);
ReportDocument report = new ReportDocument();
string reportpath = Server.MapPath("CrystalReport5.rpt");
report.Load(reportpath);
report.SetDataSource(ds);
CrystalReportViewer1.ReportSource = report;

}

Klbaiju, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response