SQL Select语句Powershell 2.0打印表

时间:2013-06-07 15:22:30

标签: sql-server powershell

我正在尝试使用PowerShell在我的数据库中打印一个人员表。我希望select statment以XML格式返回结果,并将其打印到屏幕上。 ATM我在打印到屏幕时遇到问题。

$conn = New-Object System.Data.SqlClient.SqlConnection

$conn.ConnectionString = "Server=SQLSERVER;Database=myDatabase;user id=usr;password=pss;"
$conn.Open()

$cmd = New-Object System.Data.SqlClient.SqlCommand
$cmd.CommandText = "SELECT TOP 100 * FROM people"

$cmd.connection = $conn
$reader = $cmd.ExecuteXmlReader()

write-output $reader
$conn.close()

$conn.ConnectionString = "Server=SQLSERVER;Database=myDatabase;user id=usr;password=pss;" $conn.Open() $cmd = New-Object System.Data.SqlClient.SqlCommand $cmd.CommandText = "SELECT TOP 100 * FROM people" $cmd.connection = $conn $reader = $cmd.ExecuteXmlReader() write-output $reader $conn.close()

0 个答案:

没有答案