Executing MySQL User Defined Variables with a .NET MySqlCommand
Executing MySQL user defined variables with a .NET MySqlCommand requires a modification to the connection string. To use user defined variables, the Allow User Variables option must be set to True.
SOLUTION:
To use a MySQL user defined variable in a .NET MySqlCommand, follow these steps:
$connectionstring = "Server=$server;Port=$port;Database=$DataBase;Uid=$User;Pwd=$Password;allow zero datetime=yes;Allow User Variables=True";
EXAMPLE CODE:
$connectionstring = "Server=$server;Port=$port;Database=$DataBase;Uid=$User;Pwd=$Password;allow zero datetime=yes;Allow User Variables=True"; $conn = new-object MySql.Data.MySqlClient.MySqlConnection($connectionstring); $conn.Open(); $sql = "SET @a = 1;SELECT @a;"; $cmd = new-object MySql.Data.MySqlClient.MySqlCommand($sql,$conn); $ds = New-Object system.Data.DataSet; $da = New-Object MySql.Data.MySqlClient.MySqlDataAdapter($cmd); $da.fill($ds); $conn.close(); $ds.tables[0]
Note: This solution has been tested using version 6.3.6.0 of MySql.Data.
The above is the detailed content of How to Execute MySQL User-Defined Variables with a .NET MySqlCommand?. For more information, please follow other related articles on the PHP Chinese website!