I'm still pretty new into Powershell and this has taken way too much time, so HELP! (please)
I have a script that starts out by extracting a value from a SQL Server table. The extract works by populating a "table" via:
$DataSet = New-Object System.Data.DataSet
$SqlAdapter.Fill($DataSet)
Where I run into a problem is getting the single value out of $DataSet
. The value is a date time stamp that I need. Referencing $DataSet.Tables[0]
shows me the date time stamp with a heading of Column1. I've tried all kinds of casting, ToString(), etc. The results are either a display of data types (e.g. System.Data.DataRow
) or any number of errors. How do I get the value into a variable that is recognized as a date time?
TIA,
John
A DataSet in ADO.NET contains multiple tables. What you have is just giving you the first (only) table in your dataset. You need to specify which row and column to return to get a single value. You would have to do something like this if you are looking for a single value:
$value = $DataSet.Tables[0].Rows[0]["Column1"]
Select the appropriate row from the Rows
property and then grab the value by column name:
$row1column1value = $dataset.Tables[0].Rows[0].Column1
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With