I've added some values into my tbl_class using
static DataClassesDataContext db = new DataClassesDataContext();
static tbl_Class _Class = new tbl_Class();
and in my add button:
_Class.ClassName = txtClass.Text;
_Class.Capacity = System.Convert.ToByte(txtCapacity.Text);
_Class.Place = txtPlace.Text;
_Class.TeacherName = txtTeacherName.Text;
_Class.Registered = 0;
_Class.ClassComments = txtDesc.Text;
db.tbl_Classes.InsertOnSubmit(_Class);
db.SubmitChanges();
now I need this last inserted row's id for next step. how do I retrieve it?
I used this code:
var query = (db.tbl_Classes
.OrderByDescending(m => m.classID).Take(1)).ToArray();
to get the last ID but I don't know how to put this id in my int variable. any help would be great.
保存后,请尝试以下操作:
var classID = _Class.classID;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.