locked
Error :invalid file path & Object reference not set to an insteance of object RRS feed

  • Question

  • User910710390 posted

    I am trying to convert texts   in report(crystalreport2010) from alignment left to right  in this code(VS2008)

    but show errors  in reportdocument .Reportdefinition.reportObjects(parameter)  

      Private rdoc As New ReportDocument()
        Private ds As New DataSet
        Private Function accrpt() As DataSet
    
    
            Dim cmd As New SqlCommand
            Dim Q As String = "select * from assetsgroup"
            Dim A As New SqlDataAdapter
            Dim CON As New SqlConnection("Data Source=(local);DataBase=crm;User Id=sa;Password=admin@123;")
            With cmd
                .CommandType = CommandType.Text
                .CommandText = Q
                .Connection = CON
            End With
            A.SelectCommand = cmd
            Dim ds As New DataSet
            A.Fill(ds)
            Return ds
    
        End Function
        Private Sub BRL_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BRL.Click
            Try
    
                Dim rdoc As New ReportDocument()
                Dim ds As DataSet
                ds = accrpt()
                ds.WriteXmlSchema("D:\project\LTRCrystal\LTRCrystal\bin\Debug\xml\acr.xml")
                rdoc.Load("D:\project\LTRCrystal\LTRCrystal\bin\Debug\report\rpt.rpt")
                rdoc.SetDataSource(accrpt())
    
                
    
                converttxtobj("FieldHeader1").Text = txtf1.Text
                converttxtobj("FieldHeader2").Text = txtf2.Text
                converttxtobj("FieldHeader3").Text = txtf3.Text
                converttxtobj("FieldHeader4").Text = txtf4.Text
                CrystalReportViewer1.RefreshReport()
                chalign()
    
                CrystalReportViewer1.RightToLeft = Windows.Forms.RightToLeft.Yes
    
                CrystalReportViewer1.ReportSource = rdoc
    
                'CType(rdoc.ReportDefinition.ReportObjects.Item, CrystalDecisions.CrystalReports.Engine.TextObject)
    
            Catch ex As Exception
                MessageBox.Show(ex.Message)
            End Try
        End Sub
        Private Sub chalign()
            Dim rdet As ReportObjects
            Dim fcount As Int16 = 1
            Dim clhdrn As String = ""
    
            For Each rdet In rdoc.ReportDefinition.Sections("DetailsSection").ReportObjects
                clhdrn = "FieldHeader" & fcount.ToString()
                If isnum("Field" & fcount.ToString()) Then
                    getcolhdrobjformat(clhdrn).HorizontalAlignment = Alignment.RightAlign
                Else
                    getcolhdrobjformat(clhdrn).HorizontalAlignment = Alignment.RightAlign
                End If
                fcount = +1
            Next
        End Sub
        Private Function isnum(ByVal fn As String) As Boolean
            Try
                Select Case convertfobj(fn).DataSource.ValueType
                    Case FieldValueType.CurrencyField, _
                         FieldValueType.Int16sField, _
                        FieldValueType.Int16uField, _
                        FieldValueType.Int32sField, _
                        FieldValueType.Int32uField, _
                        FieldValueType.Int8sField, _
                        FieldValueType.Int8uField, _
                        FieldValueType.NumberField
    
                        Return True
                    Case Else
                        Return False
                End Select
            Catch ex As Exception
                MessageBox .Show (ex.Message )
            End Try
           
    
        End Function
        Private Function getcolhdrobjformat(ByVal chdrn As String) As ObjectFormat
            Try
                Return converttxtobj(chdrn).ObjectFormat
            Catch ex As Exception
                MessageBox.Show(ex.Message)
            End Try
    
        End Function
        Private Function converttxtobj(ByVal txtobjn As String) As TextObject
            Try
                Return CType(rdoc.ReportDefinition.ReportObjects(txtobjn), TextObject)---> here errors     
            Catch ex As Exception
                MessageBox.Show(ex.Message)
            End Try
    
        End Function
        Private Function convertfobj(ByVal fobjn As String) As FieldObject
            Try
                Return CType(rdoc.ReportDefinition.ReportObjects(fobjn), FieldObject)
            Catch ex As Exception
                MessageBox.Show(ex.Message)
            End Try
    
        End Function

    how can I do here

    why show me this error

    Please help me

    Friday, June 5, 2015 4:58 PM

Answers

  • User281315223 posted

    Currently you are attempting to access an object from your ReportObjects collection (e.g. rdoc.ReportDefinition.ReportObjects), however I don't see where this is specifically defined at.

    Have you considered using the Visual Studio debugger and placing a breakpoint in this code to take a look at the values of your rdoc, rdoc.ReportDefinition or rdoc.ReportDefinition.ReportObjects objects? If any of these are null, you'll receive your the null reference exception that you are currently encountering. 

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, June 5, 2015 5:16 PM