Crystal Reports from SQL Query String
Typically, Crystal Reports are generated based on pre-defined columns. However, it is indeed possible to create Crystal Reports with dynamic columns. In this context, we will demonstrate the process of generating dynamic Crystal Reports using SQL statements. By entering a SQL statement in a designated textbox, the Crystal Reports will be generated based on the provided SQL query.
This approach allows for flexibility and adaptability in generating Crystal Reports, as the user has the ability to customize the report output based on their specific SQL requirements. By using SQL statements, the Crystal Reports can dynamically retrieve and present data from the underlying database, providing a tailored reporting experience.
Implementing dynamic Crystal Reports through SQL statements empowers users to generate reports that align precisely with their data analysis needs, enhancing the versatility and effectiveness of Crystal Reports in capturing and presenting information.
Please note that all the programming samples provided in these tutorials for Crystal Reports are based on the crystaldb database. Prior to starting this tutorial, I highly recommend reviewing the database structure to familiarize yourself with its organization. You can access the database structure by clicking on the following link: Click here to view the Database Structure .
To begin, create a new VB.NET project. Within this project, it is necessary to add a Strongly Typed Dataset. Before proceeding with the creation of the Strongly Typed Dataset, I suggest referring to the detailed tutorial that outlines the process step by step. This tutorial will guide you in create a strongly typed datset and provide valuable insights into its implementation. Additionally, it is recommended to include five columns in the DataTable. However, please note that you have the flexibility to add any number of columns based on your specific requirements.
Next step is to create a Crystal Reports design from the Strongly Typed dataset.
Select all the column from dataset.
Select the default form(Form1.vb) and add a TextBox , Button and Crystal Reports Viewer .
Here we are going to pass the SQl statements to Crystal Reports at runtime . For that we parsing the SQL statement before we passing it to Crystal Reports. So we create a function for parsing SQL statements.
Put the following vb.net source code in your form and run the program .Full Source VB.NET
You have to provide the necessary databse information to Connection String.