I'm trying to insert a row from my datagridview to database, which is newly created. First I use ; db.recordTable.InsertOnSubmit();
however it requires db.SubmitChanges();
to make changes permanent. However db.SubmitChanges();
submits all changes on the gridview to database. But I'm encoding password section on the datagridview therefore submit fails. Is there anyway for me to insert only single row without submitting all changes on the datagridview ?
Before submit changes you can track all the changed objects in the DataContext
like this:
MyEntity changedEntityToSubmit; // first you need to know what is the entity you need to submit.
List<object> allChangedEntities = new List<object>(myDataContext.GetChangeSet().Inserts);
allChangedEntities.Remove(changedEntityToSubmit);
myDataContext.Refresh(RefreshMode.OverwriteCurrentValues, allChangedEntities);
Then:
myDataContext.recordTable.InsertOnSubmit(rec);
myDataContext.SubmitChanges();
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.