i have problem guys about overload resolution

Overload resolution failed because no Public 'Add' can be called with these arguments:
'Public Function Add(text As String) As System.Windows.Forms.ListViewItem.ListViewSubItem':
Argument matching parameter 'text' cannot convert from 'DBNull' to 'String'.
'Public Function Add(item As System.Windows.Forms.ListViewItem.ListViewSubItem) As System.Windows.Forms.ListViewItem.ListViewSubItem':
Argument matching parameter 'item' cannot convert from 'DBNull' to 'ListViewSubItem'.


this is my code

Public Sub displaydata()
        Dim objdatareader As SqlDataReader
        objdatareader = objCommand.ExecuteReader
        While objdatareader.Read
            Dim listview As New ListViewItem
            With listview
                .Text = objdatareader.Item("IV_Form_ID")
                .SubItems.Add(objdatareader("Date_Started"))
   
            End With

            ListView1.Items.Add(listview)

        End While
    End Sub

i used stored procedure

you could check for NULL before assigning values

Something like this perhaps:

.Text = IIf(IsDBNull(objdatareader.Item("IV_Form_ID")), "<NULL>", objdatareader.Item("IV_Form_ID"))
.SubItems.Add(IIf(IsDBNull(objdatareader.Item("Date_Started")), "<NULL>", objdatareader.Item("Date_Started")))

Of course, you may want to do something else in the "True Part" of the IIF statement, besides passing in the string "<NULL>".

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.