1
votes

I'm creating a windows form application, and I need to create a crystal report without database.

I know how to create a dataset and a datatable, but I dont know how to fill this datatable or clear it, and I dont know how to display that crystal report on click on a button in my form.

I have 3 variables : id, firstname, lastname I want to add these 3 variables values to my datatable of 3 columns to display them in crystal report.

I'm totaly new to crystal report! Any Help Please...

1

1 Answers

1
votes

Not sure what you are asking.

            my_rpt objRpt;
            // Creating object of our report.
            objRpt = new my_rpt();

            DataSet ds = new DataSet("MyDataSet");

            DataTable dt = new DataTable("MyDataTable");
            ds.Tables.Add(dt);


            dt.Columns.Add("id", typeof(int));
            dt.Columns.Add("firstname", typeof(string));
            dt.Columns.Add("lastname", typeof(string));

            dt.Rows.Add(new object[] { 1,"John", "Smith"});
            dt.Rows.Add(new object[] { 2, "Mary", "Jones" });
            dt.Rows.Add(new object[] { 3, "Harry", "James" });

            // Setting data source of our report object
            objRpt.SetDataSource(ds);

            CrystalDecisions.CrystalReports.Engine.TextObject root;
            root = (CrystalDecisions.CrystalReports.Engine.TextObject)
                 objRpt.ReportDefinition.ReportObjects["txt_header"];
            root.Text = "Sample Report By Using Data Table!!";

            // Binding the crystalReportViewer with our report object. 
            crystalReportViewer1.ReportSource = objRpt;