Hey
I use your latest components of v6 mySQL dotConnect.
On the server, I have set a unique key, which goes over 5 fields.
When the user enters a duplicate article, then the error is thrown, as expectet.
But my question is: how can I remove this article from the Datacontext, so this input will not be tried again!?
THX
Duplicate Key Entry
-
- Devart Team
- Posts: 1710
- Joined: Thu 03 Dec 2009 10:48
As I can understand, you need to cancel changes made in DataContext so that the next call of SubmitChanges won't fail as well. Am I correct? For this purpose, please use the RejectChanges method:
Here we try to insert a new entity, and if SubmitChanges fails, we call RejectChanges to remove the problem entity from DataContext.
Please tell us if this helps.
Code: Select all
Dept newDept = new Dept() { Deptno = 10, Dname = "New Dept", Loc = "Somewhere" };
dataContext.Depts.InsertOnSubmit(newDept);
try {
dataContext.SubmitChanges();
}
catch(Exception ex)
{
dataContext.RejectChanges();
}
Please tell us if this helps.