- Open Visual Studio 2008
- Create a new project
- Click Project->Add item
- In Reporting tab select Crystal Report
- Select DataSource and column to display
Here my datasource is a XML file and I generated XML file when a button is clicked:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button.Click
Dim myData As New DataSet
Dim cmd As New MySqlCommand
Dim myAdapter As New MySqlDataAdapter
Try
obj.connecttodatabase()
cmd.CommandText = "select mainitemcode as ItemCode,mainitemname as ItemName,mainitemfloor as Location from mainitem"
cmd.Connection = obj.con
myAdapter.SelectCommand = cmd
myAdapter.Fill(myData)
myData.WriteXml("D:\mainitem.xml", XmlWriteMode.WriteSchema)
myData.Clear()
obj.disconnectdatabase()
Catch ex As Exception
MessageBox.Show(ex.Message, "Report could not be created", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End Sub
To view the report add CrystalReportViewer control to a form and place the code:
Imports CrystalDecisions.CrystalReports.Engine
'Place code in any event like form load or click
Dim cryRpt As New ReportDocument
cryRpt.Load(
"D:\CrystalReport1.rpt" )
frmF.CrystalReportViewer1.ReportSource = cryRpt
frmF.CrystalReportViewer1.Refresh()
No comments:
Post a Comment