How to validate fields on the form in C#

  • Thread starter Thread starter juventusaurabh
  • Start date Start date
J

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??
 
Controls that take user input will typically have a Validating event that
you can use to check the data the user entered.
 
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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top