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值。在MySQL中插入查詢後獲取自動增量值
當某個記錄的ID大於當前AUTO_INCREMENT號碼時,使用'SELECT MAX(id)'* can *可能會返回錯誤的值。我知道這絕對不是常見的情況,但仍然... –