Trapping/Handling Constraint Errors

  • Thread starter Thread starter OHM
  • Start date Start date
O

OHM

I know this is not purely a VB.NET question, but I thought I would ask tho !

First create a typed-dataset with an integer ID primary-key field and a
string Name field.
Then create a form with a datagrid and a reference to the dataset on
it. set the grids datasource to dataset1.table1.
If you then enter 1 and Me on the first line, all is OK.
If you enter 1 and Me2on the second line, you get the following error:
"Error when committing the row to the original datastore" - "Column ID is
constrianed to be unique, Value 1 is already present. Do you want to correct
the value? Yes/No.
I would like to put my own message up for the user or do something
else, but I cant seem to find a way to hook into this internally-handled
ADO.NET error.
Any answers would be greatfully received.

Cheers - OHM
 
Hey OHM,

First of all, I would turn off your constraints. This will take care of the
message popping up on you.

After that, I like to attach to the PositionChanged event of the
CurrencyManager when I've gone to the next row. You can also attach to the
RowChanging event of your dataset, but I've had mixed results with that.
Should work with your constraints not being enabled.

From there you can check errors in the row and populate your own error
messages...

Personally, I hate grids, because they after all.. suck...

The other events you could attach to to help out would be the cellchanged
event of your datagrid. I haven't played with this too much but could work.
As the validating event could work...

So with those 3,429 events you *should* be able to accomplish it...

That or you could write your own grid. =)

HTH,
CJ
 
Thanks CJ, I thought someone was going to come back with a reply like that
but was hoping I'd missed something obviously easier.

Thanks again for your reply.

Regards - OHM
 
Nono... It is just a pain in the a$$...

=)


OHM said:
Thanks CJ, I thought someone was going to come back with a reply like that
but was hoping I'd missed something obviously easier.

Thanks again for your reply.

Regards - OHM


dataset
 
Hi OHM

I almost was writting the same as CJ in the ADONET newsgroup, however I
thought would not really help you, and I had to much answers the last time
like that.

And beside that who is the window forms datagrid expert from this newsgroup?

Although Ken and I are learning more and more because you are not
anserwering them at the moment.

:-)

Cor
 
Well Guys, Thanks anyway. It's not because I dont want to asnwer these
questions on the NG, basically I'm so tied up with work at the moment that I
hardly ever have any spare time.

Ive been working for the community in other ways, I'll let you know when the
site goes live and you can see for yourself what i've been doing.

Good to see the work goes on unabated anyway.

Regards - OHM
 
Back
Top