Home All Groups Group Topic Archive Search About

How to validate fields on the form in C#

Author
10 Mar 2006 7:14 PM
juventusaurabh
I have a form with a number of fields, some of which would be
filled(populated) automatically from the MS SQL database on certain
event.Now, I have certain validations on the fields from sql database
as constraints(eg. format of the tel number), So I was wondering how do
I catch these runtime exceptions which r likely to occur if the user
enters something which violated the sql constraints.

Also, on my form, the user can also change the information (which is
populated by the sql database), this information after submitting goes
back into the database which has constraints. So, I would like to
validate this info b4 Sql throws exception.

Any idea how to approach over this??

Author
10 Mar 2006 7:16 PM
Marina Levit [MVP]
Controls that take user input will typically have a Validating event that
you can use to check the data the user entered.

Show quoteHide quote
"juventusaurabh" <saurabh.kot***@gmail.com> wrote in message
news:1142018072.858520.320210@i39g2000cwa.googlegroups.com...
>I have a form with a number of fields, some of which would be
> filled(populated) automatically from the MS SQL database on certain
> event.Now, I have certain validations on the fields from sql database
> as constraints(eg. format of the tel number), So I was wondering how do
> I catch these runtime exceptions which r likely to occur if the user
> enters something which violated the sql constraints.
>
> Also, on my form, the user can also change the information (which is
> populated by the sql database), this information after submitting goes
> back into the database which has constraints. So, I would like to
> validate this info b4 Sql throws exception.
>
> Any idea how to approach over this??
>
Are all your drivers up to date? click for free checkup

Author
10 Mar 2006 7:19 PM
dkode
You could use a validator control to check the values before they are
submitted to SQL.

Technically, this checking should occur wherever your business logic
rules exist (UI, Business Layer etc) so that once your business rules
run against the input, you can throw an appropriate exception and
display it to the user.

Bookmark and Share