473,398 Members | 2,113 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

Catching ConstraintExceptions on dialogs and allowing the user to keep trying...

If I call EndCurrentEdit on a data linked form which contains data that
breaks a unique constraint, a ConstraintException is thrown as expected.
If I catch that exception and call EndCurrentEdit again, it appears to work
but the row is in fact returned to its original state.
It is as though the second call was actually CancelCurrentEdit.

What is the correct way to handle a ConstraintException such that the user
can change what they've entered and try to commit the record again?

Here is some code to reproduce my problem. Create a form and add a single
TextBox to it.
Place the following code into the Form.Load event.

DataTable table = new DataTable("TABLE");
table.Columns.Add("COLUMN");
table.Constraints.Add("CONSTRAINT", table.Columns[0], false);
table.Rows.Add(new object[] {"first"});
table.Rows.Add(new object[] {"second"});
//binding manager points to the first row which contains "first"
textBox1.DataBindings.Add("Text", table, "COLUMN");
//change it to clash with the second row
textBox1.Text = "second";

try {
this.BindingContext[table].EndCurrentEdit();
Console.WriteLine("success");
}
catch(ConstraintException) {
Console.WriteLine("failed");
}

try {
this.BindingContext[table].EndCurrentEdit();
Console.WriteLine("success");
}
catch(ConstraintException) {
Console.WriteLine("failed");
}
You will notice that it failed the first time and succeeded the second.

Nathan
Nov 16 '05 #1
0 1021

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Steven Reddie | last post by:
In article <slrnbnj19j.av.juergen@monocerus.manannan.org>, Juergen Heinzl wrote: >In article <f93791bd.0309282133.650da850@posting.google.com>, Steven Reddie wrote: >> I understand that access...
2
by: David | last post by:
Hello, I have an application that has been running for years and had little problem with it. We've been retesting the latest code under Windows 2003 and found a surprise. There is a certain...
7
by: cmay | last post by:
FxCop complains every time I catch System.Exception. I don't see the value in trying to catch every possible exception type (or even figuring out what exceptions can be caught) by a given block...
1
by: JimHurst | last post by:
I'm writing a C# win forms application and the customers wish to be able to define at run/install time which language that application runs in. I've manage to set the applications culture, setting...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.