asp.net - After inserting a new record how to get the primary key -
i using webmatrix design simple form. form uses jquery ui lot. in 1 of modal windows insert new record. table in mysql has primary key in auto increment. after posting new record, used code below if successful:
$.getjson('shared/partials/newuser/' + $("#add-opno").val(), function (data) { var newrecip = data; console.log(newrecip.id); }); when debugged script noticed console value undefined. below newuser script.
@{ response.cache.setcacheability(httpcacheability.nocache); if(urldata[0].isint()){ var db = database.open("sb_cpd"); var sql = "select id cpd_recipients opno ='@0'"; var recipient = db.querysingle(sql,urldata[0]); json.write(recipient, response.output); } }
ok if understood correct, way last inserted id in mysql db (the equivalent of scope_identity() in sql server goes this:
insert table(column1, column2) values (@column1, @column1); select last_insert_id(); of course table needs have auto_increment column.
otherwise can highest value in id column this:
select max(id) cpd_recipients; i hope helps.
Comments
Post a Comment