I am looking for a way to properly exit a while reader.read routine. In my code below I want to add back in the commented out If/End If. If I uncomment these lines the next routine in my program that tries to read from the database gives me an DataReader is already in use error. There are sometimes multiple countries are returned and I only want one of them that matches the Name variable. When that is found I want to exit out of the reader and close it out so I do not get the Reader already in use error.
SQLString = "Select * from CountryList where CountryName LIKE '%" + Name + "%'"
command.CommandText = SQLString
Using rs
rs = command.ExecuteReader()
While rs.Read
DXCCID = rs("DxccID")
CountryName = rs("CountryName")
'If CountryName = Name Then
' rs.Close()
' Exit While
'End If
End While
command.Dispose()
rs = Nothing
End Using
Any help would be appreciated..