Передача данных из таблицы данных в подотчет с помощью Crystal Report - PullRequest
0 голосов
/ 30 августа 2018

У меня проблемы с передачей данных из таблицы данных в подотчет, я всегда получаю ошибку

Object reference not set to an instance of an object. 

Я новичок в Crystal Report и использую vb.Net в Visual Studio 2012. Надеюсь, вы мне поможете, спасибо:)

Private Sub Button4_Click (отправитель как объект, e как EventArgs) Обрабатывает Button4.Click

    Try
        Dim frm As New Printform
        Dim rpt As New mainreport
        Dim dt1 As New DataTable
        Dim dt2 As New DataTable
        Dim dt3 As New DataTable
        Dim dt4 As New DataTable
        Dim dt5 As New DataTable
        With dt1.Columns
            .Add("Date")
            .Add("Attended By")
            .Add("Last name")
            .Add("First name")
            .Add("Initial")
            .Add("Street")
            .Add("City")
            .Add("Zipcode")
            .Add("Dob")
            .Add("Age")
            .Add("Height")
            .Add("Weight")
            .Add("Gender")
            .Add("Status")
            .Add("Number")
            .Add("Type")
        End With
        With dt2.Columns
            .Add("Attended By")
            .Add("Patient")
            .Add("Patient Type")
            .Add("Date")
            .Add("Complaints")
            .Add("Type")
            .Add("Medicine")
            .Add("Quantity")
            .Add("Remarks")
        End With
        With dt3.Columns
            .Add("Attended By")
            .Add("Patient")
            .Add("Type")
            .Add("Date")
            .Add("rep")
            .Add("flo")
            .Add("lun")
            .Add("hea")
            .Add("sys")
            .Add("dia")
            .Add("pul")
            .Add("sit")
            .Add("agi")
            .Add("dig")
            .Add("gen")
            .Add("uri")
            .Add("ski")
            .Add("loc")
            .Add("ner")
            .Add("eye")
            .Add("col")
            .Add("vis")
            .Add("far")
            .Add("fal")
            .Add("ear")
            .Add("hear")
            .Add("nose")
            .Add("thro")
            .Add("rema")
            .Add("reco")
        End With
        With dt4.Columns
            .Add("Attended By")
            .Add("Patient")
            .Add("Type")
            .Add("Date")
            .Add("phy")
            .Add("hea")
            .Add("hig")
            .Add("low")
            .Add("cir")
            .Add("ner")
            .Add("rad")
            .Add("exc")
            .Add("ane")
            .Add("sin")
            .Add("dia")
            .Add("epi")
            .Add("mal")
            .Add("rhe")
            .Add("thy")
            .Add("tub")
            .Add("hep")
            .Add("ven")
            .Add("chi")
            .Add("his")
            .Add("cli")
            .Add("xray")
            .Add("diag")
            .Add("trea")
            .Add("t1")
            .Add("t2")
            .Add("t3")
            .Add("t4")
            .Add("t5")
            .Add("t6")
            .Add("t7")
            .Add("t8")
            .Add("t9")
            .Add("t10")
            .Add("t11")
            .Add("t12")
            .Add("t13")
            .Add("t14")
            .Add("t15")
            .Add("t16")
            .Add("t17")
            .Add("t18")
            .Add("t19")
            .Add("t20")
            .Add("t21")
            .Add("t22")
            .Add("t23")
            .Add("t24")
            .Add("t25")
            .Add("t26")
            .Add("t27")
            .Add("t28")
            .Add("t29")
            .Add("t30")
            .Add("t31")
            .Add("t32")
        End With
        With dt5.Columns
            .Add("name")
            .Add("immu")
            .Add("alle")
            .Add("prob")
        End With
        For i As Integer = 0 To frmviewallrecords.dv1.RowCount - 1
            dt1.Rows.Add(frmviewallrecords.dv1.Rows(i).Cells(0).Value, frmviewallrecords.dv1.Rows(i).Cells(2).Value, frmviewallrecords.dv1.Rows(i).Cells(3).Value, frmviewallrecords.dv1.Rows(i).Cells(4).Value, frmviewallrecords.dv1.Rows(i).Cells(5).Value, _
                       frmviewallrecords.dv1.Rows(i).Cells(6).Value, frmviewallrecords.dv1.Rows(i).Cells(7).Value, frmviewallrecords.dv1.Rows(i).Cells(8).Value, frmviewallrecords.dv1.Rows(i).Cells(9).Value, frmviewallrecords.dv1.Rows(i).Cells(10).Value, _
                       frmviewallrecords.dv1.Rows(i).Cells(11).Value, frmviewallrecords.dv1.Rows(i).Cells(12).Value, frmviewallrecords.dv1.Rows(i).Cells(13).Value, frmviewallrecords.dv1.Rows(i).Cells(14).Value, _
                       frmviewallrecords.dv1.Rows(i).Cells(15).Value, frmviewallrecords.dv1.Rows(i).Cells(16).Value)
        Next
        For i As Integer = 0 To frmviewallrecords.dv2.RowCount - 1
            dt2.Rows.Add(frmviewallrecords.dv2.Rows(i).Cells(2).Value, frmviewallrecords.dv2.Rows(i).Cells(3).Value, frmviewallrecords.dv2.Rows(i).Cells(4).Value, _
                         frmviewallrecords.dv2.Rows(i).Cells(5).Value, frmviewallrecords.dv2.Rows(i).Cells(6).Value, frmviewallrecords.dv2.Rows(i).Cells(7).Value, _
                        frmviewallrecords.dv2.Rows(i).Cells(8).Value, frmviewallrecords.dv2.Rows(i).Cells(9).Value, frmviewallrecords.dv2.Rows(i).Cells(10).Value)
        Next
        For i As Integer = 0 To frmviewallrecords.dv3.RowCount - 1
            dt3.Rows.Add(frmviewallrecords.dv3.Rows(i).Cells(2).Value, frmviewallrecords.dv3.Rows(i).Cells(3).Value, frmviewallrecords.dv3.Rows(i).Cells(4).Value, frmviewallrecords.dv3.Rows(i).Cells(7).Value, frmviewallrecords.dv3.Rows(i).Cells(8).Value, _
                       frmviewallrecords.dv3.Rows(i).Cells(9).Value, frmviewallrecords.dv3.Rows(i).Cells(10).Value, frmviewallrecords.dv3.Rows(i).Cells(11).Value, frmviewallrecords.dv3.Rows(i).Cells(12).Value, frmviewallrecords.dv3.Rows(i).Cells(13).Value, _
                       frmviewallrecords.dv3.Rows(i).Cells(14).Value, frmviewallrecords.dv3.Rows(i).Cells(15).Value, frmviewallrecords.dv3.Rows(i).Cells(16).Value, frmviewallrecords.dv3.Rows(i).Cells(17).Value, frmviewallrecords.dv3.Rows(i).Cells(18).Value, _
                       frmviewallrecords.dv3.Rows(i).Cells(19).Value, frmviewallrecords.dv3.Rows(i).Cells(20).Value, frmviewallrecords.dv3.Rows(i).Cells(21).Value, frmviewallrecords.dv3.Rows(i).Cells(22).Value, frmviewallrecords.dv3.Rows(i).Cells(23).Value, _
                       frmviewallrecords.dv3.Rows(i).Cells(24).Value, frmviewallrecords.dv3.Rows(i).Cells(25).Value, frmviewallrecords.dv3.Rows(i).Cells(26).Value, frmviewallrecords.dv3.Rows(i).Cells(27).Value, frmviewallrecords.dv3.Rows(i).Cells(28).Value, _
                       frmviewallrecords.dv3.Rows(i).Cells(29).Value, frmviewallrecords.dv3.Rows(i).Cells(30).Value, frmviewallrecords.dv3.Rows(i).Cells(31).Value, frmviewallrecords.dv3.Rows(i).Cells(32).Value, frmviewallrecords.dv3.Rows(i).Cells(33).Value)
        Next
        For i As Integer = 0 To frmviewallrecords.dv4.RowCount - 1
            dt4.Rows.Add(frmviewallrecords.dv4.Rows(i).Cells(2).Value, frmviewallrecords.dv4.Rows(i).Cells(3).Value, frmviewallrecords.dv4.Rows(i).Cells(4).Value, frmviewallrecords.dv4.Rows(i).Cells(7).Value, frmviewallrecords.dv4.Rows(i).Cells(8).Value, _
                       frmviewallrecords.dv4.Rows(i).Cells(9).Value, frmviewallrecords.dv4.Rows(i).Cells(10).Value, frmviewallrecords.dv4.Rows(i).Cells(11).Value, frmviewallrecords.dv4.Rows(i).Cells(12).Value, frmviewallrecords.dv4.Rows(i).Cells(13).Value, _
                       frmviewallrecords.dv4.Rows(i).Cells(14).Value, frmviewallrecords.dv4.Rows(i).Cells(15).Value, frmviewallrecords.dv4.Rows(i).Cells(16).Value, frmviewallrecords.dv4.Rows(i).Cells(17).Value, frmviewallrecords.dv4.Rows(i).Cells(18).Value, _
                       frmviewallrecords.dv4.Rows(i).Cells(19).Value, frmviewallrecords.dv4.Rows(i).Cells(20).Value, frmviewallrecords.dv4.Rows(i).Cells(21).Value, frmviewallrecords.dv4.Rows(i).Cells(22).Value, frmviewallrecords.dv4.Rows(i).Cells(23).Value, _
                       frmviewallrecords.dv4.Rows(i).Cells(24).Value, frmviewallrecords.dv4.Rows(i).Cells(25).Value, frmviewallrecords.dv4.Rows(i).Cells(26).Value, frmviewallrecords.dv4.Rows(i).Cells(27).Value, frmviewallrecords.dv4.Rows(i).Cells(28).Value, _
                       frmviewallrecords.dv4.Rows(i).Cells(29).Value, frmviewallrecords.dv4.Rows(i).Cells(30).Value, frmviewallrecords.dv4.Rows(i).Cells(31).Value, frmviewallrecords.dv4.Rows(i).Cells(32).Value, frmviewallrecords.dv4.Rows(i).Cells(33).Value, _
                       frmviewallrecords.dv4.Rows(i).Cells(34).Value, frmviewallrecords.dv4.Rows(i).Cells(35).Value, frmviewallrecords.dv4.Rows(i).Cells(36).Value, frmviewallrecords.dv4.Rows(i).Cells(37).Value, frmviewallrecords.dv4.Rows(i).Cells(38).Value, _
                       frmviewallrecords.dv4.Rows(i).Cells(39).Value, frmviewallrecords.dv4.Rows(i).Cells(40).Value, frmviewallrecords.dv4.Rows(i).Cells(41).Value, frmviewallrecords.dv4.Rows(i).Cells(42).Value, frmviewallrecords.dv4.Rows(i).Cells(43).Value, _
                       frmviewallrecords.dv4.Rows(i).Cells(44).Value, frmviewallrecords.dv4.Rows(i).Cells(45).Value, frmviewallrecords.dv4.Rows(i).Cells(46).Value, frmviewallrecords.dv4.Rows(i).Cells(47).Value, frmviewallrecords.dv4.Rows(i).Cells(48).Value, _
                       frmviewallrecords.dv4.Rows(i).Cells(49).Value, frmviewallrecords.dv4.Rows(i).Cells(50).Value, frmviewallrecords.dv4.Rows(i).Cells(51).Value, frmviewallrecords.dv4.Rows(i).Cells(52).Value, frmviewallrecords.dv4.Rows(i).Cells(53).Value, _
                       frmviewallrecords.dv4.Rows(i).Cells(54).Value, frmviewallrecords.dv4.Rows(i).Cells(55).Value, frmviewallrecords.dv4.Rows(i).Cells(56).Value, frmviewallrecords.dv4.Rows(i).Cells(57).Value, frmviewallrecords.dv4.Rows(i).Cells(58).Value, _
                       frmviewallrecords.dv4.Rows(i).Cells(59).Value, frmviewallrecords.dv4.Rows(i).Cells(60).Value, frmviewallrecords.dv4.Rows(i).Cells(61).Value, frmviewallrecords.dv4.Rows(i).Cells(62).Value, frmviewallrecords.dv4.Rows(i).Cells(63).Value)
        Next
        Dim count As Integer = frmviewallrecords.dv5.RowCount

        If frmviewallrecords.dv6.RowCount > frmviewallrecords.dv5.RowCount Then
            count = frmviewallrecords.dv6.RowCount
            If frmviewallrecords.dv7.RowCount > frmviewallrecords.dv6.RowCount Then
                count = frmviewallrecords.dv7.RowCount
            End If
        ElseIf frmviewallrecords.dv7.RowCount > frmviewallrecords.dv5.RowCount Then
            count = frmviewallrecords.dv7.RowCount
        End If
        For i As Integer = 0 To count - 1
            Dim immu As String
            Dim alle As String
            Dim prob As String
            immu = getImmu(frmviewallrecords.dv5, i)
            alle = getAlle(frmviewallrecords.dv6, i)
            prob = getProb(frmviewallrecords.dv7, i)

            dt5.Rows.Add(frmviewallrecords.Label8.Text, immu, alle, prob)
        Next

        rpt.Subreports.Item("Subreport1").SetDataSource(dt1)--------->Error: Object reference not set to an instance of an object
        rpt.Subreports.Item("Subreport2").SetDataSource(dt2)
        rpt.Subreports.Item("Subreport3").SetDataSource(dt3)
        rpt.Subreports.Item("Subreport4").SetDataSource(dt4)
        rpt.Subreports.Item("Subreport5").SetDataSource(dt5)
        With frm
            frm.CrystalReportViewer1.ReportSource = rpt
            frm.ShowDialog()
        End With
    Catch ex As Exception
        MsgBox(ex.Message)
    End Try

End Sub
...