Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #Requieres MySQL Connector NET 8.3.0
- [void][system.reflection.Assembly]::LoadFrom("C:\Program Files (x86)\MySQL\MySQL Connector NET 8.3.0\MySql.Data.dll")
- Function New-updateSQLQuery ($connectionProperties, $CustomerID, $CustomerName) {
- $Connection = New-Object MySql.Data.MySqlClient.MySqlConnection
- $Connection.ConnectionString="server=$($connectionProperties.mysqlHost);uid=$($connectionProperties.mysqlUser);pwd=$($connectionProperties.mysqlPass);database=$($connectionProperties.mysqlDatabase)"
- $Connection.Open()
- $command = New-Object MySql.Data.MySqlClient.MySqlCommand
- $command.Connection = $Connection
- $command.CommandText = "UPDATE Customers SET CustomerName = @CustomerName WHERE CustomerID = @CustomerID"
- $command.Parameters.AddWithValue("@CustomerName", $CustomerName) | Out-Null
- $command.Parameters.AddWithValue("@CustomerID", $CustomerID) | Out-Null
- $command.ExecuteNonQuery() | Out-Null
- $Connection.Close()
- }
- $connectionProperties = New-Object PSObject
- $connectionProperties | Add-Member Noteproperty "mysqlHost" "localhost"
- $connectionProperties | Add-Member Noteproperty "mysqlUser" "myuser"
- $connectionProperties | Add-Member Noteproperty "mysqlPass" "mypswd"
- $connectionProperties | Add-Member Noteproperty "mysqlDatabase" "mydb"
- New-updateSQLQuery $connectionProperties "6" "Combre"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement