View Full Version : MVC get the ID of row just entered
alex57
07-13-2010, 01:52 PM
Hello,
I need to be able to return the ID of the row just inserted. I am using LINQ to do the insert so I don't think SELECT SCOPE_IDENTITY() is available?
Thanks
Freon22
07-13-2010, 03:51 PM
If you showed some code it would be easyer to help. But here is a link that should help
http://forums.silverlight.net/forums/p/23890/85447.aspx
In this thread someone wanted to get the return ID also
MyBDDDataContext db = new MyBDDDataContext();
record newRecord = new record();
newRecord.record_title = newRecordBDD.Title;
newRecord.record_text = newRecordBDD.Text;
newRecord.record_date = DateTime.Now;
db.records.InsertOnSubmit(newRecord);
try
{
db.SubmitChanges();
int id = newRecord.ID; // you can access your newRecord to get the ID
}
catch (Exception)
{
throw;
}
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.