Dim dt As DataTable = GetMockData()
For Each row As DataRow In dt.Rows
Console.WriteLine("Int: {0}; Decimal: {1}; String: {2}; DBNull: {3}; DateTime: {4}", _
row.GetValueOrDefault(Of Integer)("Int"), _
row.GetValueOrDefault(Of Decimal)("Decimal"), _
row.GetValueOrDefault(Of String)("String"), _
row.GetValueOrDefault(Of Integer)("DBNull"), _
row.GetValueOrDefault(Of DateTime)("DateTime"))
Public Function GetMockData() As DataTable
Dim dt = New DataTable("TestData")
dt.Columns.Add("Int", GetType(Integer))
dt.Columns.Add("decimal", GetType(decimal))
dt.Columns.Add("String", GetType(String))
dt.Columns.Add("DbNull", GetType(Integer))
dt.Columns.Add("DateTime", GetType(DateTime))
dr("DBNull") = DBNull.Value
dr("DateTime") = DateTime.Now
dr2("DBNull") = DBNull.Value
dr2("DateTime") = DateTime.Now.AddDays(7)
Public Module DataRowExtensions
<System.Runtime.CompilerServices.Extension>
Public Function GetValueOrDefault(Of TExpectedType)(dr As DataRow, propertyName As String) As TExpectedType
If DBNull.Value.Equals(dr(propertyName)) Then
Return DirectCast(dr(propertyName), TExpectedType)