i am using this code to search record in crystal report when print from print report button in crystal report i am using this code for displaying record .
using CrystalDecisions.Web;
using CrystalDecisions.Shared;
public partial class About : System.Web.UI.Page
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["con"].ToString());
SqlCommand cmd = new SqlCommand();
SqlDataAdapter da = new SqlDataAdapter();
DataTable dt = new DataTable();
DataTable dt1 = new DataTable();
protected void Page_Load(object sender, EventArgs e)
{
ReportDocument crystalReport = new ReportDocument();
crystalReport.Load(Server.MapPath("CrystalReport2.rpt"));
crystalReport.SetDatabaseLogon("sa", "123456789", @"TRAINING-ROOM-8", "newMreport");
CrystalReportViewer1.ReportSource = crystalReport;
}
protected void Button2_Click(object sender, EventArgs e)
{
SqlCommand cmd = new SqlCommand("SELECT * FROM Transactions where Patient = @Patient ");
cmd.Connection = con;
cmd.Parameters.Add("@Patient", SqlDbType.NVarChar).Value = TextBox3.Text;
SqlDataAdapter da = new SqlDataAdapter(cmd);
dt.Clear();
da.Fill(dt);
if (dt.Rows.Count > 0)
{
ReportDocument Report = new ReportDocument();
Report.Load(Server.MapPath("~/CrystalReport2.rpt"));
Report.SetDataSource(dt);
Report.SetDatabaseLogon("sa", "123456789", @"TRAINING-ROOM-8", "newMreport");
CrystalReportViewer1.ReportSource = Report;
CrystalReportViewer1.ReportSource = Report;
CrystalReportViewer1.DataBind();
}
}