Click here to Skip to main content
15,891,204 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
Posted
Comments
Which line? Did you debug?
tharif4me 5-Sep-15 13:39pm    
With objReport
.Load(Application.StartupPath & "\INVOICE.rpt")
.Database.Tables(0).SetDataSource(rptdt)
objClsCrystalRptVw.ReportSource = objReport
objClsCrystalRptVw.Refresh()
End With
What is null here?
tharif4me 5-Sep-15 13:51pm    
.Load(Application.StartupPath & "\INVOICE.rpt")
That means the file path is wrong else the file does not exist.

1 solution

You'll have to debug your code to find where the null is and what is needed to solve it.

http://stackoverflow.com/questions/4660142/what-is-a-nullreferenceexception-and-how-do-i-fix-it[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900