Print Page | Close Window

displaying wrong records

Printed From: Crystal Reports Book
Category: Crystal Reports for Visual Studio 2005 and Newer
Forum Name: Data Connectivity
Forum Discription: How to connect to data sources and export reports
URL: http://www.crystalreportsbook.com/forum/forum_posts.asp?TID=4881
Printed Date: 07 May 2024 at 9:38pm


Topic: displaying wrong records
Posted By: vyasdipti
Subject: displaying wrong records
Date Posted: 26 Nov 2008 at 2:21am

I have to show the  report of employee telephone numbers. So for this i gave two options:

1. All and 2. Employee wise.
 
In case 'Employee wise' radiobutton is clicked then one textbox will come where u will give employee id and all telephone numbers(residential cell / residential landline / personal cell / office number etc) of that particular employee will be displayed.
 
But in case the radiobutton 'All' is selected then all telephone numbers of all the employees will be displayed.
 
Here, i could do with both the things properly. For first time when i select the radiobutton of 'all' and click on show report it is displaying correct report giving telephone numbers of all the employees. Then when i select the radiobutton 'employee wise' and give the id of particular employee and click on button, then also particularly for that employee the report is displayed correctly.
 
but when i again come back to radiobutton 'all' after when once employee wise report is displayed, then in 'all' also same record is displayed and all records is not coming.
wat will be the reason for this? For your persual i m copy pasting the coding. Please get back to me with this at earliest.
 
 

protected void btnshow_Click(object sender, EventArgs e)

{

//rdbtcust is to show report customer wise

if (rdbtncust.Checked)

{

lblcustpk.Visible = true;

txtcustname.Visible = true;

btncustpk.Visible = true;

string custid = Session["custid"].ToString();

Response.Write(custid);

tblreport.Visible = true;

SqlDataAdapter dap = new SqlDataAdapter("select custid, fname, lname, restelno, mobileno, shopll, resmobno, others from tblcustgeneral where custid='" + custid + "'", con);

DataSet das = new DataSet();

dap.Fill(das);

ReportDocument rpt11 = new ReportDocument();

rpt11.Load(Server.MapPath("custwisetelno.rpt"));

rpt11.SetDataSource(das);

CrystalReportViewer1.SelectionFormula = "{tblcustgeneral.custid}=" + custid + "";

CrystalReportViewer1.ReportSource = rpt11;

CrystalReportViewer1.DataBind();

btnprint.Visible = true;

//custwisetotdeduction.rpt

}

//rdbtnall is to show report of all the customers

else if (rdbtnall.Checked)

{

SqlDataAdapter dap2 = new SqlDataAdapter("select custid, fname, lname, restelno, mobileno, shopll, resmobno, others from tblcustgeneral", con);

DataSet das2 = new DataSet();

dap2.Fill(das2);

ReportDocument rpt1 = new ReportDocument();

rpt1.Load(Server.MapPath("alltelno.rpt"));

rpt1.SetDataSource(das2);

tblreport.Visible = true;

CrystalReportViewer1.ReportSource = rpt1;

CrystalReportViewer1.DataBind();

btnprint.Visible = true;

}

}

 

protected void rdbtnall_CheckedChanged(object sender, EventArgs e)

{

Session["custid"] = null;

lblcustpk.Visible = false;

txtcustname.Visible = false;

btncustpk.Visible = false;

txtcustname.Text = "";

}

protected void rdbtncust_CheckedChanged(object sender, EventArgs e)

{

lblcustpk.Visible = true;

txtcustname.Visible = true;

btncustpk.Visible = true;

}



-------------
dIPTI vYAS
Arete Technologies Pvt Ltd
Sr.Systems Analyst



Replies:
Posted By: hilfy
Date Posted: 02 Dec 2008 at 12:32pm

It looks like you're using the same viewer for every load of the report.  You may need to close and dispose of the report in the viewer prior to loading a different report.  The code for this looks something like this:

If (CrystalReportViewer1.ReportSource != null)
{
 
  ((ReportDocument) CrystalReportViewer1.ReportSource).Close();
  ((ReportDocument) CrystalReportViewer1.ReportSource).Dispose();
}
 
I haven't tested this because we always open reports in new windows so we get a fresh viewer every time.  However, I think it will work.
 
-Dell


-------------
Proviti, Data & Analytics Practice
http://www.protiviti.com/US-en/data-management-advanced-analytics - www.protiviti.com/US-en/data-management-advanced-analytics



Print Page | Close Window