Error : Conversion from string ?serial? to type 'Integer' is not valid

elianeasmar

Well-known member
Joined
Oct 3, 2013
Messages
76
Programming Experience
Beginner
Hello. I am a little confused.
I have this code:

Dim dv As New DataView(_DataSet.Tables(0))
        ' select deleted rows 
        dv.RowStateFilter = DataViewRowState.Deleted
        For _irow As Long = 0 To dv.Table.Rows.Count - 1
                If Not IsDBNull(dv!serial) Then
                txtSerial.Text = (dv!serial).ToString
                Dim strconnection As String = "Data Source=EASMAR-PC;Initial Catalog=Database Connection;Integrated Security=True;"
                Dim _cn As SqlConnection = New SqlConnection(strconnection)
                _cn.Open()
                Dim cmd As New SqlCommand
                cmd.CommandText = "Delete from tblCustomer where serial= " & (dv!serial).ToString
            End If
        Next


I am getting this error:
Conversion from string ?serial? to type 'Integer' is not valid

on this line:
If Not IsDBNull(dv!serial) Then

serial is an autoincremented integer in my database. So why am i getting this string error conversion?
Is there a logic reason for this?

I tried to replace the previous line by : If Not IsDBNull(dv.Table.PrimaryKey) Then

I tried to replace the previous line by this one:
If Not IsDBNull(dv.Item("Serial")) Then

Still the same error
 
Last edited:
Back
Top