Marina said:
If there was a constaint violation, why would you want to bother validating
anything else? The constraint check is a type of validation - and it already
caught an error. Who cares if there are other validation problems - one has
already been found that makes the change illegal.
Well, the nice thing to do is keep all the user's hard work in typing
out an entire address record and just inform them that the PK is
wrong/collides with another PK and must be changed.
At the moment, I have a torturous route to follow in that I must find
every occasion that a BindingSource's EndEdit method might be called,
and wrap it in a try/catch block to handle the COnstraintException that
will otherwise cause my app to quit. Once I've caught the exception, I
need to handle it nicely, and I really dont see a way to do that. I can
use string manipulation to pull apart the error message and find which
columns are in error (but i'd have expected a ConstraintException to
have a key/value collection for that) but even if I do, and I find the
columns that are in error, there's nothing I can do with that
information..
The data the user typed seems to exist[at this moment in time] in only
one place: the .Text value of the bound textboxes. If we trace the
route from bound textbox, right the way through to the underlying
datatable, we see that the textbox might be displaying "newvalue" but
its underlying data chain contains "oldvalue" at every other step.
I cant believe that I'm considering extending BindingSource to redefine
the EndEdit method thus:
EndEdit()
try{
base.EndEdit()
} catch(constraintException ex){
//pull erroneous columns out of ex.Message
//crawl back through the bindings to find the controls that the
underlying
// values are bound to
//for all columns not in error, set the underlying values to those
the textboxes
// curretly display
//for columns in error, reset the displayed data in the control to
the underlying value
//show a message to the user that the following columns were found
to be in error
// and they have been reset to defaults, user must pick a different
value
}
All i can say is yuck; I expected more of validation than that. Would
it be easier to set mydataset.EnforceConstraints = false, and implement
RowChanging in all my 98 datatables to do specific validation for each?
Such a move takes time; Have i simply hit the performance/simplicity
wall inherent in every RAD system whereby the basic routine is fine if
youre writing some low-grade app but when it becomes a serious tool you
should do away with the automatic provisions of the IDE and code it all
yourself the hard way?
I had high hopes for VS2005 and I'm finding difficulty in having it
meet them. It's entirely possible that this is because I'm using it in
totally the wrong way, but i feel its actually more likely that its
because I have questions that noone can answer (Which reminds me, I
must check to see if anyone has told me why master BindingSources
destroy their related child's Detached data during an EndEdit - this
makes creating related data very hard, and I feel it's another great
example of something MS got very wrong)
And as David points out, it's very odd design to allow the primary key to be
changed.
I dont know if there's a rule that PKs must always be generated by the
system without user interaction but I have the design for a system
where several tables have compound primary keys that the user must be
instrumental in creating. If this is a design no-no then do let me know
and i'll have the designers work it over. For an accurate description
of why the system is designed thus, please see my response to David.
Thanks for your comments