A key advantage is that this means ADO .NET works great with muli-tiered ('client/server' or 'client/middleware/server') systems -- such as the Internet! After a DataSet is created, your program can disconnect from the actual physical source of the data (the database) and only needs to reconnect once either a change or more data is needed. A DataSet can be thought of as being like a custom database just for your program. There are tables, columns, relationships, constraints, views, and so forth. Changes to the 'real' database are communicated using messages (that is, SQL commands in our case) and this further isolates your program from changes, differences, or even problems (such as the database being taken offline) to the 'real' database.
Our tutorial program, as in previous installments, is not intended to be an example of program design, but rather is intended to help you understand exactly what the ADO .NET objects are doing. For this reason, things like Close and Dispose methods are not called to eliminate a few statements. Only a few Try-Catch blocks have been included ... just as a reminder that you do need them. And the program doesn't even have an Exit function. These things can become very critical in online server based systems, but they don't make much of a difference in a standalone examle like this.
To illustrate add, change, and delete, our example has been modified again to add a button at the bottom and to replace all the Label controls with TextBox controls since we can't insert new text into a Label control. The Two Boolean data items have also been replaced with CheckBox controls. Our new Form looks like this:
Our form is programmed to progress through three functions. First, a new row is added to the database table. Then a row selected in the ListBox can be changed in the database by keying in new values in the TextBox and CheckBox components. Finally, a selected row can be deleted from the database. The caption on the button is changed as the program runs to tell the user which function is next and the first few characters of the caption is used as a flag to control an If program block.
Next page >
A Few Words About Design > Page
1,
2,
3,
4,
5,
6