Monday, April 16, 2012

How to create a crystal report based on a custom SQL statement

Welcome everybody

In this article i will show you how to create a crystal report that based on a custom SQL statement; you have to follow these steps after creating a new project and a sample database :


  1. Add a data set item.
  2. Customize the data set to fit the data that will be retrieved from the database. 
  3. Add a crystal reports item and link it to the previous added data set.
  4. Add a crystal report viewer component to the form which you want to view the report and link it to the previous added crystal report.
  5. Find a way to program a function that returns a data table, and be sure that the columns names and the columns data types in the data table are same as these in the data set .
  6. Bind the data table with the data set, and the crystal report viewer with a report document by using this code
            ReportDocument rpt = new ReportDocument();
            DataSet1 ds = new DataSet1();
            ds.Tables[0].Merge(datattable1);
            rpt.Load(/*CrystalReport1.rpt path*/);
            rpt.SetDataSource(ds);
            crystalReportViewer1.ReportSource = rpt;

note: put the previous code in form load region.

And for more details watch this video

good luck

4 comments:

  1. What a lovely looking you are! I love this

    Crystal Custom

    ReplyDelete

  2. Sun damage may strike at any season, whether it’s summer or winter, so it’s wisest to always wear sunglasses whenever we go out. It makes for an awesome fashion statement too!


    Crystal Custom
    Promotional Sunglasses
    Promo Sunglasses
    Personalized sunglasses
    Customized sunglasses


    ReplyDelete
  3. Imprint your logo and it will be seen reflecting sunlight all day long. But remember, wearing your sunglasses at night is now a growing trend, so you'll get exposure even after the sun has set.

    Promo sunglasses

    ReplyDelete