Validating data coming in from Streamreader

FreeriderUK

Well-known member
Joined
Jun 27, 2006
Messages
100
Location
London
Programming Experience
10+
I am importing spreadsheet data using StreamReader.

Is there any way to check the data being imported is valid?

The first column in my spreadsheet is an integer which I need to check against a valid range of numbers before accepting the data - if it's invalid I will use a default value (the first in my range).

I know SourceReader has the .Item(x) property for the row, but what about the field/column or whatever you call it?
 
I found a solution!

I don't know if this will be helpful to anyone, but here's a snippet of the code I used.
(after filling an array with the values I want to check):

VB.NET:
  While sourceReader.Read()

            'for each row from source
            For i As Integer = 0 To sourceReader.FieldCount - 1

                Select Case i
                    Case 0 'First column

                        'Loop through array
                        For z = 0 To MaxItems - 1
                            If CheckArray(z) = sourceReader.GetValue(i) Then
                                CheckIsValid = True
                                Exit For
                            Else
                                CheckIsValid = False
                            End If
                        Next

                End Select
            Next
         
        End While
 
Back
Top