Matt
Matt

Reputation: 1573

Can get property value by ExpandProperty but not by direct access

I have a System.Data.DataSet object that has been serialized and then deserialized into a PSObject.

I'm trying to access a property that was populated from a column in the table titled Properties.

While Get-Member shows the object has a property named Properties and I can use select -ExpandProperties to get the value, I can't access it directly as a property on the object.

Update: The actual SQL query runs on a server and the results are serialized using Export-CliXml and placed in an accessible share. The results are rehydrated using Import-CliXml which results in an object type prefixed with Deserialized as noted by Mötz below. Explanation of this can be found here.

$> $res.Tables[0] | Get-Member

TypeName: Deserialized.System.Data.DataRow

Name       MemberType Definition
----       ---------- ----------
GetType    Method     type GetType()
ToString   Method     string ToString(), string ToString(string format, System.IFormatProvider formatProvider), string IFormattable.ToString(string format, System.IFormatProvider formatProvider)
Properties Property   System.String {get;set;}

$> $res.Tables[0].Properties
$> $res.Tables[0]."Properties"
$> $res.Tables[0] | select -ExpandProperty "Properties"
<object type= .... > .... </object>

Upvotes: 1

Views: 225

Answers (1)

M&#246;tz
M&#246;tz

Reputation: 1722

We need a little more for us to help you. We don't know what your data source looks like, the table structure and other important details.

I just made a quick sample against one of my databases and things looks a bit different.

$SqlConnection = new-object System.Data.SqlClient.SqlConnection
$SqlConnection.ConnectionString = "data source=.;Initial catalog=db;Trusted_Connection=True;"

$SqlCommand = $SqlConnection.CreateCommand()
$SqlCommand.CommandText = "SELECT * FROM dbo.Table"
$DataAdapter = new-object System.Data.SqlClient.SqlDataAdapter $SqlCommand

$dataset = new-object System.Data.Dataset
$DataAdapter.Fill($dataset)

Your Type says: "Deserialized.System.Data.DataRow" while mine says "System.Data.DataRow".

PS C:\windows\system32> $dataset.Tables[0] | Get-Member


   TypeName: System.Data.DataRow

Name                      MemberType            Definition
----                      ----------            ----------
AcceptChanges             Method                void AcceptChanges()
BeginEdit                 Method                void BeginEdit()
CancelEdit                Method                void CancelEdit()
ClearErrors               Method                void ClearErrors()
Delete                    Method                void Delete()
EndEdit                   Method                void EndEdit()
Equals                    Method                bool Equals(System.Object obj)
GetChildRows              Method                System.Data.DataRow[] GetChildRows(string relationName), System.Data...
GetColumnError            Method                string GetColumnError(int columnIndex), string GetColumnError(string...
GetColumnsInError         Method                System.Data.DataColumn[] GetColumnsInError()
GetHashCode               Method                int GetHashCode()
GetParentRow              Method                System.Data.DataRow GetParentRow(string relationName), System.Data.D...
GetParentRows             Method                System.Data.DataRow[] GetParentRows(string relationName), System.Dat...
GetType                   Method                type GetType()
HasVersion                Method                bool HasVersion(System.Data.DataRowVersion version)
IsNull                    Method                bool IsNull(int columnIndex), bool IsNull(string columnName), bool I...
RejectChanges             Method                void RejectChanges()
SetAdded                  Method                void SetAdded()
SetColumnError            Method                void SetColumnError(int columnIndex, string error), void SetColumnEr...
SetModified               Method                void SetModified()
SetParentRow              Method                void SetParentRow(System.Data.DataRow parentRow), void SetParentRow(...
ToString                  Method                string ToString()
Item                      ParameterizedProperty System.Object Item(int columnIndex) {get;set;}, System.Object Item(s...
ACCOUNTTYPE               Property              int ACCOUNTTYPE {get;set;}
AUTOINFO                  Property              int AUTOINFO {get;set;}
AUTOLOGOFF                Property              int AUTOLOGOFF {get;set;}
AUTOUPDATE                Property              int AUTOUPDATE {get;set;}
CLIENTACCESSLOGLEVEL      Property              int CLIENTACCESSLOGLEVEL {get;set;}
COMPANY                   Property              string COMPANY {get;set;}
COMPILERWARNINGLEVEL      Property              int COMPILERWARNINGLEVEL {get;set;}
CONFIRMDELETE             Property              int CONFIRMDELETE {get;set;}
CONFIRMUPDATE             Property              int CONFIRMUPDATE {get;set;}
CREDENTIALRECID           Property              long CREDENTIALRECID {get;set;}
DEBUGGERPOPUP             Property              int DEBUGGERPOPUP {get;set;}
...                       ...                   ...

So the list of methods that I have available exceeds the your list. That is a first. The next is that all my properties are mapped to a column in my table.

So I would guess that you need to share some more code on how you fill data into your dataset object, for us to understand what you're facing.

Upvotes: 1

Related Questions