Quantcast
Channel: Windows Forms Data Controls and Databinding forum
Viewing all articles
Browse latest Browse all 2535

How to trap System.Data.NoNullAllowedException error with BindingNavigator

$
0
0

To explain my issue, it would be simplest to explain how to recreate it...

SQL Server Data Table, simple database for this example, 2 fields...
pkid, (non identity) is primary key, not null
Description, varchar(25)

CREATE TABLE TEST (pkid varchar(25) NOT NULL, Description varchar(25), PRIMARY KEY (pkid))
  1. Use the wizard to create the form in "Details View" (Dragging the table from DataSources after changing the drop down option from DataGridView to Details)
  2. Have at least one record (row) saved in the database.
  3. Run the form, showing a record or records. (example: binding navigator is on record 1 of 1 or 1 of 5 or whatever)
  4. User clicks to add a new record, and before he/she has entered a pkid value, hit's the BindingNavigator's moveprevious button, as he or she wants info from another record in order to complete the current record
    (Image of current form)
  5. System.Data.NoNullAllowedException error happens as an unhandled exception.
    (Screen capture of error message dialog shown here)

Where do I handle this exception, and allow the user to switch rows (I'll catch the error later if they try to save it without entering the pkid).  

I've found some similar threads where people get this error when clicking add twice in a row, but their solution doesn't work for me (handling the datagridview's RowValidating event).  It doesn't work for me, as I'm not using a DataGridView, but rather databound textboxes (https://groups.google.com/forum/#!topic/microsoft.public.dotnet.framework.windowsforms.databinding/6G0y2YmT7VM

Many many thanks in advance to anyone who can help me!!



Viewing all articles
Browse latest Browse all 2535

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>