We will be undergoing scheduled maintenance on May 20th, 2013 at 02:00 GMT.
Visitors to VTC.com will be able to view all introductory videos for each training course.
Free Trial Members will gain access to first three chapters for each training course.
Full Access Members have full access to VTC.com�s entire library of video tutorials.
Now let's add the code to save our changes directly to the database. First we'll need to take a look at the task class. You can see we already have a save method which we are calling but it doesn't actually do anything yet. Before we add our new code to the Save Method, we need to make one tweak to the constructor. Here we need to add this line, ID equals task ID. This saves the ID was passed in the ID properties so that we can use it for the purposes of saving. When the row is new, we will insert it directly into the database, when the row is not new, we will use an update command to update the existing row that is in the database. We will create a couple of new methods to do this, so let's call them first. This is the insert row method. The first thing it needs to do, is set the is new property to false because now that we've inserted the row, it is no longer new. Any future changes to it will be updates. To insert the row we are creating a new database record and then on the database record, assigning each column equal to the property that we capture here in the class. We then insert this record into the task table and check for errors. Now let's add the update row method. This method works similarly but it uses a SQL update statement. Here you can see we are using the parameters to specify each of the values. We then create a prepared statement from this SQL and we bind the types for each of the columns. We then bind each of the parameters to the property values in the class. Important thing to note here is the dates are checked for null before. If they are null we just assign blank, otherwise we use the SQL date as the value. Once all that work is done, we execute the statement, and check for errors. Now let's go back to the ToDo window, we have one other change to make here. The update task row method which we've written earlier is a new line of code. We need to make sure to set the row tag equal to the task that is being edited. This is necessary when we create new rows or new tasks so that they can be edited later. Let's save that. Lastly so that we can test a little more easily, we will add a re-load menu to the file menu. And back on the ToDo window we will add a menu handler for file re-load that simply loads the task again from the database. Now let's run the project. Let's edit a task, and you can see the name is updated, but this doesn't tell us that it was saved to the database, so let's re-load, and you can see that take out garbage was re-loaded from the database. To do a full verify let's quit the application, and run it again. And now it still says take out garbage. So by simply implementing the Save Method on the task class, all the tasks are now saved automatically.
| Course: | Real Studio |
| Author: | Paul Lefebvre |
| SKU: | 34190 |
| ISBN: | 1-936334-77-1 |
| Release Date: | 2011-02-02 |
| Duration: | 7 hrs / 87 lessons |
| Work Files: |
Yes |
| Captions: | No |
| Compatibility: |
Vista/XP/2000, OS X, Linux QuickTime 7, Flash 8 |