I'm used to home-brewing a lot of this DAO stuff, but in this case I'm wanting to use the DataSet and built-in functionality from Visual Studio as much as possible, as this is a very basic utility type of application. Here are my basic requirements for the application:
1. User will select an environment at runtime from a drowdown (The databases are identical, i.e., Prod, QA, UAT, and user needs to be able to choose which environment they will be working in);
2. User will be displayed a list of records representing scheduled tasks which they can modify (Update, Add, Delete).
To this end, I have created a SQL proc to bring backk all the records in the database, as well as an Insert and Update proc. I want to use procs instead of generated UPDATE statements because the user's name as well as the current DateTime need to be persisted as part of records that are added or updated. I created a DataSet in Visual Studio, and dragged the main table that I included (BULK_DATA_UPLOAD_SCHEDULE) onto the form. I got a DataGridView and a BindingNavigator with ToolStripButton's that are presumably meant to handle the CRUD operations of the DataGridView.
When the application runs, everything loads just fine into the DataGridView. I was also able to get the changing environment to work by updating the ConnectionString on the TableAdapter... So far, so good...
The problem seems to come in when I use the buttons on the BindingNavigator to attempt to add, update, or delete rows. The BindingNavigator and DataGridView appear to be bound together, because clicking the Delete button does indeed remove a row from the tabl; the Add button creates a new row, and the navigation buttons work. However, nothing gets persisted to the database. Furthermore, when a new row is added, the values aren't accurate in the row, because there are default values that need to be set (One column, BULK_DATA_OBJECT_ID, is a foreign key reference to another talbe. I have bound this column to a DropDownList that is correctly populated when the table is loaded with existing values, but on a new row, it's value is not selected. A default value should be getting auto-populated here, somehow). So, I guess my questions are these:
1) How do I get the values form the DataGridView back to the database? Bear in mind that I want to call my own Insert / Update procs for these. I know how to add them to the TableAdapter in the deisgneer, but is there some event that I'm supposed to be binding to on the TableAdpater? The DataGridView?
2) Hand-in-hand with #1, how do I specifiy the default values to appear on a new row in the DataGridView when the user adds a new row?
3) I'd like to do some basic validation at some point beofre data is just pushed back to the database (for example, I'd like to make sure that none of the schedules overlap. What event and on what object do I need to listen so I can perform this validation before the data goes to the database?
4) Lastly, when the user exits the application, I'd like to make sure that the DataGridView isn't dirty. What do I need to do to find this?
Thanks for any assistance. This all seems like very basic stuff that should have been a walkthrough on these objects, but I have had an awful time trying to find it if it is. I was able to capture the Click event on the Save button on the MenuItemToolStrip of the BindingNavigator, and then call Update( dataset) on my TableAdapter, passing in my DataSet I'd created. This did work, but I'm not entirely sure how or why, and it obviously is calling the built-in Update functions, which I didn't want to use for the aforemetioned reasons. It also perofrms no validation, which again, I want to do before allowing it to update.