0

I have the following table:

ID|Name |FruitOrder                           
1 |Sarah|Apple, Banana, Orange, Peach, Mangoes
2 |John |Apple, Banana                        
3 |Mary |Peach, Mangoes                       
4 |Mark |Mangoes       

I want to take the returned sql table dataset, and append a new column called "note" to the dataset, filling each row with the string "Query1" (for simplicity) :

ID|Name |FruitOrder                            | Note                           
1 |Sarah|Apple, Banana, Orange, Peach, Mangoes | Query1
2 |John |Apple, Banana                         | Query1                        
3 |Mary |Peach, Mangoes                        | Query1                      
4 |Mark |Mangoes                               | Query1

Powershell Code, please see foreach for suggestion.

#powershell code
$SQLDataset = New-Object System.Data.DataSet
$SqlAdapter.fill($SQLDataset) | out-null


foreach ($object in SQLDataset.tables){
# suggestion for logic/code please
}   
2
  • 1
    Do you want to append the dataset in the table or a custom PS object will do? Commented Mar 12, 2019 at 14:42
  • @VivekKumarSingh - I prefer a table. Will need to export to a CSV at the end. Thank you! Commented Mar 12, 2019 at 16:35

1 Answer 1

1

Try this:

$newvalue = $SQLDataset |select -expand tables | select ID,Name,FruitOrder,query

this will add the "query" to the array, so you can then set it in your app.

You could then do a:

$newvalue = $newvalue | %{$_.query = "select * from table";$_}

and have your query on each line.

(and yes, I am sure there are easier or even better ways).

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.