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:

Unknown said...

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

Tariq said...

Nice starting tutorials for crystal reports. Good work!!

cater said...

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

yanmaneee said...

cheap jordans
yeezy 500
nike shox for men
jordan shoes
adidas nmd r1
adidas yeezy
calvin klein underwear
nike air max
yeezy boost 350
lebron 15

backsterejabyn said...

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

Unknown said...

moved here go to my blog her comment is here visit this web-site YOURURL.com Discover More Here

mcneslee said...

k2d27t1i27 k9d78j7v34 s6v96i4y21 n8e63y0o01 a7f51l5f06 i1q31a4b67

Anonymous said...

supreme outlet
kyrie shoes
supreme outlet
yeezy
fear of god essentials hoodie
russell westbrook shoes
bape clothing
yeezy
off white hoodie
golden goose sneakers