Skip to content

Instantly share code, notes, and snippets.

@SQLvariant
Created November 20, 2020 16:12
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SQLvariant/6b5a5a008b5e78d42f926714d1479f2e to your computer and use it in GitHub Desktop.
Save SQLvariant/6b5a5a008b5e78d42f926714d1479f2e to your computer and use it in GitHub Desktop.
Uploaded via PowerShell
$dbName="SAMPLE"
$server="not.my.localhost"
#Define connection string for the database
$cn = new-object system.data.OleDb.OleDbConnection("server=$($server);Provider=IBMDADB2;DSN=$($dbName);trusted_connection=true;");
#Define data set for first query
$ds = new-object "System.Data.DataSet" "ds"
#Define query to run
$q = "select * from hello_world"
# Define data object given the specific query and connection string
$da = new-object "System.Data.OleDb.OleDbDataAdapter" ($q, $cn)
# Fill the data set - essentially run the query.
$da.Fill($ds) | Out-Null
# Print the result
foreach ($Rows in $ds.Tables[0].Rows)
{
$Rows | Format-Table
}
# Close the Connection
$cn.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment