Created
November 20, 2020 16:12
-
-
Save SQLvariant/6b5a5a008b5e78d42f926714d1479f2e to your computer and use it in GitHub Desktop.
Uploaded via PowerShell
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$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