private void Report_Load(object sender, EventArgs e) { ReportDocument crystalreport = new ReportDocument(); crystalreport.Load(@"D:\Development\VS2010 Projects\MVC Applications\Application_Print_CrystalReports\Application_Print_CrystalReports\leavereport.rpt"); //Here am writing query to display all the records which are present in the table Customers dscustomers = GetData("Select * From Leave_Form"); crystalreport.SetDataSource(dscustomers); crystalReportViewer1.ReportSource = crystalreport; crystalReportViewer1.Refresh(); crystalReportViewer1.Dock = DockStyle.Fill; this.Controls.Add(crystalReportViewer1); } //Here customers is my dataset name private Customers GetData(string query) { string conString = ConfigurationManager.ConnectionStrings["Myconn"].ConnectionString; SqlCommand cmd = new SqlCommand(query); using (SqlConnection con = new SqlConnection(conString)) { using (SqlDataAdapter sda = new SqlDataAdapter()) { cmd.Connection = con; con.Open(); sda.SelectCommand = cmd; using (Customers dscustomers = new Customers()) { sda.Fill(dscustomers, "DataTable1"); return dscustomers; } } } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)