Reputation: 63
Dears all,
I'm trying to return the Oracle RowId after an insert but the result is always null (even if the Insert is correct). Why? What's wrong?
Here below you can find the code:
cmd.CommandType = CommandType.Text;
cmd.AddParameter("ROWINSERTED", string.Empty, DBTypes.NVarchar2, ParameterDirection.InputOutput);
cmd.CommandText = $@"INSERT INTO EQUIPVAR(ID_VAR, ID_QU, XTGYREVAVALUE) VALUES(1, 1, 'TEST') RETURNING rowid INTO :ROWINSERTED";
var res = cmd.ExecuteScalar();
I'm waiting the result inside the parameter ROWINSERTED
Thanks in advance.
Upvotes: 0
Views: 302
Reputation: 699
Here's how you can do it with Dapper (nuget package):
DynamicParameters parameters = new DynamicParameters();
parameters.Add("out_id", dbType: DbType.Decimal, direction: ParameterDirection.Output);
database.Execute($@"INSERT INTO EQUIPVAR(ID_VAR, ID_QU, XTGYREVAVALUE) VALUES(1, 1, 'TEST') RETURNING rowid INTO :out_id", parameters);
int id = (int)parameters.Get<decimal>("out_id");
Upvotes: 1