.net - sqldatasource insert return identity value -
.net - sqldatasource insert return identity value -
im using sqldatasource sds = new sqldatasource(); in code behind , inserting using sds.insert(); please tell me how inserted record primary key value? please note im not using stored procedure.
last_insert_id();
gives lastly primary key id, can append on end of current insert , key value returned insert.
here c# example:
tring sqlins = "insert table (name, information, other) values (@name, @information, @other)"; db.open(); seek { sqlcommand cmdins = new sqlcommand(sqlins, db.connection); cmdins.parameters.add("@name", info); cmdins.parameters.add("@information", info1); cmdins.parameters.add("@other", info2); cmdins.executenonquery(); cmdins.parameters.clear(); cmdins.commandtext = "select @@identity"; // lastly inserted id. int insertid = convert.toint32( cmdins.executescalar() ); cmdins.dispose(); cmdins = null; } catch(exception ex) { throw new exception(ex.tostring(), ex); } { db.close(); }
i found @ msdn:
http://social.msdn.microsoft.com/forums/en-us/csharpgeneral/thread/91bd10ce-c83b-4766-920b-2137ddc29908
.net insert return sqldatasource
Comments
Post a Comment