views:

326

answers:

2

Hello. Im working with dataSets validation in my project. I'm doing validation when DataTable_ColumnChanged event fires in partial class of dataTable, and its doing its job, but i would like to also validate datatype mismach on dataSet level, not UI, to provide custom error message. If [someID] expects number, but someone enters string in textbox for instance.

The problem is, dataSet is handling that type of error somewhere before DataTable_ColumnChanged event fires, and never change column, I understand that.

So the question is where and how to intercept it. I want to handle that in partial dataTable class, wrap into a property or something, but VS generated bunch of code and i dont know where to look :) Thanks.

A: 

ColumnChanging event?\

Dataset events

Spence
I tried before, it doesnt fire. :(
Wally
Well give us some code then. Dataset WILL fire a ColumnChanged event on a dataset, IF the dataset is asked to do this. My hunch is that it's being intercepted in your UI, OR its being intercepted on a new row. Can you show us the code that your using to change the values with. We can troubleshoot from there
Spence
Well, it is column is bound to textbox via XAML. I would't like logic for dataType in UI.Text="{Binding Path=Naziv, UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=True}"
Wally
To be honest I did what you wanted to do on a previous project and it was very very difficult to write the code. What happened is you end up implementing a RDBMS in memory in your dataset. Sometimes it's better to catch stupid stuff in the GUI, or provide a "validation" function on a row but let the database tell you when things are wrong.
Spence
Thanks for your answer. I'm still learning this stuff, and i find biggest question "What to learn and in what situation to use?". I started to realise there is no silver bullet :). Everywhere there are compromises to be made. Time involved vs flexibility.
Wally
A: 

This isn't exactly an answer to your question, but when you mentioned that VS is creating a bunch of goo it made me think that you are probably using drag/drop functionality to accomplish this task. This is partially why, as you already pointed out, you can't figure out what's going on.

This codegen by studio is making it more complicated for you. If I'd suggest considering removing this autogenerated dataset and creating your own typed data set to replace it if you are early on in your project. If you are in the position where you can make this change to a more sane typed dataset it will help position you to not get into situations like you are in now.

Moreover, if you have the time, you might consider a design that doesn't use datasets at all, but that is certainly much more to take on. Most folks are using an ORM solution such as NHibernate or something similiar to do the kinds of things we used to use DataSets for. Obviously, if there are time or external factors that make it so you must use DataSets, then forget this ORM consideration--but do think about removing the autogenerated dataset and making a typed dataset instead. It will be much easier on you.

Kevin Won
Yes, that is true, I use VS drag and drop functionality. Makes it so easy :).Right now I am in the process of learning doing things, but i would like to do it the right way.I guess I'll take the option for manualy typing datasets.I needed this kind of answer i guess, thanks alot. :)
Wally