Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Constraint confusion
Message
From
02/09/2003 09:13:07
 
 
To
All
General information
Forum:
ASP.NET
Category:
ADO.NET
Title:
Constraint confusion
Miscellaneous
Thread ID:
00825272
Message ID:
00825272
Views:
48
Hi all.

In lurking a thread on constraints between Rick Strahl, John Miller, Bonnie Berent, Kevin McNeish and others, I did a little experimentation, and I'm afraid I've come up with more questions than anwers.

First, to address the issue that Rick originally raised in that thread, I found two ways of suppressing constraints when adding rows to an ADO.NET DataTable.

I created a unique column (by setting the column's Unique property "true"), and tested it to determine that the constraints.count is indeed incremented, and that it will indeed prohibit insertion of a duplicate row.

Next, I used the DataTable.BeginLoadData() method, which turns off the constraint enforcement, used DataTable.LoadDataRow() to load a series of uniqueness-violating DataRow.ItemArrays, then made a call to DataTable.EndLoadData(). In this technique, the unique constraints were indeed suppressed, and by wrapping the EndLoadData() in a try{} block, was able to trap the uniqueness violation.

Note that this same technique works fine with DataTable.Rows.Add(DataRow).

The other technique I discovered is to toggle the EnforceConststraints property of the DataSet from true (the default) to false. Then after loading the new rows, toggling of EnforceConstraints back to true triggers the uniqueness violation error.

I'll start another thread with my other questions <s>
>>-Steve->>

Steve Sawyer
Geeks and Gurus, Inc.
Next
Reply
Map
View

Click here to load this message in the networking platform