Reputation: 568
Code works fine until I try to add a custom column using:
$datatable.Columns.Add("AD_description1", "String")
If I comment the string I can perfectly see results in GridView. But once the string uncommented the gridview displays:
How do I add a custom field properly?
$adapter = New-Object System.Data.OleDb.OleDbDataAdapter($QueryString, $ConnectionString)
#Load the DataTable
$datatable = New-Object System.Data.DataTable
[void]$adapter.Fill($datatable)
$datatable.Columns.Add("AD_description1", "String")
$datatable | out-gridview
Upvotes: 0
Views: 285
Reputation: 16096
See these results:
$adapter = New-Object System.Data.OleDb.OleDbDataAdapter($QueryString, $ConnectionString)
#Load the DataTable
$datatable = New-Object System.Data.DataTable
[void]$adapter.Fill($datatable)
$datatable.Columns.Add("AD_description1", "String")
$datatable
# Results
<#
AllowDBNull : True
AutoIncrement : False
AutoIncrementSeed : 0
AutoIncrementStep : 1
Caption : AD_description1
ColumnName : AD_description1
Prefix :
DataType : System.String
DateTimeMode : UnspecifiedLocal
DefaultValue :
Expression :
ExtendedProperties : {}
MaxLength : -1
Namespace :
Ordinal : 0
ReadOnly : False
Table : {}
Unique : False
ColumnMapping : Element
Site :
Container :
DesignMode : False
#>
$adapter = New-Object System.Data.OleDb.OleDbDataAdapter($QueryString, $ConnectionString)
#Load the DataTable
$datatable = New-Object System.Data.DataTable
[void]$adapter.Fill($datatable)
$datatable.Columns.Add("AD_description1")
$datatable.Columns.Add("SomeString")
$datatable
# Results
<#
AllowDBNull : True
AutoIncrement : False
AutoIncrementSeed : 0
AutoIncrementStep : 1
Caption : AD_description1
ColumnName : AD_description1
Prefix :
DataType : System.String
DateTimeMode : UnspecifiedLocal
DefaultValue :
Expression :
ExtendedProperties : {}
MaxLength : -1
Namespace :
Ordinal : 0
ReadOnly : False
Table : {}
Unique : False
ColumnMapping : Element
Site :
Container :
DesignMode : False
AllowDBNull : True
AutoIncrement : False
AutoIncrementSeed : 0
AutoIncrementStep : 1
Caption : SomeString
ColumnName : SomeString
Prefix :
DataType : System.String
DateTimeMode : UnspecifiedLocal
DefaultValue :
Expression :
ExtendedProperties : {}
MaxLength : -1
Namespace :
Ordinal : 1
ReadOnly : False
Table : {}
Unique : False
ColumnMapping : Element
Site :
Container :
DesignMode : False
#>
References:
Upvotes: 0