I have the following codes, which I created as extension for datatable in my project. It actually worked. Just wonder if there is any optimization can be made through. Thanks. =)
<Extension()>
Public Function HasNull(ByVal dataTable As DataTable) As Boolean
For Each column As DataColumn In dataTable.Columns
If dataTable.Rows.OfType(Of DataRow)().Any(Function(r) r.IsNull(column)) Then
Return True
End If
Next
Return False
End Function
<Extension()>
Public Function SetDefaultForNull(ByVal dataTable As DataTable) As DataTable
For Each row As DataRow In dataTable.Rows
For Each col As DataColumn In dataTable.Columns
Dim value As Object = row(col)
If IsDBNull(value) Then
Dim dataType As String = col.DataType.ToString
Select Case dataType
Case "System.DateTime"
value = New DateTime
Case "System.Decimal", "System.Int16", "System.Int32", "System.Int64"
value = 0
Case "System.String"
value = String.Empty
Case "System.Boolean"
value = False
Case Else
value = 0
End Select
row(col) = value
End If
Next
Next
Return dataTable
End Function