[DB Last ID] Sample Of How To Get Lastest Inserted ID

Mar 5, 2013 at 9:34 AM
Edited Mar 5, 2013 at 9:35 AM
File GBMS->Request_BLL.cs
 string strsql = "Insert into bgm_request (bgm_year, bgm_req_date, bgm_req_name, bgm_strat_list_seq, job_site_seq"
+ ", prj_type_seq, bgm_req_scope, bgm_req_reason, bgm_req_object, bgm_req_plan, bgm_req_target"
+ ", bgm_req_remark, date_start, date_end, record_status, created_by, created_when, job_site_seq_main)"
+ " values(@bgm_year, @bgm_req_date, @bgm_req_name, @bgm_strat_list_seq, @job_site_seq"
+ ", @prj_type_seq, @bgm_req_scope, @bgm_req_reason, @bgm_req_object, @bgm_req_plan, @bgm_req_target"
+ ", @bgm_req_remark, @date_start, @date_end, @record_status, @created_by, @created_when, @job_site_seq_main)";
                dbManager.ExecuteNonQuery(CommandType.Text, strsql);

                string strsqlLast_insert = "select distinct last_insert_id() FROM bgm_request";
                DataSet ds = new DataSet();
                ds = dbManager.ExecuteDataSet(CommandType.Text, strsqlLast_insert);
                return Convert.ToInt32(ds.Tables[0].Rows[0][0]);