Bhavesh Vankar

Bhavesh Vankar

  • 755
  • 1.2k
  • 89.2k

Crystal Report printing using button by where clause.

Jan 23 2021 9:07 AM
in my practicle i want to print selected record by id or gr name but its not wokring report showing all records not seletcted where is mistakes kindly suggest me right code.
 
  1. protected void btnPrint_Click(object sender, EventArgs e)  
  2.    {  
  3.              SqlConnection con = new SqlConnection(@"Connection string");  
  4.        con.Open();  
  5.        SqlCommand cmd = new SqlCommand("Select * from student_details Where grno Like'" + TextBox1.Text + "' or name like'"+ studentname +"%'",con);  
  6.        SqlDataAdapter sda = new SqlDataAdapter(cmd);  
  7.        DataSet ds = new DataSet();  
  8.        sda.Fill(ds);  
  9.   
  10.        ReportDocument crReport = new ReportDocument();  
  11.        crReport.Load(Server.MapPath("~/StudentsRecord.rpt"));  
  12.        crReport.SetDataSource(ds.Tables["student_details"]);  
  13.   
  14.        CrystalReportViewer1.ReportSource = crReport;  
  15.   
  16.        crReport.ExportToHttpResponse(ExportFormatType.PortableDocFormat,Response, false"Student Records");  
  17.        con.Close();  
  18.    }  
 

Answers (3)