I have a stored procedure with two OUT parameters 'test1' and test2' in MySQL running server 5.6
CREATE PROCEDURE `test_procedure`(OUT test1 varchar(20),OUT test2 int)
BEGIN
SET test1 = 'testing variable 1';
SET test2 = 3;
END
I have ODBC driver 5.3 installed on my computer. I am using the following code to bind the parameters and get the output value:
OdbcCommand cmdTest = new OdbcCommand();
cmdTest.Connection = this.conn;
cmdTest.CommandText = "{call test.test_procedure (?, ?)}";
cmdTest.Parameters.Add(@"test1", OdbcType.VarChar, 20).Direction = ParameterDirection.Output;
cmdTest.Parameters.Add(@"test2", OdbcType.Int).Direction = ParameterDirection.Output;
cmdTest.CommandType = CommandType.StoredProcedure;
using (OdbcDataReader returnRead = cmdTest.ExecuteReader())
{
while (returnRead.Read())
{
//Do something
}
}
string test1 = cmdTest.Parameters[0].Value.ToString();
string test2 = cmdTest.Parameters[1].Value.ToString();
However, the value for strings test1
and test2
in C# code are returned as empty strings. How can I get the values that I set in the stored procedure?
I have also tried ExecuteNonQuery()
but it gives the same result. I know I am connecting to the database since I am able to use SELECT
and INSERT
with ExecuteReader()
.