Im working with dataSets vali开发者_JAVA百科dation 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.
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.
ColumnChanging event?\
Dataset events
精彩评论