I want to get the id of the last inserted row from mysql, but i get somekind of Exception unhandled. The visual studio gives me this error :
MySql.Data.MySqlClient.MySqlException: 'OUT or INOUT argument 9 for routine test.pr_VendegFelvetele is not a variable or NEW pseudo-variable in BEFORE trigger'.
mysql code:
CREATE PROCEDURE pr_VendegFelvetele(
IN uvezNev VARCHAR(75),
IN ukerNev VARCHAR(75),
IN uemail VARCHAR(255),
IN utel INT(15),
IN ucim VARCHAR(75),
IN uiranyito INT(5),
IN uvaros VARCHAR(55),
IN uorszag VARCHAR(45),
OUT uvendegID INT(11)
)
BEGIN
INSERT INTO `vendeg`(`vezNev`, `kerNev`, `email`, `tel`, `cim`, `iranyito`, `varos`, `orszag`)
VALUES (uvezNev, ukerNev, uemail, utel, ucim, uiranyito, uvaros, uorszag);
SET uvendegID = LAST_INSERT_ID();
END
By the way mysql procedure works perfectly.
c# code:
String query = "CALL pr_VendegFelvetele(@uvezNev, @ukerNev, @uemail, @utel, @ucim, @uiranyito, @uvaros, @uorszag, @uvendegID);";
MySqlCommand cmd = new MySqlCommand(query, Con);
cmd.Parameters.AddWithValue("@uvezNev", uvezNev);
cmd.Parameters["@uvezNev"].Direction = ParameterDirection.Input;
cmd.Parameters.AddWithValue("@ukerNev", ukerNev);
cmd.Parameters["@ukerNev"].Direction = ParameterDirection.Input;
cmd.Parameters.AddWithValue("@uemail", uemail);
cmd.Parameters["@uemail"].Direction = ParameterDirection.Input;
cmd.Parameters.AddWithValue("@utel", utel);
cmd.Parameters["@utel"].Direction = ParameterDirection.Input;
cmd.Parameters.AddWithValue("@ucim", ucim);
cmd.Parameters["@ucim"].Direction = ParameterDirection.Input;
cmd.Parameters.AddWithValue("@uiranyito", uiranyito);
cmd.Parameters["@uiranyito"].Direction = ParameterDirection.Input;
cmd.Parameters.AddWithValue("@uvaros", uvaros);
cmd.Parameters["@uvaros"].Direction = ParameterDirection.Input;
cmd.Parameters.AddWithValue("@uorszag", uorszag);
cmd.Parameters["@uorszag"].Direction = ParameterDirection.Input;
cmd.Parameters.AddWithValue("@uvendegID", MySqlDbType.Int32);
cmd.Parameters["@uvendegID"].Direction = ParameterDirection.Output;
Con.Open();
cmd.ExecuteNonQuery();
MessageBox.Show(cmd.Parameters["@uvendegID"].Value.ToString());
I get it on cmd.ExecuteNonQuery();
I added these lines and now it works.
cmd.CommandText = "pr_VendegFelvetele";
cmd.CommandType = CommandType.StoredProcedure;
This link helped: https://dev.mysql.com/doc/connector-net/en/connector-net-programming-stored-using.html