Understanding Field(Of T) and SetField(Of T)
The Field
generic extension method allows retrieving a strongly typed form for all values from a given column within a table. Field
receives as an argument the column name or the column index and then tries to convert values in a column into the specified type. Because of this, when using Field
you should also predict some exceptions, such as InvalidCastException
that can occur if the conversion fails, NullReferenceException
if Field
attempts to access a non-Nullable
null value, and IndexOutOfRangeException
if you pass an invalid index for the column. The following code retrieves all strongly typed versions of orders’ data:
Private Sub FieldDemo() Try Dim query ...
Get Visual Basic 2015 Unleashed now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.