Public Class Test_Class
Public Sub ShowReport(ByVal objClsCrystalRptVw As Object, ByVal StrSql As String, ByVal ReportName As String)
Try
Dim rptda As New SqlDataAdapter
Dim rptds As New DataSet
Dim rptcmd As New SqlCommand
Dim rptdt As DataTable
If con.State = ConnectionState.Open Then con.Close()
con.Open()
rptcmd = New SqlCommand(StrSql, con)
rptda.SelectCommand = rptcmd
rptda.Fill(rptds, "DS")
With rptds
rptdt = rptds.Tables(0)
End With
If rptdt.Rows.Count = 0 Then
EmptyReport = True
MessageBox.Show("Records Not Found For This Criteria", ProjectName, MessageBoxButtons.OK, MessageBoxIcon.Information)
Else
EmptyReport = False
With objReport
.Load(Application.StartupPath & "\INVOICE.rpt")
.Database.Tables(0).SetDataSource(rptdt)
objClsCrystalRptVw.ReportSource = objReport
objClsCrystalRptVw.Refresh()
End With
End If
Catch ex As Exception
MessageBox.Show(ex.Message, ProjectName, MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End Sub
End Class
'THEN MY BUTTON CLICK EVENT
Hide Copy Code
Private Sub BtnPreview_Click(sender As Object, e As EventArgs) Handles BtnPreview.Click
Try
Test_Class.EmptyReport = True
Dim Frm As New frmreport
Dim paramstr As String = "'" & comp_code & "',"
paramstr = paramstr & txtInvNo.Text
Call testclass.ShowReport(Frm.objClsCrystalRptVw, "EXEC INV_SAL_REPORT" & paramstr, "INVOICE.rpt")
If Test_Class.EmptyReport = False Then
Frm.objClsCrystalRptVw.Refresh()
Frm.WindowState = FormWindowState.Maximized
Frm.Text = Me.Text
Frm.Show()
End If
Catch ex As Exception
MessageBox.Show(ex.Message, ProjectName, MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try