From this post, I will show you how to create a basic Crystal Report. You don't need to have previous knowledge in reporting. Just a little bit knowledge in C# and SQL would be enough.
In SQL Server, I'm creating a database named 'Company' and inside that I have a table named 'Employee'. An employee has an id, a name and a designation. Sample values are added into the Employee table.
In SQL Server, I'm creating a database named 'Company' and inside that I have a table named 'Employee'. An employee has an id, a name and a designation. Sample values are added into the Employee table.
Then in the dialog box, select 'Data' as the Category and from Template, select DataSet. The name for the new data set is given as EmployeeDataSet.xsd in this example. Then click Add.
Then the EmployeeDataSet.xsd file will be opened. If not open it from the Solution Explorer. In the Toolbox, under DataSet, click on the TableAdapter, drag it to the working area and drop it.
Then the Table Adapter Configuration Wizard will be opened.
Click on New Connection. Then give the database details appropriately. In this example, server name is localhost and the database is Company. Then test the connection.
Once the connection is successful, click OK.
Now the connection string is created. Click next in the Table Adapter Configuration Wizard.
In the next window, you can give a name for the connection string. For my convenience, I'll leave the default name. Then click Next.
In the next window, you can specify the SQL query for the table adapter. I'll use the Query Builder to build the query.
In the Add Table window, select the tables you want for the query and click on Add. Then close the window. In this example I'm adding the Employee table.
Then select the columns needed for the query and click Execute Query to view the result. Then click OK.
Now the query is successfully built. Click Next.
Now the table adapter is successfully configured. Click Finish.
Here I'm creating a Standard Report using the Reporting Wizard.
In the wizard, select the data table that you want in the report. Here I'm selecting the Employee table. Then click Next.
Then select the fields to be displayed in the report and click Next.
Next thing is filtering fields. Here I don't need any filtering so I'll click Next.
Next thing is selecting a style for the report. I'll select Standard style and click Finish.
Now the report is created. You can drag the fields and customize the appearance. Add lines and images if you need. I'll just leave it as it is.
Now the designing is over. Now we need to view the report. Get the Windows Form (here Form1). In Tool box, under Reporting menu, click on the Crystal Report Viewer and drag it to the form and drop.
Now run the project and see the output report.
Feel free to put your comments here !
-Tharindu Edirisinghe
-SLIIT 10'