Two SQL commands to output two columns in a Data Table?

I’m stuck on this code. I am connecting to a .sdf file and initiating a connection – that all works fine. What isn’t working is the output of my queries to a Data Table. As it is, it only outputs the last query results.

$binpath = "C:Program FilesMicrosoft SQL Server Compact Editionv4.0Desktop"; [Reflection.Assembly]::LoadFile("$binpathSystem.Data.SqlServerCe.dll") $connectionString = "Data Source='$filepath.sdf';" $connection = New-Object "System.Data.SqlServerCe.SqlCeConnection" $connectionString $command = New-Object "System.Data.SqlServerCe.SqlCeCommand" $command.CommandType = [System.Data.CommandType]"Text" $command.Connection = $connection $connection.Open() $command.CommandText = "SELECT TOP 1 WorkOrderName FROM Products as WorkOrder" $command.CommandText = "SELECT SUM(CASE WHEN Name not like '%no%' THEN 1 ELSE 0 END) as Edges FROM Edgebanding" $dt = new-object "System.Data.DataTable" $rdr = $command.ExecuteReader() $dt.Load($rdr) $connection.Close(); $dt | Out-Default | Format-Table 

My results just give me:

Edges ----- 30 

What am I missing?

submitted by /u/Davidjlo
[link] [comments]

Leave a Reply