So I have this connection
$connectionString = "Data Source=Something ;Initial Catalog=Something ;Integrated Security=SSPI"
$connection = New-Object -TypeName System.Data.SqlClient.SqlConnection($connectionString)
$query = "select MAX(ID) from [dbo].[Table];"
$command = New-Object -TypeName System.Data.SqlClient.SqlCommand($query, $connection)
$connection.Open()
$NewID = $command.ExecuteScalar()
$connection.Close()
echo $NewID
And it works fine and does the job. Say I want to INSERT A ROW. Do I need the last 3 lines possibly with another method in $command.method()? In which line is the query actually executed?
Question 2: What method should I use if I want to get the whole result set to PowerShell?