At this point all we need to do is run the application and the Grid fills automatically with all the records in the Categories table. We use the Grid’s intrinsic means of adding rows to the underlying data model by simply typing into the provided empty row. Once you move off the row and all valid values have been entered, the row will be automatically inserted into the Database and the negative temporary primary key value will be replaced with the real server generated value.
If you select one or many rows and press the keyboard Delete key, after accepting the confirmation prompt, the row will be deleted from the Grid and from the Database.
Simply typing into the cells and moving off the row causes the existing records to be Updated as well.
Any failure to comply to constraints will be exposed as an error message that will be bubbled by the grid to the user and this will cause the current operation to cancel. In other words, you cannot delete rows that have constraints, you cannot enter characters into numeric fields and so forth.
This sample can be scaled and made better so that we can store "Previous State" instances of the records so that if we cancel, we can restore all of the original values to each row. We can provide a test to see if the current record has any changes or has been "dirtied" so that we can skip making a round trip to the Database.
This sample will show a working implementation of the content discussed in these five articles. Make sure that you change the connection string in the Form_Load event so that it points to your instance of SQL Server.