#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Function GetSqlDAtaSet
#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
# usage: #
#-=-=-=-=-=
# $myinfo = Getsqldataset $sqlquery "servername\instance,port" database_name
# $myinfo = Getsqldataset $sqlquery "server1\test" database1
#
{
Param($sql,
$server=".",
$SQLdb)
$sqlConnection = new-object System.Data.SqlClient.SqlConnection "Server = $server;Database=$SQLdb;Integrated Security=True"
$return_value = $sqlConnection.Open()
$sqlCommand = New-object system.data.sqlclient.SqlCommand
$sqlCommand.CommandTimeout = 30
$sqlCommand.Connection = $sqlConnection
$sqlCommand.CommandText = $sql
$sqlDataAdapter = new-object System.Data.SqlClient.SQLDataAdapter($sqlCommand)
$sqlDataSet = new-object System.Data.dataset
$sqlDataAdapter.fill($sqlDataSet) # move data into dataset
$mydata = $sqlDataSet.tables[0].select()
$sqlconnection.close() # close connection
return $mydata # return object
}
|