Skip to sidebar Skip to content
Ipercube Technical
Jack of all trades, master of none
Date: Time: - Stardate:
Welcome, Log in by clicking  Here!
SS64
MDN
Stack
Code
GitHub
Wiki
Convert
V Studio
  • Home
  • VB Functions
    • Access Functions
    • Assembly Info
    • Color/Image Functions
    • Data Table Functions
    • Email Functions
    • Active Directory Functions
    • LDAP Functions
    • Excel Functions
    • Logging Functions
    • Source Code Retrieval
    • String Functions
    • Sql Functions
    • Object Utilities Functions
    • System and Utilities
    • Utility Forms
  • VB Classes
    • Environment Variables Helper
  • ABAP
    • ABAP Reports
    • ABAP HTTP Functions
Ipercube Technical
  • Home
  • VB Functions
    • Access Functions
    • Assembly Info
    • Color/Image Functions
    • Data Table Functions
    • Email Functions
    • Active Directory Functions
    • LDAP Functions
    • Excel Functions
    • Logging Functions
    • Source Code Retrieval
    • String Functions
    • Sql Functions
    • Object Utilities Functions
    • System and Utilities
    • Utility Forms
  • VB Classes
    • Environment Variables Helper
  • ABAP
    • ABAP Reports
    • ABAP HTTP Functions

Convert Empty Strings To DBNull

Converts all empty or whitespace-only string values in a DataTable to DBNull.

  • Only columns of type String are evaluated
  • Values already set to DBNull are not modified
  • Whitespace-only strings (e.g., spaces or tabs) are also converted to DBNull
VB
    Public Function ConvertEmptyStringsToDBNull(dt As DataTable) As DataTable
    
        For Each row As DataRow In dt.Rows
            For Each col As DataColumn In dt.Columns
                If col.DataType Is GetType(String) Then
                    Dim value As Object = row(col)
                    If value IsNot DBNull.Value AndAlso String.IsNullOrWhiteSpace(value.ToString()) Then
                        row(col) = DBNull.Value
                    End If
                End If
            Next
        Next
        
        Return dt
    End Function
Posted by ipercube


© 2026 Ipercube Design