参数'expression'无法转换为'DBNull'类型

时间:2018-05-02 00:42:29

标签: asp.net vb.net

我有一个vb的应用程序,用于获取Dvg中的已完成的列表,并且有大约17个论坛和本地mssql数据库,并且如果不是则使用dbnull表达式并按下按钮进行一些计算并且答案出现在fourm上的标签中..但是当我通过视觉工作室2017运行这个应用程序时发生了一个奇怪的问题它运行完美并且没有错误..但是当将其转换为exe文件并设置它时,按下此按钮时会出现以下错误“Argument'expression'无法转换为'DBNull'类型 “虽然在使用visual studio运行它时不会出现..问题是什么??

这里是代码,但我不认为它的问题,因为它在visual studio中工作正常 它的长代码,所以我将把它的一部分,其余的重复12个月和10年this is pic of the error

 If Form1.ComboBox1.Text = "2018" Then

            ' total kfalat
            If TextBox1.Text = "1" Then

                Form5.total.Text = Form1.Table1DataGridView.Rows.Count - 1

                Dim HoN As Integer = 0
                ' total done
                For Each gvRow As DataGridViewRow In Form2.TableDataGridView.Rows
                    If Not IsDBNull(gvRow.Cells(13).Value) Then

                        If Val(Me.TextBox2.Text) <= Val(gvRow.Cells(13).Value) AndAlso Val(gvRow.Cells(13).Value) <= Val(Me.TextBox3.Text) Then

                            If Not IsDBNull(gvRow.Cells(1).Value) Then
                                Dim strNgheo As String = gvRow.Cells(1).Value
                                If strNgheo = "1" Then
                                    HoN = HoN + 1
                                End If
                            End If
                        End If
                    End If
                Next
                Form5.done.Text = HoN.ToString
                'undone
                Form5.notdone.Text = Val(Form5.total.Text) - Val(Form5.done.Text)

                'asbab 3adam alta7seel

                'lm yarod

                Dim HoN11 As Integer = 0

                For Each gvRow As DataGridViewRow In Form2.TableDataGridView.Rows
                    If Not IsDBNull(gvRow.Cells(13).Value) Then

                        If Val(Me.TextBox2.Text) <= Val(gvRow.Cells(13).Value) AndAlso Val(gvRow.Cells(13).Value) <= Val(Me.TextBox3.Text) Then

                            If Not IsDBNull(gvRow.Cells(1).Value) Then
                                Dim strNgheo As String = gvRow.Cells(1).Value
                                If strNgheo = "لم يرد" Then
                                    HoN11 = HoN11 + 1
                                End If
                            End If
                        End If
                    End If
                Next
                Form5.Label69.Text = HoN11.ToString

                'lmo2agal

                Dim HoN12 As Integer = 0

                For Each gvRow As DataGridViewRow In Form2.TableDataGridView.Rows
                    If Not IsDBNull(gvRow.Cells(13).Value) Then

                        If Val(Me.TextBox2.Text) <= Val(gvRow.Cells(13).Value) AndAlso Val(gvRow.Cells(13).Value) <= Val(Me.TextBox3.Text) Then

                            If Not IsDBNull(gvRow.Cells(1).Value) Then
                                Dim strNgheo As String = gvRow.Cells(1).Value
                                If strNgheo = "مؤجل" Then
                                    HoN12 = HoN12 + 1
                                End If
                            End If
                        End If
                    End If
                Next
                Form5.Label67.Text = HoN12.ToString

                'سيحضر

                Dim HoN13 As Integer = 0

                For Each gvRow As DataGridViewRow In Form2.TableDataGridView.Rows
                    If Not IsDBNull(gvRow.Cells(13).Value) Then

                        If Val(Me.TextBox2.Text) <= Val(gvRow.Cells(13).Value) AndAlso Val(gvRow.Cells(13).Value) <= Val(Me.TextBox3.Text) Then

                            If Not IsDBNull(gvRow.Cells(1).Value) Then
                                Dim strNgheo As String = gvRow.Cells(1).Value
                                If strNgheo = "سيحضر " Then
                                    HoN13 = HoN13 + 1
                                End If
                            End If
                        End If
                    End If
                Next
                Form5.Label65.Text = HoN13.ToString


                Dim HoN10 As Integer = 0
                Dim money As Integer = 0
                ' astmarat gdeda
                For Each gvRow As DataGridViewRow In Form1.Table1DataGridView.Rows
                    If Not IsDBNull(gvRow.Cells(8).Value) Then

                        If Val(Me.TextBox2.Text) <= Val(gvRow.Cells(8).Value) AndAlso Val(gvRow.Cells(8).Value) <= Val(Me.TextBox3.Text) Then

                            If Not IsDBNull(gvRow.Cells(15).Value) Then
                                'Dim strNgheo As Integer = gvRow.Cells(19).Value
                                ' If strNgheo = (gvRow.Cells(19).Value = True) Then
                                If gvRow.Cells(15).Value > 0 Then

                                    HoN10 = HoN10 + 1
                                    ' ElseIf gvRow.Cells(19).Value = False Then
                                    '    End
                                    money = money + Val(gvRow.Cells(15).Value)

                                End If
                            End If
                        End If
                    End If
                Next
                Form5.Label59.Text = HoN10.ToString

                Form5.Label58.Text = money.ToString


                Dim orphensmoney1 As Integer = 0
                Dim HoN1 As Integer = 0

                Dim familiesmoney1 As Integer = 0
                Dim HoN2 As Integer = 0

                Dim sicksmoney1 As Integer = 0
                Dim HoN3 As Integer = 0

                Dim studentsmoney1 As Integer = 0
                Dim HoN4 As Integer = 0
                ' alkafalat almotwagda belf3l
                For Each gvRow As DataGridViewRow In Form1.Table1DataGridView.Rows

                    If Not IsDBNull(gvRow.Cells(19).Value) Then
                        'Dim strNgheo As Integer = gvRow.Cells(19).Value
                        ' If strNgheo = (gvRow.Cells(19).Value = True) Then
                        If gvRow.Cells(19).Value = True Then

                            HoN1 = HoN1 + 1
                            ' ElseIf gvRow.Cells(19).Value = False Then
                            '    End
                            orphensmoney1 = orphensmoney1 + Val(gvRow.Cells(23).Value)

                        End If
                    End If
                    If Not IsDBNull(gvRow.Cells(20).Value) Then
                        'Dim strNgheo As Integer = gvRow.Cells(19).Value
                        ' If strNgheo = (gvRow.Cells(19).Value = True) Then
                        If gvRow.Cells(20).Value = True Then

                            HoN2 = HoN2 + 1
                            ' ElseIf gvRow.Cells(19).Value = False Then
                            '    End
                            familiesmoney1 = familiesmoney1 + Val(gvRow.Cells(24).Value)

                        End If
                    End If

                    If Not IsDBNull(gvRow.Cells(21).Value) Then
                        'Dim strNgheo As Integer = gvRow.Cells(19).Value
                        ' If strNgheo = (gvRow.Cells(19).Value = True) Then
                        If gvRow.Cells(21).Value = True Then

                            HoN3 = HoN3 + 1
                            ' ElseIf gvRow.Cells(19).Value = False Then
                            '    End
                            sicksmoney1 = sicksmoney1 + Val(gvRow.Cells(25).Value)

                        End If
                    End If

                    If Not IsDBNull(gvRow.Cells(22).Value) Then
                        'Dim strNgheo As Integer = gvRow.Cells(19).Value
                        ' If strNgheo = (gvRow.Cells(19).Value = True) Then
                        If gvRow.Cells(22).Value = True Then

                            HoN4 = HoN4 + 1
                            ' ElseIf gvRow.Cells(19).Value = False Then
                            '    End
                            studentsmoney1 = studentsmoney1 + Val(gvRow.Cells(26).Value)

                        End If
                    End If



                Next
                Form5.Label11.Text = HoN1.ToString
                Form5.Label10.Text = orphensmoney1.ToString
                Form5.Label14.Text = HoN2.ToString
                Form5.Label13.Text = familiesmoney1.ToString
                Form5.Label17.Text = HoN3.ToString
                Form5.Label16.Text = sicksmoney1.ToString
                Form5.Label20.Text = HoN4.ToString
                Form5.Label19.Text = studentsmoney1.ToString

                Form5.Label8.Text = (Val(HoN1) + Val(HoN2) + Val(HoN3) + Val(HoN4)).ToString
                Form5.Label9.Text = (Val(orphensmoney1) + Val(familiesmoney1) + Val(sicksmoney1) + Val(studentsmoney1)).ToString



                Dim HoN5 As Integer = 0
                Dim ORPHENS As Integer = 0
                Dim HoN6 As Integer = 0
                Dim families As Integer = 0
                Dim HoN7 As Integer = 0
                Dim sicks As Integer = 0
                Dim HoN8 As Integer = 0
                Dim students As Integer = 0

                ' almo7asal fe kol band

                For Each gvRow As DataGridViewRow In Form2.TableDataGridView.Rows

                    If Not IsDBNull(gvRow.Cells(13).Value) Then
                        If Val(Me.TextBox2.Text) <= Val(gvRow.Cells(13).Value) AndAlso Val(gvRow.Cells(13).Value) <= Val(Me.TextBox3.Text) Then

                            If Not IsDBNull(gvRow.Cells(14).Value) Then
                                'Dim strNgheo As Integer = gvRow.Cells(19).Value
                                ' If strNgheo = (gvRow.Cells(19).Value = True) Then
                                If gvRow.Cells(14).Value > 0 Then

                                    HoN5 = HoN5 + 1
                                    ' ElseIf gvRow.Cells(19).Value = False Then
                                    '    End
                                    ORPHENS = ORPHENS + Val(gvRow.Cells(14).Value)

                                End If
                            End If

                            If Not IsDBNull(gvRow.Cells(16).Value) Then
                                'Dim strNgheo As Integer = gvRow.Cells(19).Value
                                ' If strNgheo = (gvRow.Cells(19).Value = True) Then
                                If gvRow.Cells(16).Value > 0 Then

                                    HoN6 = HoN6 + 1
                                    ' ElseIf gvRow.Cells(19).Value = False Then
                                    '    End
                                    families = families + Val(gvRow.Cells(16).Value)

                                End If
                            End If

                            If Not IsDBNull(gvRow.Cells(18).Value) Then
                                'Dim strNgheo As Integer = gvRow.Cells(19).Value
                                ' If strNgheo = (gvRow.Cells(19).Value = True) Then
                                If gvRow.Cells(18).Value > 0 Then

                                    HoN7 = HoN7 + 1
                                    ' ElseIf gvRow.Cells(19).Value = False Then
                                    '    End
                                    sicks = sicks + Val(gvRow.Cells(18).Value)

                                End If
                            End If

                            If Not IsDBNull(gvRow.Cells(20).Value) Then
                                'Dim strNgheo As Integer = gvRow.Cells(19).Value
                                ' If strNgheo = (gvRow.Cells(19).Value = True) Then
                                If gvRow.Cells(20).Value > 0 Then

                                    HoN8 = HoN8 + 1
                                    ' ElseIf gvRow.Cells(19).Value = False Then
                                    '    End
                                    students = students + Val(gvRow.Cells(20).Value)

                                End If
                            End If
                        End If


                    End If
                Next

                Form5.Label32.Text = HoN5.ToString
                Form5.Label31.Text = ORPHENS.ToString

                Form5.Label29.Text = HoN6.ToString
                Form5.Label28.Text = families.ToString

                Form5.Label26.Text = HoN7.ToString
                Form5.Label25.Text = sicks.ToString

                Form5.Label23.Text = HoN8.ToString
                Form5.Label22.Text = students.ToString

                Form5.Label35.Text = Val(HoN8.ToString) + Val(HoN7.ToString) + Val(HoN6.ToString) + Val(HoN5.ToString)
                Form5.Label34.Text = Val(ORPHENS.ToString) + Val(families.ToString) + Val(sicks.ToString) + Val(students.ToString)


                Form5.Label53.Text = Val(Form5.Label8.Text) - Val(Form5.Label35.Text)
                Form5.Label52.Text = Val(Form5.Label9.Text) - Val(Form5.Label34.Text)

                Form5.Label50.Text = Val(Form5.Label11.Text) - Val(Form5.Label32.Text)
                Form5.Label49.Text = Val(Form5.Label10.Text) - Val(Form5.Label31.Text)

                Form5.Label47.Text = Val(Form5.Label14.Text) - Val(Form5.Label29.Text)
                Form5.Label46.Text = Val(Form5.Label13.Text) - Val(Form5.Label28.Text)

                Form5.Label44.Text = Val(Form5.Label17.Text) - Val(Form5.Label26.Text)
                Form5.Label43.Text = Val(Form5.Label16.Text) - Val(Form5.Label25.Text)

                Form5.Label41.Text = Val(Form5.Label20.Text) - Val(Form5.Label23.Text)
                Form5.Label40.Text = Val(Form5.Label19.Text) - Val(Form5.Label22.Text)

            End If

0 个答案:

没有答案