Hi
I am trying to execute SQL code like this:
INSERT INTO test.table1(`Name`, `X`, `Y`, `Geometry`) VALUES('hello4', 0.5, 0.5, NULL );
SET @MyLastID = LAST_INSERT_ID();
in _cmd.ExecuteNonQuery();
_cmd is MySqlCommand with CommandType.Text
@MyLastID - MySqlParameter with Output direction
But I got error on setting output parameter
Is there a way how to implement output parameter value retrieving without stored procedure and without using of DataReader ? (My project architecture requirement)
Thanks
Obtain ID after INSERT in Output CommandType.Text parameter
Re: Obtain ID after INSERT in Output CommandType.Text parameter
MySQL does not support OUT parameters in protocol yet. dotConnect for MySQL allows to handle this situaltion via reader (docs).
As a workaround, try the following code:
As a workaround, try the following code:
Code: Select all
using (MySqlConnection conn = new MySqlConnection("server=db;port=3309;uid=root;pwd=root;database=test;")) {
conn.Open();
MySqlCommand cmd = conn.CreateCommand();
cmd.CommandText = "insert into testtable (field) values ('myvalue'); select LAST_INSERT_ID()";
int i3 = Convert.ToInt32(cmd.ExecuteScalar());
}
Re: Obtain ID after INSERT in Output CommandType.Text parameter
OK
Yesterday I already read this doc, but was not sure it is actual till now.
Because in another doc I saw:
I have already used workaround similar like yours.
But now I am sure this was correct way.
Thanks a lot
Yesterday I already read this doc, but was not sure it is actual till now.
Because in another doc I saw:
http://dev.mysql.com/doc/connector-net/ ... -directionGets or sets a value indicating whether the parameter is input-only, output-only, bidirectional, or a stored procedure return value parameter. As of MySQL version 4.1 and earlier, input-only is the only valid choice.
I have already used workaround similar like yours.
But now I am sure this was correct way.
Thanks a lot
Re: Obtain ID after INSERT in Output CommandType.Text parameter
Ah!
It is another netConnector for MySql!
The document I mentioned relates to another .NET Connector, not by Devart.
This was part of reason of my misunderstanding.
So I use theirs dotNetConnector, not yours.
But anyway your answer is important because if it is really not implemented in protocol, then their connector most probably can't get output parameters too.
Sorry
It is another netConnector for MySql!
The document I mentioned relates to another .NET Connector, not by Devart.
This was part of reason of my misunderstanding.
So I use theirs dotNetConnector, not yours.
But anyway your answer is important because if it is really not implemented in protocol, then their connector most probably can't get output parameters too.
Sorry