How to Make CrystalReport and Search Data in C# .NET

  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.ComponentModel;  
  4. using System.Data;  
  5. using System.Drawing;  
  6. using System.Linq;  
  7. using System.Text;  
  8. using System.Windows.Forms;  
  9. using CrystalDecisions.CrystalReports.Engine;  
  10. using System.Data.OleDb;  
  11. using SakshiHospital;  
  12. namespace ClientManagementApp  
  13. {  
  14.    public partial class Cry_Report : Form  
  15.    {  
  16.       public Cry_Report()  
  17.       {  
  18.          InitializeComponent();  
  19.          // Cry_Report  
  20.          //  
  21.          this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);  
  22.          this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;  
  23.          this.ClientSize = new System.Drawing.Size(721, 439);  
  24.          this.Name = "Cry_Report";  
  25.          this.Text = "Cry_Report";  
  26.          this.Load += new System.EventHandler(this.Cry_Report_Load);  
  27.          this.ResumeLayout(false);  
  28.          //  
  29.                                 //// CrystalDecisions.Windows.Forms.CrystalReportViewer crystalReportViewer1 = new CrystalDecisions.Windows.Forms.CrystalReportViewer();  
  30.          this.SuspendLayout();  
  31.       }  
  32.       private void Cry_Report_Load(object sender, EventArgs e)  
  33.       {  
  34.       }  
  35.       private void Cry_Report_Load_1(object sender, EventArgs e)  
  36.       {  
  37.          //reportViewer1.ProcessingMode = ProcessingMode.Local;  
  38.          //reportViewer1.LocalReport.ReportPath = @".\Report1.rdlc";  
  39.          ////Customers dsCustomers = GetData();  
  40.          ////ReportDataSource datasource = new ReportDataSource("Customers", dsCustomers.Tables[0]);  
  41.          //reportViewer1.LocalReport.DataSources.Clear();  
  42.          ////reportViewer1.LocalReport.DataSources.Add(datasource);  
  43.          //this.reportViewer1.RefreshReport();  
  44.       }  
  45.       private void btnshow_Click(object sender, EventArgs e)  
  46.       {  
  47.          try  
  48.          {  
  49.             // string bill_no = "B_00" + txtbillno.Text;  
  50.             DataSet ds = new DataSet();  
  51.                      // con = new OleDbConnection(ConfigurationManager.ConnectionStrings["connect"].ConnectionString);  
  52.             OleDbConnection con = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=ClientMgmtDb1.accdb;");  
  53.             con.Open();  
  54.             OleDbDataAdapter da = new OleDbDataAdapter();  
  55.             if (txtbillno.Text == "")  
  56.             {  
  57.                da = new OleDbDataAdapter("select ID,NAME,AMT,AMC_INC,AMC,AMOUNT_INWORDS,BILL_Number,NARAT,VAT,S_T,VAT_PAY,SERVICE_TAX,VAT_AMT,SERVICETAX_AMT,TOTAL_AMOUNT FROM tbl_ClientDetails where NAME='" + txtbillno.Text.Trim() + "'", con);  
  58.             }  
  59.             else  
  60.                da = new OleDbDataAdapter("select ID,NAME,AMT,AMC_INC,AMC,AMOUNT_INWORDS,BILL_Number,NARAT,VAT,S_T,VAT_PAY,SERVICE_TAX,VAT_AMT,SERVICETAX_AMT,TOTAL_AMOUNT FROM tbl_ClientDetails where BILL_Number='" + txtbillno.Text.Trim() + "'", con);  
  61.                // da = new OleDbDataAdapter("select Bill.Bill_no,Bill.opd_id ,Bill.paitient_name,Bill.SEX,Bill.age,Bill.gurdian_name,Bill.Contact_no,Bill.Date_admission,Bill.Date_Discharge,Bill.Dignosis_dr,Bill.Operation_dr,Bill.Adv_amount,Bill.total_amount,Bill_Details.particular,Bill.address,Bill_Details.value from Bill join Bill_Details on Bill.Bill_no=Bill_Details.Bill_no and Bill.Bill_no='" + bill_no + "'", con);  
  62.                da.Fill(ds, "Dataset1");  
  63.                CrystalReport1 cr = new CrystalReport1();  
  64.                // cr.SetParameterValue("BILL_Number", txtbillno.Text);  
  65.                cr.SetDataSource(ds.Tables[0]);  
  66.                this.crystalReportViewer1.ReportSource = cr;  
  67.                this.crystalReportViewer1.Show();  
  68.                con.Close();  
  69.          }  
  70.          catch (OleDbException s)  
  71.          {  
  72.             MessageBox.Show("Server Problem...");  
  73.          }  
  74.       }  
  75.       private void txtbillno_TextChanged(object sender, EventArgs e)  
  76.       {  
  77.          txtbillno.BackColor = System.Drawing.Color.Aqua;  
  78.       }  
  79.       private void txtbillno_KeyUp(object sender, KeyEventArgs e)  
  80.       {  
  81.       }  
  82.    }