I have the following code:
tb_Job_No.Text is a combobox

This is the code

Public Sub RepCD_process()

        ssql_Job = "SELECT * FROM Rep_Dist"
        ssql_Job = ssql_Job + " WHERE (Job_Number = '" & tb_Job_No.Text & "') "

        Dim Main_Form As New Main_Form
        With Main_Form

            .DA_RepDist.SelectCommand.CommandText = ssql_Job

            If .DS_RepDist1.Rep_Dist.Rows.Count <> 0 Then
                Dim str(9) As String
                Dim listitem As ListViewItem


                X = 0
                    str(0) = .DS_RepDist1.Rep_Dist(X).Rep_No.ToString()
                    ssql_Rep = "SELECT * FROM Rep_List"
                    ssql_Rep = ssql_Rep + " WHERE (Rep_Number = '" & .DS_RepDist1.Rep_Dist(X).Rep_No.ToString & "') "
                    .DA_Rep_List.SelectCommand.CommandText = ssql_Rep
                    str(1) = .DS_Rep_List1.Rep_List(0).Rep_Company_Name.ToString()
                    str(2) = .DS_RepDist1.Rep_Dist(X).item_number.ToString()
                    str(3) = .DS_RepDist1.Rep_Dist(X).Comm_Dist.ToString()
                    str(4) = .DS_RepDist1.Rep_Dist(X).Comm_Amt.ToString()
                    str(5) = .DS_RepDist1.Rep_Dist(X).Comm_Percent.ToString()

                    'If Not (IsDBNull(DataTable.Rows(X).Item("MyValue"))) Then
                    '    myString = DataTable.Rows(X).Item("MyValue")
                    'End If

                    If (IsDBNull(.DS_RepDist1.Rep_Dist(X).Item("Ck_Amt"))) Then
                        str(6) = 0
                        str(6) = .DS_RepDist1.Rep_Dist(X).Item("Ck_Amt")
                    End If
                    If Not (IsDBNull(.DS_RepDist1.Rep_Dist(X).Item("CK_Date"))) Then
                        str(7) = ""
                        str(7) = .DS_RepDist1.Rep_Dist(X).Item("CK_Date")

		 The error I'm getting is" Conversion from type 'DBNull' to type 'String' is not valid.

                    End If
                    If Not (IsDBNull(.DS_RepDist1.Rep_Dist(X).Item("Ck_No"))) Then
                        str(8) = ""
                        str(8) = .DS_RepDist1.Rep_Dist(X).Item("Ck_No")
                    End If
                    'If str(0) = .DS_RepDist1.Rep_Dist(X).Rep_No.ToString Then

                    'str(9) = str(4) - str(6)

                    listitem = New ListViewItem(str)
                    ' End If

                    X += 1
                Loop Until X = .DS_RepDist1.Rep_Dist.Rows.Count

          End If

        End With
        If CBRepName.Text.Count <> 0 Then
            Me.CBRepName.Text = Me.CBRepName.Text(0).ToString()
        End If

    End Sub

Can't seem to get pasted this, when it is remark out all works. Can someone give me a suggestion on how to correct this and get data into the listview?

You could edit the table so it has a default of an empty string instead of null, or use a try/catch method inside a loop, leaving the array item as an empty string for that index, which will work unless you need to distinguish between null and empty string.

This article has been dead for over six months. Start a new discussion instead.