DBNull Help

Welcome Forums General PowerShell Q&A DBNull Help

This topic contains 0 replies, has 1 voice, and was last updated by  Forums Archives 7 years, 2 months ago.

  • Author
  • #5194

    Points: 0
    Rank: Member

    by sqlspy at 2012-10-12 04:26:53


    I'm getting a DBNull error message when trying to load data into a DataTable object. Can anyone suggest a fix? Many Thanks!

    $os = Get-WmiObject -Class Win32_OperatingSystem -ComputerName $Server

    $table = New-Object system.Data.DataTable “$Server”

    $col01 = New-Object system.Data.DataColumn BootDevice,([string])
    $col02 = New-Object system.Data.DataColumn BuildNumber,([string])
    $col03 = New-Object system.Data.DataColumn PAEEnabled,([Boolean])


    $row = $table.NewRow();

    $row.BootDevice = $os.BootDevice;
    $row.BuildNumber = $os.BuildNumber;
    $row.PAEEnabled = $os.PAEEnabled;

    Exception setting "PAEEnabled": "Cannot set Column 'PAEEnabled' to be null. Please use DBNull instead."
    At C:\Users\kdal321\AppData\Local\Temp\2\2134e5f7-6c9c-47d8-804a-b26a0b1b929c.ps1:19 char:6
    + $row. < <<< PAEEnabled = $os.PAEEnabled;
    + CategoryInfo : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : PropertyAssignmentException

    by JeffH at 2012-10-12 04:49:37

    The problem is most likely that the PAEEnabled property is empty in WMI. You will need to test it first.

    if ($os.PAEEnabled) {
    $row.PAEEnabled = $os.PAEEnabled
    else {
    $row.PAEEnabled = $False

    by sqlspy at 2012-10-12 05:40:57

    Perfect, thanks Jeff.

The topic ‘DBNull Help’ is closed to new replies.

denizli escort samsun escort muğla escort ataşehir escort kuşadası escort