syntax to use near 'xxx= @@IDENTITY'
Posted by:
Name Luo
Date: April 01, 2019 08:19PM
Why output param @Id is replaced by Null ?
My Code:
try
{
string connetStr = "data source=127.0.0.1;database=Test; uid=root;pwd=root;Allow User Variables=True;";
MySqlConnection conn = new MySqlConnection(connetStr);
conn.Open();
string sql =
@"INSERT T_Test_Table
(
Name
)
VALUES
(
@Name -- Name - nvarchar(50)
);
SET @Id = @@IDENTITY";
MySqlCommand cmd = new MySqlCommand(sql, conn);
MySqlParameter mpName = new MySqlParameter("Name", MySqlDbType.VarChar, 50);
mpName.Value = "Tests";
mpName.Direction = ParameterDirection.Input;
MySqlParameter mpId = new MySqlParameter("@Id", MySqlDbType.Int32);
mpId.Direction = ParameterDirection.Output;
cmd.Parameters.Add(mpName);
cmd.Parameters.Add(mpId);
int iRes = cmd.ExecuteNonQuery();
cmd.Parameters.Clear();
conn.Close();
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
throw new Exception("Mysql ExecuteNonQuery Error:\r\n" + ex.Message, ex);
}
Subject
Written By
Posted
syntax to use near 'xxx= @@IDENTITY'
April 01, 2019 08:19PM
February 28, 2020 05:26PM
Sorry, you can't reply to this topic. It has been closed.
Content reproduced on this site is the property of the respective copyright holders.
It is not reviewed in advance by Oracle and does not necessarily represent the opinion
of Oracle or any other party.