powershell execute sql and return a datareader

$strConn="Data Source=.;Initial Catalog=AdventureWorksDW2008R2;Integrated Security=True;"
$conn=New-Object System.Data.SqlClient.SqlConnection
$conn.ConnectionString=$strConn
$conn.Open()

$comm=$conn.CreateCommand()
$comm.CommandText="SELECT TOP 1000 [FullDateAlternateKey],[WeekNumberOfYear],[MonthNumberOfYear],[CalendarYear] FROM [DimDate]"

$dr=$comm.ExecuteReader()

while ($dr.Read())
{
    write-output $dr[0].ToString()
}
posted @ 2011-03-28 22:10  哥本哈士奇(aspnetx)  阅读(465)  评论(0编辑  收藏  举报