G F
asked on
Require Primary Key ID from row just inserted into Table using Maria DB\MySQL
Hi!
I'm creating a Maria DB project (MySQL) using C#, and I have a need to get the primary key Id from a row I just insert into a table.
I've looked at several solutions on the internet and I'm not having any success. They are either unreliable (documented errors) or do not work with MySql/Maria.
This is my last effort:
MySqlCommand cmd = new MySqlCommand("INSERT INTO bbb.traveldocuments (CustomerID,TDNumber,TDDat eCreated,T DMoveStart ,TDMoveEnd ,TDJobNumb er,TDPermi tType,TDNo tes)" + "VALUES(@CustomerID,@TDNum ber,@TDDat eCreated,@ TDMoveStar t,@TDMoveE nd,@TDJobN umber,@TDP ermitType, @TDNotes); SELECT SCOPE_IDENTITY() ", con);
.
.
.
cmd.Parameters.AddWithValu e("@TDNote s", txtBox_TD_Notes.Text);
cmd.ExecuteNonQuery();
int insertedID = Convert.ToInt32(cmd.Execut eScalar()) ;
When I run the above code I get:
MySql.Data.MySqlClient.MyS qlExceptio n: 'FUNCTION SCOPE_IDENTITY does not exist'
Are there any suggestions I can try?
Thank you in advance.
G
I'm creating a Maria DB project (MySQL) using C#, and I have a need to get the primary key Id from a row I just insert into a table.
I've looked at several solutions on the internet and I'm not having any success. They are either unreliable (documented errors) or do not work with MySql/Maria.
This is my last effort:
MySqlCommand cmd = new MySqlCommand("INSERT INTO bbb.traveldocuments (CustomerID,TDNumber,TDDat
.
.
.
cmd.Parameters.AddWithValu
cmd.ExecuteNonQuery();
int insertedID = Convert.ToInt32(cmd.Execut
When I run the above code I get:
MySql.Data.MySqlClient.MyS
Are there any suggestions I can try?
Thank you in advance.
G
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
You're welcome :)
ASKER
G