Skip to content

Enhancement: Empty Strings added as DBNULL instead of " " #9

@jakedenyer

Description

@jakedenyer

Warren -

Just noticed this when working with RVTools data from Excel and importing it to a database. Have some empty columns that are adding as empty strings in the DB instead of NULL.

Here is the line I modified to add a DBNULL value instead of an empty string.

                if ($property.GetType().IsArray)
                {
                    $DR.Item($Name) = $Value | ConvertTo-XML -As String -NoTypeInformation -Depth 1
                }
                elseif($Value -eq $null)
                {
                    $DR.Item($Name) = [DBNull]::Value
                }
                else
                {
                    $DR.Item($Name) = $Value
                }

Change to: elseif($Value -eq $null -or $Value -eq "")

                if ($property.GetType().IsArray)
                {
                    $DR.Item($Name) = $Value | ConvertTo-XML -As String -NoTypeInformation -Depth 1
                }
                elseif($Value -eq $null -or $Value -eq "")
                {
                    $DR.Item($Name) = [DBNull]::Value
                }
                else
                {
                    $DR.Item($Name) = $Value
                }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions