CREATING CRYSTAL REPORTS VB.NET 2012 STEP BY STEP - PART 2
Creating A New Report
In our part one tutorial, we saw how to prepare create a new VB.NET project which we will use in creating and displaying our crystal reports.
In this part, we will see how to create the Crystal Report inside VB.NET.
1. Under your project name, right-click and select Add then click New Item. Under Reporting, select Crystal Reports. (Remember we started by installing Crystal Reports for VS 2012. If you missed this step, please refer to this tutorial here)
3. In the Crystal Reports Gallery select one of the three options; in our case, we will pick option 2 which is As a Blank Report. So select As a Blank Report. Then under Choose an Expert, select Standard. Finally, click OK button.
4. Back now to your workspace. With the report open(the one you have just added), check to the left and you will see a Field Explorer pane.
Right-click on the database fields as shown below. Then click on the Databse Expert.
5. Since you may wish to distribute your application, click Project Data.
Under ADO.NET Datasets, click on the Dataset you created earlier(in part 1 of this tutorial). Expand the Dataset and select the table(s) you wish to include in your report. Move the selected table to the space on the right as shown in step 3 of the diagram below. Click OK.
Under Database Fields, expand the table you are using in your report and select the fields you wish to use in that report.
7. Drag these fields and place them on the Report's Details area. See diagram below.
8.Create a form to hold the report.
Go to the Toolbox and drag CrystalReportViewer on the form.
9. Place a button on the form and type the following code:
Dim rpt as New myReportName()
Dim Conn as OleDbConnection
Dim newcmd As New OleDbCommand
Dim my DA As New OleDbDataAdapter
Dim myDS As New name of your Dataset
conn=New OleDb.OleDbConnection"Provider=Microsoft.Jet.Oledb.4.0; Data Source=" & Application.StartupPath & "\ClassManager.mdb;jet oledb:Database Password=******")
newcmd=conn.createCommand()
newcmd.commandText="Select from yourTable where field= '" & txtOne.text & "'"
myDA=New OleDbDataAdapter(newcmd)
MyDA.Fill(myDs, "yourtable"
'Show Report Now!!
rpt.SetDataSource(myDS)
CrystalReportViewer1.ReportSource=rpt
conn.close()
newcmd.cancel()
Comments
Post a Comment