Public Sub ReplaceNulls(ByVal TheRow As Data.DataRow)
'Replace any row items containg null data with the default data for this item's data type.
For I As Integer = 0 To TheRow.Table.Columns.Count - 1
Dim TableColumn As Data.DataColumn = TheRow.Table.Columns(I)
Dim ColumnType As Type = TableColumn.DataType
If TheRow.Item(I) Is DBNull.Value Then
If ColumnType.FullName = "System.String" Then
TheRow.Item(I) = ""
Else
TheRow.Item(I) = Activator.CreateInstance(ColumnType)
End If
End If
Next I
End Sub
Tips and tricks for .NET using ASP and VB code.
Replace any nulls in a DataRow with default data.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment