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); |
| |
| myConnection.Open(); |
| mySQLDataAdapter = new SqlDataAdapter(sqlString, myConnection); |
| |
| myDataSet = new DataSet(); |
| mySQLDataAdapter.Fill(myDataSet, "Test"); |
| |
| myReport = new CrystalReport1(); |
| myReport.SetDataSource(myDataSet); |
| myView.ReportSource = myReport; |
| //myReport.Load("~/CrystalReport1.rpt") |
| |
| myConnection.Close(); |
| } |
Other sample project:
use Crystal Report with SQL ServerSample 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 DatasetsSample projects when your database is Oracle:
Crystal Report with DataSet and DataTable using C#Best regards,
Guo