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. Basically 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. For example, the following code retrieves all strongly typed versions of orders’ data:
There is also a SetField
method that allows putting ...
Get Visual Basic® 2010 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.