SqlDataReader
has never had a ToArray
method. ToArray
is generally an extension method on IEnumerable<T>
that converts a set of items to an array. A data reader is a forward, readonly enumeration of records.
The original code was using LINQ. The result of that LINQ query (aka matches
) is IEnumerable<string>
which is then converted to a string array. Your new code is executing a reader and getting the reader back but it never enumerates the results. You are missing code to get this to work.
Dim matches As New List(Of String)
Using reader As SqlDataReader = addresscmd.ExecuteReader()
While (reader.Read())
Dim address As String = reader.GetFieldValue(Of String)("currentAddress")
matches.Add(address)
End While
Return matches.ToArray()
End Using
Note that this is quite a bit extra code over the LINQ version. I don't personally find it easier to read or maintain but if that is really what you want then you are responsible for allocating and cleaning up the reader, parsing the resultset manually and picking out the column(s) you care about.