The backstory is that I want to be able to initialize a blank row on for a DataTable without having to always check for DBNull.Value
. I have an extension method that creates a new blank row and then fills each of the values in the row with the default type for that column.
<Extension()> _
Public Function NewBlankRow(ByVal table As DataTable) As DataRow
Dim row As DataRow = table.NewRow()
For Each col As DataColumn In table.Columns
row(col.ColumnName) = CType(Nothing, col.DataType)
Next
Return row
End Function
I get the following message for the second usage of col (the one within CType
)
Cannot resolve symbol 'col'
For C-Sharper's, Calling CType(Nothing, T)
should be the same as calling Default<T>
Is there a better way to do this? Why can't I access col within CType
?