DataTable to crystal report


  • Hy, i have a problem with populating crystal report. I'm using DataTable and fill it and then pass data to crystal reports. In my DataTable i have all data from my select query, but in crystal report i have all data from database!

    Please help how to solve it!

    Tuesday, March 03, 2009 10:13 AM


  • Hi ivan,

    The problem should be the data in your datatable. The result you got may occur when you get the database data from guide rather than dynamic code from your select query.
    I don't know which database are you using?

    Code Snippet populating crystal report from select query with C# and SQL Server database:
            private void populateCrystalReport()  
                SqlConnection myConnection;  
                DataSet myDataSet;  
                SqlDataAdapter mySQLDataAdapter;  
                CrystalReport1 myReport;  
                string connectionString = "Server=.;Database=xx; User ID=sa;Password=xx";  
                myConnection = new SqlConnection(connectionString);  
                string sqlString = "SELECT A, B, C FROM myTable WHERE A='a'";  
                SqlCommand mySQLCommand;  
                mySQLCommand = new SqlCommand(sqlString, myConnection);  
                mySQLDataAdapter = new SqlDataAdapter(sqlString, myConnection);  
                myDataSet = new DataSet();  
                mySQLDataAdapter.Fill(myDataSet, "Test");  
                myReport = new CrystalReport1();  
                myView.ReportSource = myReport;  
    Other sample project:
    use Crystal Report with SQL Server

    Sample projects when your database is Access:
    Dynamic Crystal Report with C#
    use Crystal Reports with Access database in C#
    Creating Crystal Reports using C# with Datasets

    Sample projects when your database is Oracle:
    Crystal Report with DataSet and DataTable using C#

    Best regards,
    • Marked as answer by Guo Surfer Friday, March 06, 2009 11:44 AM
    Thursday, March 05, 2009 11:12 AM