Validating Data in an ADO.NET 2.0 Application (C# Implementation)

Apologies for this newbie-ish question. As opposed to a full answer to my question, I would really be very happy to receive pointers to books / web-based resources that talk about what I need to do. My search efforts so far have not produced any fruit...

I have created a very plain Windows Forms application that uses ADO.NET 2.0 capabilities to retrieve & store information. I am talking about one of those applications where you just drag/drop Data Sources onto your form and all the underlying bindings, table adapters, etc. are automatically created for you (i.e. very little coding). I am going against a SQL Server 2005 Express Edition database.

Some of the fields in my database tables are not nullable.

I would like to implement a validation check that would produce a friendly warning if the user has neglected to complete a required field, on attempting to save the data into the database. Specifically, I would like to eliminate the Unhandled exception that currently appears in this case.

Body of Exception Dialog:

[Red X] Unhandled exception has occurred in your application. If you click Continue, the application will ignore this error and attempt to continue. If you click Quit, the application will close immediately.

Column 'LocationId' does not allow nulls.

I have looked at the underlying code for my form, and have found that the Save button handler contains the following:

this.Validate();
this.carBindingSource.EndEdit();
this.carTableAdapter.Update(this.cartrackerDataSet.Car);

It looks like the validation I'm looking for would be triggered by the Validate() function; I am just unclear as to what to implement on my LocationId field in response to the trigger.

Thanks very much for any guidance provided.



Answer this question

Validating Data in an ADO.NET 2.0 Application (C# Implementation)

  • MF Newbie

    Hi,

    The built-in windows form validation is ***. The best way to validate win forms apps I found is the Billy Hollis validation control which implements validation similar to the validation controls of asp.net:

    http://dotnetmasters.com/

    Charles


  • Validating Data in an ADO.NET 2.0 Application (C# Implementation)