Source Code and Samples

Wednesday, 14 February 2007

Connect to Sql Server and execute SQL statements

Description

Connect to Sql Server and execute SQL statements

Data Source

$Table = new-object System.Data.DataTable
$sqlConn = new-object System.Data.SqlClient.SqlConnection("Data Source=Server\sqlexpress;Initial Catalog=dbProducts;Integrated Security=True")
$adapter = new-object System.Data.SqlClient.SqlDataAdapter("Select * from Products",$sqlConn)
$adapter.Fill($Table)
write-output $table

1 comment:

joe said...

You could always change

write-output $table
to
$table | Out-GridView

This makes it much easier to read.