using System; using System.Data; using System.Windows.Forms; using CrystalDecisions.CrystalReports.Engine; using CrystalDecisions.Shared; using System.Data.SqlClient; namespace cbc { public partial class Form1 : Form { public Form1() { InitializeComponent(); } ReportDocument rpt = new ReportDocument(); private void Form1_Load(object sender, EventArgs e) { { rpt.Load(@"F:\Project\cbc\cbc\CrystalReport1.rpt"); crystalReportViewer1.ReportSource = rpt; crystalReportViewer1.Refresh(); } } private void btn_refresh_Click(object sender, EventArgs e) { //Begin: Bind the reports dynamically DataTable dtReports = BindReports(); rpt.SetDataSource(dtReports); //End: Bind the reports dynamically //Begin: Update the report label value from All to the entered employee name in the text box TextObject myTextObjectOnReport; if (rpt.ReportDefinition.ReportObjects["emp"] != null)// emp is a database table named.this is error point. { myTextObjectOnReport = (TextObject)rpt.ReportDefinition.ReportObjects["emp"]; myTextObjectOnReport.Text = textBox7.Text; } crystalReportViewer1.ReportSource = rpt; crystalReportViewer1.Refresh(); //End } //Filtered the report details based on the employee name entered in the textbox private DataTable BindReports() { //string conString = @"Data Source =WVDI1IHCL32\WVDI1IHCL32;Initial Catalog=Test;Integrated Security=True;"; SqlConnection con = new SqlConnection("initial catalog=sha;integrated security=yes"); con.Open(); int empid = Convert.ToInt32(textBox7.Text); // string query = "SELECT * FROM emp WHERE id="+empid+" "; SqlDataAdapter sqlAdapter = new SqlDataAdapter("SELECT * FROM emp WHERE id=" + textBox7.Text + " ", con); DataTable dtReport = new DataTable(); sqlAdapter.Fill(dtReport); con.Close(); return dtReport; }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)