title: Pass parameters from powershell to stored procedure
body: <p>I was trying to pass 2 parameters to my stored procedure using powershell.</p>
  
  <p>My code is as below, when I run it in powershell there's no error. However, it doesn't seem the parameters has been passed, because I can't get the correct result. Is there anything wrong on below?</p>
  
  <pre><code>$SqlConnection = New-Object System.Data.SqlClient.SqlConnection
  $SqlConnection.ConnectionString = "Server=localhost;Database=AMSDataWarehouse    Test;Integrated Security=SSPI"
  $SqlCmd = New-Object System.Data.SqlClient.SqlCommand
  $SqlCmd.Connection = $SqlConnection
  $sqlcmd.CommandText = "YQBReport1"
  $param1=$sqlcmd.Parameters.Add("@from" , [System.Data.SqlDbType]::DateTime)
  $param1.Value = "2013-03-13"
  $param2=$sqlcmd.Parameters.Add("@to" , [System.Data.SqlDbType]::DateTime)
  $param2.Value = "2013-03-14"
  $SqlConnection.Open()
  $sqlcmd.ExecuteNonQuery()
  $SqlAdapter = New-Object System.Data.SqlClient.SqlDataAdapter
  $SqlAdapter.SelectCommand = $SqlCmd
  $DataSet = New-Object System.Data.DataSet
  $SqlAdapter.Fill($DataSet)
  $SqlConnection.Close()
  $SQLResult =$DataSet.Tables[0]
  $commands = $SQLResult | foreach-object -process { $_.output }&gt; output.ps1
  .\output.ps1
  </code></pre>
  
  <p>Adding code of YQBReport1</p>
  
  <pre><code>create PROCEDURE YQBreport1 
  AS 
  declare @from datetime, @to datetime, @TypeBigAC char(3)
  select @TypeBigAC='333'
  
  Select 
  '$application = New-Object -ComObject Visio.Application;
  $documents = $application.Documents;
  $document = $documents.Add("AMSGantt.vst");
  $pages = $application.ActiveDocument.Pages;
  $page = $pages.Item(1);
  $shape500 = $page.DrawLine(2,7.9,11,7.9);
  $shape500.TextStyle = "Title";
  $shape500.LineStyle = "Title";'
  as output
  union all
  
  select
  '$shape500.text = '+'"'+'Assignation de Barrières-' +      DATENAME(WEEKDAY,@from)+','+DATENAME(MONTH,@from)+'   '+DATENAME(DAY,@from)+','+DATENAME(YEAR,@from)+'"'+';'
  as output
  Union all
  
  SELECT 
  '$shape'+cast(ROW_NUMBER()OVER(ORDER BY (SELECT 0)) as varchar)+' =     $page.DrawRectangle'+'('+CAST(X1 as varchar)+','+CAST(Y1 as varchar)+','+CAST(X2 as   varchar)+','+CAST(Y2 as varchar)+')'+';'
  +'$shape'+ cast(ROW_NUMBER()OVER(ORDER BY (SELECT 0)) as varchar)+'.'+'LineStyle =    Gantt"'+';'
  +'$shape'+ cast(ROW_NUMBER()OVER(ORDER BY (SELECT 0)) as varchar)+'.'+'TextStyle =      "Gantt"'+case when left(arrival, 2)='AC' THEN 'Red' ELSE '' END+ CASE WHEN LEFT(Departure,      2)='AC' THEN 'Red' ELSE '' END+';'
      +'$shape'+ cast(ROW_NUMBER()OVER(ORDER BY (SELECT 0)) as varchar)+'.FillStyle =        "Gantt'+CASE WHEN CHARINDEX(@TypeBigAC, [ACType Iata])&lt;&gt;0 THEN ' Big AC' ELSE ''        END+'"'+';'
  +'$shape'+ cast(ROW_NUMBER()OVER(ORDER BY (SELECT 0)) as varchar)+'.Text = "'+case when    LEN(arrival)&lt;&gt;0 THEN Arrival ELSE '###' END +' / '+ case when len([ACType Iata])&lt;&gt;0 then    [ACType Iata] else ' ' end +' / '+ CASE WHEN LEN(Departure)&lt;&gt;0 THEN Departure ELSE '###'    END +'"'+';'
  +'$shape'+ cast(100+ROW_NUMBER()OVER(ORDER BY (SELECT 0)) as varchar)+' =   $page.DrawLine('+cast(X1 -0.5 as varchar)+','+cast(Y1 -0.03 as varchar)+','+cast(X1 +0.5 as    varchar)+','+cast(Y1 -0.03 as varchar)+ ')'+';'
  +'$shape'+ cast(100+ROW_NUMBER()OVER(ORDER BY (SELECT 0)) as varchar)+'.Text =    "'+CONVERT(char(5), [Allocation Start Datetime], 108)+'"'+';'
  +'$shape'+ cast(100+ROW_NUMBER()OVER(ORDER BY (SELECT 0)) as varchar)+'.TextStyle =   "Times"'+';'
  +'$shape'+ cast(100+ROW_NUMBER()OVER(ORDER BY (SELECT 0)) as varchar)+'.LineStyle =     "Times"'+';'
  +'$shape'+ cast(200+ROW_NUMBER()OVER(ORDER BY (SELECT 0)) as varchar)+' =    $page.DrawLine('+cast(X2 -0.1 as varchar)+','+cast(Y1 -0.03 as varchar)+','+cast(X2 +0.1 as    varchar)+','+cast(Y1 -0.03 as varchar)+ ')'+';'
  +'$shape'+ cast(200+ROW_NUMBER()OVER(ORDER BY (SELECT 0)) as varchar)+'.Text =    "'+CONVERT(char(5), [Allocation End Datetime], 108)+'"'+';'
  +'$shape'+ cast(200+ROW_NUMBER()OVER(ORDER BY (SELECT 0)) as varchar)+'.TextStyle =    "Times"'+';'
  +'$shape'+ cast(200+ROW_NUMBER()OVER(ORDER BY (SELECT 0)) as varchar)+'.LineStyle =    "Times"'+';'
  
  
  as output
  FROM GanttReport(@from,@to,@TypeBigAC)
  union all
  select '$shape'+ cast(300+ROW_NUMBER()OVER(ORDER BY (SELECT 0)) as varchar)+' =     $page.DrawLine('+cast(X1 as varchar)+','+cast(Y2 as varchar)+','+cast(X2 as     varchar)+','+cast(Y1 as varchar)+ ')'
  from GanttReportTowingLines(@from,@to,@TypeBigAC)
  </code></pre>