using (OdbcConnection con = new OdbcConnection(ConnStr))
using (OdbcCommand cmd = new OdbcCommand("INSERT INTO tblUsers(FirstName, LastName, UserName, Password, EmailId, Created_Date, typeid) VALUES ('" + ObjUserProp.FirstName + "','" + ObjUserProp.LastName + "','" + ObjUserProp.UserName + "','" + ObjUserProp.Password + "','" + ObjUserProp.EmailId + "','" + ObjUserProp.Created_Date + "'," + ObjUserProp.TypeId + ")", con))
{
con.Open();
using (OdbcCommand cmd1 = new OdbcCommand("INSERT INTO tblUsersRelation(UserId,usertypeid) VALUES ( LAST_INSERT_ID() ," + ObjUserProp.TypeId + ")", con))
{
IsDone = cmd.ExecuteNonQuery();
return IsDone;
}
}
记录仅插入到 1 个表中。请告诉我如何获取最新的自增 ID 值。
最佳答案
你最好使用 stored procedures , 在 MySql 中引用的“例程”,并传递输入参数。
关于c# - 在 MySQL 中插入查询后获取自动增量值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7982520/