DataTable ConstraintException problem/debugging VB - VS2005

B

Brice Cave

I am loading a Typed Dataset using another dataset via each table's Load() Method and getting a ConstraintException on one of the tables.

Disabling the constraints before the load and Enabling constraints after the load produces the same error.

Leaving the constraints disabled should not be an option. I want to know what is blowing the constraint.

I am loading the data using this method because I want one trip to the database to return multiple resultsets/tables via a stored proc, and I have to use our existing data access layer which does not expose a DataAdapter, just a dataset via method call. I have to use the Load method and pass an DataReader from CreateReader.

Is there ANY way to figure out which of the columns/rows are causeing the ConstraintException ? (Eyeballing rows in the DataTable Visualizer does not count ;) )

1) I have tried trapping in a delegate for FillErrorEventHandler passed to the Load method on the DataTable. This does no good because it seems the constraints are not enforced until after the entire table is loaded with data.

2) I have tried handling the RowChanging Event and looking there, but it is no good becuase of the same reason as statement #1.

3) try/catch does no good because the error message is not verbose. It just says that there was a ConstraintException.

I have tried eyeballing each column's constraints in the Properties window while in the DataSet Designer and the datatable rows thru the visualizer to no avail. Everything 'looks' good (40 rows to search, so might miss something).

I removed any primary keys on the datatable. Still get the error.

Is there any way to list the contraints on a table?

-Brice




EggHeadCafe.com - .NET Developer Portal of Choice
http://www.eggheadcafe.com
 
B

Brice

Well, It turned out that for some reason one of the columns was coming out of the stored procedure as 'Expr1'. (yes, it did have a name on it with an AS clause, but it was the second sql statement in a batch in the proc... weird that brackets around the name fixed that problem)

I caught a clue from other functionality in the code that happened to create a subset of the original data thru a DataView and attempt to create a new datatable via something like:

TypedDataTable = New TypedDataTableType(dv.ToTable())

This actually reported which column was in error for the constraints (very descriptive, I might add) and I was able to troubleshoot from there...

Just FYI...

EggHeadCafe.com - .NET Developer Portal of Choice
http://www.eggheadcafe.com
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top