2008-05-10

Create Report

Create report by vb.net and crystal report

1. Create new visual basic project.

2. Add button and CrystalReportViewer to form1.



















3. Add new DataSet item.

4. Add DataTable in dataset design page and add data table columns.
- Title, FirstName, LastName, Address



























5. Add Crystal Report item by select report document as a blank report




































6. On Field Explorer right click at Database Fields and select Database Expert.

7. Select Project Data -> ADO.NET DataSets and add customer table to ReportDataset.




















8. Design Report (Add report header name txtHeader and report footer name txtFooter).






9. Sample code to show report.

Private Sub btnShow_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnShow.Click
' Get data to dataset
Dim CustomerData As DataSet = CreateDataSet()

' Create report instance and set data to report data source
Dim rpt As New CustomerReport
rpt.SetDataSource(CustomerData.Tables(0))

' Access crystal report object
' Sample to access textbox object

Dim txtHeader As CrystalDecisions.CrystalReports.Engine.TextObject = rpt.Section2.ReportObjects("txtHeader")
txtHeader.Text = "This is Report Header"

Dim txtFooter As CrystalDecisions.CrystalReports.Engine.TextObject = rpt.Section2.ReportObjects("txtFooter")
txtFooter.Text = "This is Report Footer"

' Show Report
Me.CrystalReportViewer1.ReportSource = rpt

End Sub

Private Function CreateDataSet() As DataSet
Dim ds As New DataSet("ReportDataset")

' Create Table
Dim dt As New DataTable("Customer")
dt.Columns.Add("Title", Type.GetType("System.String"))
dt.Columns.Add("FirstName", Type.GetType("System.String"))
dt.Columns.Add("LastName", Type.GetType("System.String"))
dt.Columns.Add("Address", Type.GetType("System.String"))

' Add DataTable to DataSet
ds.Tables.Add(dt)

' Create new row
Dim dr As DataRow = ds.Tables(0).NewRow
dr("Title") = "Mr"
dr("FirstName") = "Tom"
dr("LastName") = "Brown"
dr("Address") = "Tom Address"
ds.Tables(0).Rows.Add(dr)

dr = ds.Tables(0).NewRow
dr("Title") = "Mr"
dr("FirstName") = "John"
dr("LastName") = "Grary"
dr("Address") = "John Address"
ds.Tables(0).Rows.Add(dr)

dr = ds.Tables(0).NewRow
dr("Title") = "Mr"
dr("FirstName") = "Alex"
dr("LastName") = "Smith"
dr("Address") = "Alex Address"
ds.Tables(0).Rows.Add(dr)

Return ds
End Function


10. Show Report.




8 comments:

  1. Hi,

    I recently came across your blog and have been reading along. I thought I would leave my first comment. I don't know what to say except that I have enjoyed reading. Nice blog. I will keep visiting this blog very often.

    -
    crystal reports development

    ReplyDelete
  2. Nice starting tutorials for crystal reports. Good work!!

    ReplyDelete
  3. Hi. I try to develop data report with vb.net. but still i can not found good tutorial for it. Do you have idea how to do it. if have plz post here or mail cateringlk@gmail.com

    Tx

    Cater

    ReplyDelete
  4. Casinos near me - MapyRO
    A map showing casinos and other gaming facilities located near 강원도 출장안마 or close to 전주 출장마사지 Casinos, and more nearby, see the location and check for 영천 출장샵 potential Address: 의정부 출장샵 2 Casino St, Largest 창원 출장마사지 Casino City, NV

    ReplyDelete

Thanks for your comment.