Outside Computers

Thursday, March 18, 2010

Crystal Reports VB.net how to connect them

In this post, this will show you how to connect these 3 programs namely : VB.net , Crystal Reports XI, first is you can add a crystal report viewer object so that it can browse some crystal report files , then after adding the viewer, you can now set the report source of the viewer either by wizard or by coding it.

the sample code is like this


Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
If ComboBox1.SelectedIndex = 0 Then
Me.Close()
Form2.Show()
Form2.CrystalReportViewer1.ReportSource = Application.StartupPath + "\reports\CrystalReport3.rpt"
Else
Form2.Show()

this code above will set the report source or the report that will be printed on the report viewer depending on what the user selected in the combo box.

Form2.CrystalReportViewer1.SelectionFormula() = "{tblsched.EmpId} = '" & TextBox1.Text & "'"
Form2.CrystalReportViewer1.ReportSource = Application.StartupPath + "\reports\CrystalReport2.rpt"
End If
End Sub

the 2nd quoted code shows what data will be shown depending on the value of the textbox then you can choose what report will be printed by selecting an item in the combo box.


Note: You can add you created reports in the vb.net proj so that it will accept the application.startuppath code, you can place the reports inside the bin directory

if there's some problem in this tutorial just post here your comment or leave a message

enjoy coding!!

No comments:

Post a Comment