locked
crystal report RRS feed

  • Question

  • User1692181589 posted

    Hello

              I have build datatable base on the query. I want to show  that on report.

    I want to know when I want to show datatable data on gridview I do as follows..

    grdview.datasource = dt;
    grdview.databind();

    CAN I DO THIS IN CRYSTAL REPORT WITH OUT DESIGN  REPORT.I mean drag fields in crystal report...

    string sql =  "select * from product"; 
               
    using (MySqlConnection conn = new MySqlConnection(connStr)) 
               
    { 
                   
    using (MySqlCommand cmnd = new MySqlCommand(sql, conn)) 
                   
    { 
                        conn
    .Open(); 
                       
    using (MySqlDataAdapter da = new MySqlDataAdapter(cmnd)) 
                       
    { 
                            dt
    = new DataTable("tb1"); 
                            da
    .Fill(dt); 
                       
    } 
                   
    } 
               
    } 
               
    ReportDocument doc = new ReportDocument(); 
               
    string reportpath = Server.MapPath("Reports/Offrltr.rpt");  // report with no field in it
                doc
    .Load(reportpath); 
                doc
    .SetDataSource(dt); 
               
    CrystalReportViewer1.ReportSource = doc;

     

    Tuesday, March 6, 2012 10:50 AM

Answers

All replies

  • User-236691393 posted

    No, you need to desgin the report first using the fields that you have in the database or DATASET/DATATABLE.

    Crystal report is not like GRid that it automatically populate your data without any design.

    Open crystal and create a connection to datatable and it will show you all the fields and you need to then drag and drop the fields in the way you want the report to show up.

    http://www.codeproject.com/Articles/12694/Creating-Crystal-Reports-using-C-with-Datasets

    Tuesday, March 6, 2012 11:45 AM
  • User1692181589 posted

    Hello

                  Thanks for response. But what if I am creating datatable at codebedind .like my datalayer funcation return me datatable so how can i create a connection to datatable at crystal report.

    Tuesday, March 6, 2012 2:08 PM
  • User-236691393 posted

    Crystal reports accepts either database fields or dataset fields as way to understand/populate the fields to design.

    If I were you, 

    I would add a dataset in the project and and drag all the tables I am getting data from and design the report.

    When coding behind, Crystal reports need that dataset or just datatable with all data in it

     adapter.Fill(Ds, "my_dt");//Like this MY_DT IS DATATABLE
    Practice some examples

    http://www.codeproject.com/Articles/28899/Crystal-Report-with-DataSet-and-DataTable-using-C

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, March 6, 2012 2:41 PM
  • User1692181589 posted

    hello

                thanks for reply... so you are saying that create XSD file, drag datatable on to it and and design report using datatable....

    but boos how can i fill "my_dt." with custom query

    Tuesday, March 6, 2012 2:55 PM
  • User-236691393 posted

    YES,

    After crystal design is done. You are now at start of pulling data out of database using code.

    CODE BEHIND for datatable/dataset would be the regular process of creating connection,Query, pulling data out and then giving it to crystal reports.

    Did you look at the sample ?

    http://www.codeproject.com/Articles/28899/Crystal-Report-with-DataSet-and-DataTable-using-C

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, March 6, 2012 3:11 PM