We can create crystal report in Visual Basic 6.0. Sometimes we generate the report based on parameter entered by the user and sometimes we generate the report without any input of user. If we need to pass parameter, it is better to create stored procedure. If we don’t need to pass parameter, we can directly display the required data from one or more than one table. We want to create a report, which will display a student’s detail based on the roll number entered by the end-user as a parameter. The procedure to create a report is given below-
In Project Explorer Window, Right Click on Designers --> Add --> Data Environment.
You will get the data environment window with a new connection option listed in it. Right click on the connection name -->properties -->select appropriate provider to connect to database, select “Microsoft OLEDB Provider for SQL Server” in order to connect to SQL Server --> Next -->Select Server Name --> Authentication(user id, password if required) --> select the database from where you want to display the data -->OK.
Then again right click on Connection name and select Add Command submenu.
Right Click on the Command Name -->Properties.
Here we can write the SQL Statement directly or we can select a stored procedure from Database Object drop down list.
We will select the Parameters Tab to check whether the data type of the parameter matches with the data type of the field in database or not. Here in my database the Roll Number has been declared as Varchar so the parameter is adVarChar in report.
Grouping and Aggregate Tabs are necessary in case we need to perform any calculation using group by keyword. Finally we press on OK button.
At this stage, the Data Environment window will look like follows-
Now we will add a Data Report from the Project Explorer by right clicking on the Designer folder.
We need to set 2 directives from the properties of Data Report, i.e. Data Source = DataEnvironment1 and DataMember = Command1.
Then right click on the body of the Data Report and select Retrieve Structure.
Finally we will drag the necessary field from the Data Environment window and drop in Data Report window. Arrange the fields to make better look. We can add some additional fields also to make the report attractive.
In order to pass the Roll Number as a parameter, we can create a simple window like below-
And on click of View Report button, we can write the following code-
Private Sub cmdViewReport_Click () DataEnvironment1.Command1 txtRoll.Text DataReport1.Show End Sub
The Crystal Report of Visual Basic 6.0 is ready to use.
0 comments:
Post a Comment