Click here to Skip to main content
15,890,506 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi Everyone,

I would like to display application form as tabular format for that am using crystal report viewer..Here my issue is in my table I have bulk of data's but when i run my application it shows only 1st row of the table..I would like to display all the records which are present in table..

Here am using C# winforms,visual studio 2010,sql server 2008..

Here is my code:
C#


C#
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;
                    }
                }
            }
        }
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900