0

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 ?

BarisY
  • 171
  • 2
  • 4
  • 14

1 Answers1

0

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();
Ali Adlavaran
  • 3,697
  • 2
  • 23
  • 47
  • I tried and now I can submit , but of course another problem occured. All the passwords in the database changed with encoded ones. – BarisY Jul 09 '15 at 14:36
  • Then update your post and clarify what mean the `All the passwords in the database changed with encoded ones` , Or ask it in other question. – Ali Adlavaran Jul 09 '15 at 15:10