hi ,
I have made cystal report by wizard but i want to make it through code i as using vs 2005 can anyone help me

hi ,
I have made cystal report by wizard but i want to make it through code i as using vs 2005 can anyone help me

Here are the steps:

1. Create a Data Source.

Create a public sub-class of DataSet.

namespace dbo {
        public class MyDS : DataSet {
                     // DataTables
                      DataTable dt1;
                      DataTable dt2; 

                    // Method to fetch data & table schema
                    public DataTable getTable(String sql) {
                            ....
                            SqlConnection cn=new SqlConnection("connection string");
                            SqlDataAdapter adp=SqlDataAdapter(sql,cn);
                            DataTable dt=new DataTable();
                            adp.Fill(dt);
                            return dt;
                    }          

                   // Required method - No argument (default) constructor
                   public  MyDS() {
                            dt1=getTable("select * from employees");
                            dt1.TableName="Employees";
                            Tables.Add(dt1);

                           dt2=getTable("select * from Customers");
                           dt2.TableName="Customers";
                           Tables.Add(dt2);

                           .....
                           ....
                   }    
      }
}

2. Design the Crystal Report - use MyDS DataSet as DataSource.

3. Drop - CrystalReportViewer Control and configure the reportsource and DataSet.

Form1_Load(.....) {
           MyDS a=new MyDS();
           // Assume that a Crystal Report file name is repEmp.rpt.
          //  After configure crystalReportViewer  - an object named
          //  repEmp1 will be created.
          repEmp1.SetDataSource(a);
    }

hi ada

thanks fr post ,but plz can u expain this code and can u tell me how to configure report source

hi ada

thanks fr post ,but plz can u expain this code and can u tell me how to configure report source

Can I see your code?

hi ada
i wrote my code in new thread name "dynamic crystal report"

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.