1 / 158

Chapter 6 Data Updating and Deleting with Visual Basic.NET

Chapter 6 Data Updating and Deleting with Visual Basic.NET.

hinto
Download Presentation

Chapter 6 Data Updating and Deleting with Visual Basic.NET

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Chapter 6 Data Updating and Deleting with Visual Basic.NET In this Chapter, we will discuss how to update and delete data against the databases. Basically many different methods are provided and supported by Visual Basic.NET and .NET Framework to help users to perform the data updating and deleting against the database. Among them, three popular methods are widely implemented: 1. Using TableAdapter DBDirect methods such as TableAdapter.Update() and TableAdapter.Delete() to update and delete data directly again the databases. 2. Using TableAdapter.Update() method to update and execute the associated TableAdapter’s properties such as UpdateCommand or DeleteCommand to save changes made for the table in the DataSet to the table in the database. 3. Using the run time object method to develop and execute the Command’s method ExecuteNonQuery() to update or delete data again the database directly.

  2. Chapter 6 Data Updating and Deleting with Visual Basic.NET - 2 Both methods 1 and 2 need to use Visual Basic.NET design tools and wizards to create and configure TableAdapters, build the associated queries using the Query Builder and call those queries from Visual Basic.NET applications. The difference between method 1 and 2 is that method 1 can be used to directly access the database to perform the data updating and deleting, but method 2 needs two steps to do that. First the data updating or deleting are performed to the associated tables in the DataSet, and then those updated or deleted data are updated to the tables in the database by executing the TableAdapter.Update() method. This Chapter is divided into two parts; Part I provides discussions on data updating and deleting using methods 1 and 2. Part II presents the data updating and deleting using the run time object method to develop command objects to execute the ExecuteNonQuery() method dynamically.

  3. Chapter 6 Data Updating and Deleting with Visual Basic.NET - 3 When finished this chapter, you will • Understand the working principle and structure on updating and deleting data against the database using the Visual Basic.NET design tools and wizards • Understand the procedures in how to configure the TableAdapter object by using the TableAdapter Query Configuration Wizard and build the query to update and delete data against the database • Design and develop special procedures to validate data before and after data updating and deleting • Understand the working principle and structure on updating and deleting data against the database using the run-time object method • Design and build stored procedures to perform the data updating and deleting

  4. Chapter 6 Data Updating and Deleting with Visual Basic.NET - 4 Three kinds of databases will be used in the example projects to illustrate how to perform the data updating and deleting in this Chapter. They are: Microsoft Access, SQL Server 2005 and Oracle Database 10g XE databases. In order to save time and avoid the repeatability, we will use sample projects such as InsertWizard, SQLInsertWizard, AccessInsertRTObject, SQLInsertRTObject and OracleInsertRTObject we developed in the last chapter and modify them to create new associated projects used in this Chapter. Recall that some command buttons on the different form windows in those projects have not been coded, such as Update and Delete, and those buttons or exactly those buttons’ event procedures will be developed and built in this chapter. We only concentrate on the coding for the Update and Delete buttons in this Chapter.

  5. PART I Data Updating and Deleting with Visual Basic.NET Design Tools and Wizards In this part, we discuss updating and deleting data against the database using the Visual Basic.NET design tools and wizards. We develop two methods to perform these data actions: First we use the TableAdapter DBDirect methods, TableAdapter.Update() and TableAdapter.Delete(), to directly update or delete data in the database. Second we show readers how to update or delete data in the database by first updating or deleting records in the DataSet, and then updating those records’ changes from the DataSet to the database using the TableAdapter.Update() method. Both methods utilize the so-called TableAdapter’s direct and indirect methods to complete the data updating or deleting. The database we try to use is the Microsoft Access database, CSE_DEPT.mdb. You can try to use any other databases such as Microsoft SQL Server 2005 or Oracle Database 10g XE.The only issue is that you need to select and connect the correct database with your applications.

  6. 6.1  Update or Delete Data Against Databases We have already provided a very detailed discussion about the TableAdapter DBDirect methods in section 5.1.1 in Chapter 5. To use these methods to directly access the database to make the desired manipulations to the data stored in the database, one needs to use Visual Basic.NET design tools and wizards to create and configure the associated TableAdapter. There are some limitations existed when these DBDirect methods are utilized. For example, each TableAdapter is associated with a unique data table in the DataSet, therefore the data updating or deleting can only be executed for that data table only by using the associated TableAdapter. In other words, the specified TableAdapter cannot update or delete data from any other data tables except the data table that is related to the created TableAdapter.

  7. 6.1.1 Updating and Deleting Data from Related Tables in a Dataset When updating or deleting data against related tables in a dataset, it is important to update or delete data in the proper sequence in order to reduce the chance of violating referential integrity constraints. The order of command execution will also follow the indices of the DataRowCollection in the dataset. To prevent data integrity errors from being raised, the best practice is to update or delete data against the database in the following sequence: 1. Child table: delete records. 2. Parent table: insert, update, and delete records. 3. Child table: insert and update records.

  8. 6.1.1 Updating and Deleting Data from Related Tables in a Dataset - 2 For our sample database CSE_DEPT, all five tables are related with different primary keys and foreign keys. For example, among the LogIn, Faculty and Course tables, the faculty_id works as a key to relate these three tables together. The faculty_id is a primary key in the Faculty table, but a foreign key in both LogIn and the Course tables. In order to update or delete data from any of those tables, one needs to follow the sequence above. As a case of updating or deleting a record against the database, the following data operations need to be performed: 1. First that record should be removed or deleted from the child tables, LogIn and Course tables, respectively 2. Then that record can be updated or deleted from the parent table, Faculty table 3. Finally that updated record can be inserted into the child tables such as Login and Course tables for the data updating operation.

  9. 6.1.1 Updating and Deleting Data from Related Tables in a Dataset - 3 It would be terribly complicated if we try to update a completed record (including update the primary key) for an existing data in our sample database, and in practice it is unnecessary to update a primary key for any record since the primary key has the same lifetime as a database. The popular way is to remove those undesired records and then insert new records with new primary keys. So in this Chapter, we will concentrate on either updating or deleting the whole record (including the primary key) against the database for new inserted data into the database or updating the existing data in our sample database without touching the primary key.

  10. 6.1.2 Update or Delete Data Against Database Using TableAdapter DBDirect Methods Three typical TableAdapter’s DBDirect methods are listed in Table 6-1.

  11. 6.1.2 Update or Delete Data Against Database Using TableAdapter DBDirect Methods - 2 Both DBDirect methods, TableAdapter.Update() and TableAdapter.Delete(), need the original column values as the parameters when these methods are executed. The TableAdapter.Update() method needs both the original and the new column values to perform the data updating. Another point to be noted is that when the application uses the object to store the data, for instance, in our sample project we use textbox objects to store our data, you should use this DBDirect method to perform the data manipulations against the database.

  12. 6.1.3 Update or Delete Data Against Database Using TableAdapter.Update Method You can use the TableAdapter.Update() method to update or edit records in a database. The TableAdapter.Update() method provides several overloads that perform different operations depending on the parameters passed in. It is important to understand the results of calling these different method signatures. To use this method to update or delete data against the database, one needs to perform the following two steps: • Update or delete records from the desired DataTable based on the selected data rows from the table in the DataSet • After the rows have been modified or deleted from the DataTable, call the TableAdapter.Update() method to reflect those modifications to the database. You can control the amount of data to be updated by passing an entire DataSet, a DataTable, an array of DataRows, or a single DataRow.

  13. 6.1.3 Update or Delete Data Against Database Using TableAdapter.Update Method - 2 Table 6-2 lists various TableAdapter.Update() methods.

  14. 6.2  Update and Delete Data for Microsoft Access Database Using the Sample Project – AccessUpdateDeleteWizard We have provided a very detailed introduction about the Design Tools and Wizards in Visual Basic.NET in section 4.2 in Chapter 4. The popular design tools and wizards include the DataSet, BindingSource, TableAdapter, Data Source window, Data Source Configuration window and DataSet Designer. We need to use those staff to develop our data-updating and deleting sample project based on the InsertWizard project developed in the last chapter. First let’s copy that project and do some modifications on that project to get our new project. The advantage of creating our new project in this way is that we don’t need to redo the data source connection and configuration since those jobs have been performed in the previous chapter.

  15. 6.2.1Create New Project Based on the InsertWizard Project Open the Windows Explorer and create a new folder Chapter 6, and then browse to our project InsertWizard that was developed in the last chapter, copy this project to our new folder Chapter 6. Change the name of the solution and the project from InsertWizard to AccessUpdateDeleteWizard. Double click the AccessUpdateDelete-Wizard Project.vbproj to open this project. Perform the following modifications to get our desired project: • Go to Project|AccessUpdateDeleteWizard Project Properties menu item to open the project’s property window. Change the Assembly name: from InsertWizard Project to AccessUpdateDeleteWizard Project and the Root namespace from InsertWizard_Project to AccessUpdateDeleteWizard_ Project, respectively. • Click the Assembly Information button to open the Assembly Information dialog box, change the Title: and the Product: to AccessUpdateDeleteWizard Project. Click OK to close this dialog.

  16. 6.2.2Application User Interfaces Recall that when we developed the project InsertWizards, there are five command buttons located in the Faculty form window: Select, Insert, Update, Delete and Back. In this section, we need to use both Update and Delete buttons, exactly these two buttons’ event procedures, to perform the data updating and deleting actions against the database. Unlike adding a new record into the database, for the update and delete operations, we don’t need to develop any new form window as the user interfaces to collect the new records to perform those updating and deleting operations. Instead we can use the Faculty form with some modifications.

  17. 6.2.2.1 Modify the Faculty Form Window Since we have two methods available to perform the data updating or deleting, so we need to add one more control to the Faculty form window to allow us to select between these two methods as the project runs. Add a combo box control named ComboMethod to the upper-left corner of the Faculty form window. Also we need to change all five label controls that are located inside the Faculty Information GroupBox to five textbox controls because we need to change the faculty information by entering new data into those textboxes. Besides these five textbox controls, add two more textboxes into this GroupBox and name them as txtID for the faculty_id and txtName for the Faculty Name, respectively. These two new textboxes are used to hold the faculty_id and Faculty Name information.

  18. 6.2.2.1 Modify the Faculty Form Window - 2 An advantage of using this Faculty form as our user interface is that we don’t need any searching process to find the data items to be updated or deleted from the database. Instead, we can get that data by performing a data query using the Select button’s event procedure, then we can easily update or delete that data by modifying any piece of information that is stored in the associated textbox in the Faculty form window.

  19. 6.2.2.2 Bind Data for All Textboxes of the Faculty Form Window This data binding is necessary since we need to call the Select button’s event procedure to execute the data query when we perform the data validations for data inserting, updating and deleting later. Open the Faculty form window if it is not opened, and then select the first textbox Faculty ID, which we just added. Go to the Properties window and expand the (DataBindings) item to the Text property, and then click the drop-down arrow that is next to the Text property to open the Add Project Data Source dialog box. Select the faculty_id from the list by clicking it, which is shown in Figure 6-2a. In this way, a binding relationship between the Faculty ID textbox in the Faculty form and the faculty_id column in the DataSet is setup. In a similar way, you can finish the data bindings for all of these seven textboxes. An example of binding for the Email textbox is shown in Figure 6-2b.

  20. Two Binding Examples

  21. 6.2.3 Validate Data Before the Data Updating and Deleting This data validation can also be neglected because when we performed a data query by clicking the Select button, the retrieved data should be a complete data and can be displayed in the Faculty form window. This means that all textboxes have been filled by the related faculty information and no one is empty, no matter we do some modifications or not, all textboxes is full. So this data validation before the data updating or deleting can be avoided.

  22. 6.2.4 Build the Update and Delete Queries As we mentioned, two methods will be discussed in this part; one is to update or delete records using the TableAdapter DBDirect method, and the other one is to use the TableAdapter.Update() method to update modified records from the DataSet into the database. First let’s concentrate on the first method. Now let’s build our data updating and deleting queries using the TableAdapter Query Configuration Wizard and Query Builder.

  23. 6.2.4.1 Configure TableAdapter and Build Data Updating Query Open the DataSet Designer. Then right click on the bottom item from the Faculty table and select the Add Query item from the popup menu to open the TableAdapter Query Configuration Wizard. Keep the default selection: Use SQL statements unchanged and click the Next to go to the next window. Select and check the UPDATE item from this window since we need to perform updating data query, and then click the Next again to continue. Click the Query Builder button since we want to build our updating query. The opened Query Builder window is shown in Figure 6-3. Remove the default question mark (=?) from the faculty_id row under the column Filter, and enter a question mark (?) to the name row under the column Filter, press the Enter key from the keyboard. Remove all rows under the last row – email and your finished query builder window should match one that is shown in Figure 6-3.

  24. 6.2.4.1 Configure TableAdapter and Build Data Updating Query - 2 Click the OK button to go to the next window. Click the Next to confirm this query and continue to the next step. Modify the query function name from the default one to the UpdateFaculty and click the Next and Finish button to complete this query building (Figure 6-3).

  25. 6.2.4.2 Build the Data Deleting Query Re-open the Edit DataSet with Designer window and right click on the last item from the Faculty table and select the Add Query item to open the TableAdapter Query Configuration Wizard if it is not opened. On the opened wizard, keep the default selection: Use SQL statements unchanged and click the Next to go to the next window. Select and check the DELETE item from this window since we need to perform deleting data query, and then click the Next again to continue. Click the Query Builder button since we want to build our deleting query. The opened Query Builder window is shown in Figure 6-4. Remove the question mark (=?) from the faculty_id row under the column Filter. Go to the middle pane, and then type the name into the first column just under the row of faculty_id. Move the cursor to the Filter column along the name row and enter a question mark (?) into that field, press the Enter key on the keyboard.

  26. 6.2.4.2 Build the Data Deleting Query - 1 Your finished query builder should match one that is shown in Figure 6-4. Click the OK and then Next to confirm this query, and continue to the next step. Modify the query function name from the default one to the DeleteFaculty and click the Next and then Finish button to complete this query building.

  27. 6.2.5 Develop Codes to Update Data Using the TableAdapter DBDirect Method To perform the data updating using this method, some startup coding and modifications to the original coding are necessary. We divided the coding job into three sub-sections: • Modification coding • Startup coding • Updating coding

  28. 6.2.5.1 Modifications of the Coding Because the target data to be updated or deleted in the database are new inserted data, so some modifications need to be performed first to the codes in the Insert Faculty Form. Open the code window of the Insert Faculty Form, perform the following modifications: • Change the scope of the form-level variable FacultyName to a global variable by replacing the Private with Public accessing-mode keyword in the top of the code window. • Change the code for the Back button’s event procedure, replace Me.Close() with Me.Hide().

  29. 6.2.5.2 Startup Coding The startup coding is developed inside the Faculty form. We will use this form to perform data updating, data deleting and data validation functionalities. Open the code window of the Faculty form and perform the following modifications (Figure 6-5).

  30. 6.2.5.3 Updating Coding The main coding to perform this data updating is developed inside the Update button’s event procedure. Open the Update button event procedure of the Faculty form window, enter following codes that are shown in Figure 6-6 into this event procedure.

  31. 6.2.6 Develop Codes to Update Data Using the TableAdapter.Update Method Open the Update button’s event procedure if it is not opened and add the codes that are shown in Figure 6-7 into this event procedure. The codes we developed in the previous step are highlighted by the gray color as the background.

  32. 6.2.6 Develop Codes to Update Data Using the TableAdapter.Update Method - 2 In order to update a selected row from the Faculty table in the DataSet, we need first to identify that row. Visual Basic.NET provides a default method FindBy() with the primary key as the argument to do that. To find the faculty_id, we can use a query function FindFacultyIDBy-Name() we built in section 4.14. If faculty_id is found, the default method FindByfaculty_id() is executed to locate the desired row in the Faculty table and the desired data row is returned and assigned to the local variable FacultyRow. A user-defined function UPFacultyRow() is called to assign all updated faculty information to the desired row.In this way, the selected row in the Faculty table in the DataSet is updated. The Validate() command closes out the editing of a control, in our case, closes any editing for textbox control in the Faculty form. The EndEdit() method of the binding source writes any edited data in the controls back to the record in the dataset. In our case, any updated data entered into the textbox control will be reflected to the associated column in the DataSet. Finally the Update() method of the TableAdapter sends updated data back to the database.

  33. 6.2.6 Develop Codes to Update Data Using the TableAdapter.Update Method - 3 The coding for the function UPFacultyRow() is shown in Figure 6-8. The argument of this function is a DataRow object and it is passed by a reference to the function. The advantage of passing an argument in this way is that any modifications performed to DataRow object inside the function can be returned to the calling procedure without needing another returned variable to be created. The updated faculty information that stored in the associated textbox is assigned to associated column of the DataRow in the Faculty table in the DataSet. In this way, the selected DataRow in the Faculty table is updated.

  34. 6.2.7 Develop Codes to Delete Data Using the TableAdapter DBDirect Method To delete data from a database, you can use either the TableAdapter DBDirect methodTableAdapter.Delete() or the TableAdapter.Update() method. Or, if your application does not use TableAdapters, you can use the run time object method to create command object to delete data from a database (for example, ExecuteNonQuery). The TableAdapter.Update() method is typically used when your application uses DataSets to store data, whereas the TableAdapter.Delete() method is typically used when your application uses objects, for example in our case we used textboxes, to store data.

  35. 6.2.7 Develop Codes to Delete Data Using the TableAdapter DBDirect Method-2 Open the Delete button’s event procedure in the Faculty form window, enter the codes that are shown in Figure 6-9 into this event procedure. A vbButton object of the MessageboxButtons class is created and we use these two buttons to confirm the data deleting later.The local variable Answer is an instance of DialogResult and it is used to hold the returned value of calling the MessageBox function.

  36. 6.2.8 Develop Codes to Delete Data Using the TableAdapter.Update Method Add the codes that are shown in Figure 6-10 into the Delete button’s event procedure, exactly into the Else block. The codes we developed in the previous step have been highlighted with the gray color as the background.

  37. 6.2.9 Validate the Data After the Data Updating and Deleting As we mentioned in the previous section, we do not need develop any code for these data validations and we can use the coding developed for the Select button’s event procedure to perform these validations. The last job we need to do before we can run the project to test our coding is to add some codes to the Select button’s event procedure to handle the faculty photo issue. The reason for that is because after a faculty record is updated in the database, for example, a faculty name is updated, and the associated faculty photo should also be updated. To make this project simple, we try to use a default photo 'Default.jpg' to represent any updated faculty photo.

  38. 6.2.9 Validate the Data After the Data Updating and Deleting - 2 Open the Select button’s event procedure of the Faculty form, and add the codes that are shown in Figure 6-11 into this procedure. The codes we developed in the previous step are highlighted with the gray color as the background.

  39. 6.2.9 Validate the Data After the Data Updating and Deleting - 3 The functionality of this piece of coding is: A. If no matched faculty photo has been found from execution of the function FindName(), we will continue to check whether the faculty name has been changed. B. If the faculty name has been changed or updated, which is indicated by a True of the Boolean variable FacultyNameFlag, the default faculty photo 'Default.jpg' is assigned to the photo name string variable strName, and the FacultyNameFlag is reset to avoid multiple operations of the same faculty name updating. C. If no faculty name is updated, which means that no matched faculty photo has been found. A warning message is displayed if that situation occurred.

  40. Testing the Project– Data Insertion Now let’s run the project to test our coding for the data updating and data deleting. Make sure that the default faculty photo 'Default.jpg' has been stored in the default location. Click the Select button on the Faculty form to first test the data query functionality. Then click the Insert button to open the Insert Faculty Form window to insert a new faculty record, which is shown below: • G88765 Faculty ID textbox • George Stone Faculty Name textbox • Associate Professor Title textbox • MTC-119 Office textbox • 750-330-3377 Phone textbox • University of Florida College textbox • gstone@college.edu Email textbox

  41. Testing the Project– Data Updating Click the Insert button to insert this new faculty record into the Faculty table. Then click the Back button to return to the Faculty form to perform the data updating, data deleting and data validation functionalities. Click the drop-down arrow of the combo box ComboName and you will find that the new added faculty name has been in this box. Select this name and click the Select button to retrieve back the new inserted faculty record and display it in the associated textboxes in this form. Now update this record by entering the information listed below to modify this faculty record: Professor Title textbox MTC-219 Office textbox 750-378-5577 Phone textbox

  42. Testing the Project– Data Validation Keep the content of all other textboxes unchanged, and click the Update button to update this new record to the database. You can use either TableAdapter DBDirect or TableAdapter.Update method as you like by selecting it from the Method combo box. To validate this updating, make sure that the faculty name of the updated record is in the ComboName combo box and then click the Select button to retrieve back that updated data. You can find that the faculty record is updated, which is shown in Figure 6-13.

  43. Testing the Project– Data Deleting To delete this faculty record, click the Delete button. Click Yes to MessageBox. Then you can validate that deletion by clicking the Select button to try to retrieve back that deleted record. What happened after you clicked the Select button? A message "No matched faculty found" is displayed to indicate that the faculty record has been deleted from the database. One point to be noted is that when you update the faculty name by changing the content of the Faculty Name textbox, be sure to go to the ComboName combo box to select the modified faculty name to perform the data validation by clicking the Select button after you finished the updating of that record. You need to perform the same operations if you want to delete that record from the database. The key is that the content of the faculty name textbox (named Name) may different with the content of the combo box ComboName, and the former is an updated faculty name and the latter is an old faculty name if an updating of the faculty name is performed.

  44.  6.3Update and Delete Data For SQL Server Database Using the Sample Project – SQLUpdateDeleteWizard To save time and space, we still modify an existing project SQLInsertWizard to create a new project SQLUpdateDeleteWizard and use it in this Chapter. Create a new folder Chapter 6 if you have not, and copy the project SQLInsertWizard to our new folder Chapter 6. Change the name of the solution and the project to SQLUpdateDeleteWizard. Double click the SQLUpdateDeleteWizard Project.vbproj to open this project, and perform the following modifications to get our desired project: • Go to the Project|SQLUpdateDeleteWizard Project Properties menu item to open the project’s property window. Change the Assembly name: to SQLUpdateDeleteWizard Project and the Root namespace to SQLUpdate-DeleteWizard_ Project. • Click the Assembly Information button to open the Assembly Information dialog box, change the Title: and the Product: to SQLUpdateDeleteWizard Project. • Click OK to close this dialog box.

  45. 6.3Update and Delete Data For SQL Server Database Using the Sample Project – SQLUpdateDeleteWizard - 2 Because of the similarity between this project and the project AccessUpdateDeleteWizard, we will not duplicate any identical parts. Perform the following jobs to finish the modifications to this project: • Modify the graphical user interface, Faculty form window (6.2.2.1). • Finish data bindings between the textbox controls on the Faculty form and the associated columns in the Faculty table in the DataSet (6.2.2.2). • Finish the coding for validating data before the data updating and deleting (6.2.3). • Finish building of the Update and Delete queries (6.2.4). • Finish the coding for the updating data using the TableAdapter DBDirect method and TableAdapter.Update() method (6.2.5, 6.2.6). • Finish the coding for deleting data using the TableAdapter DBDirect method and TableAdapter.Update() method (6.2.7, 6.2.8). • Finish the coding for validating the data after the data updating and deleting (6.2.9).

  46. 6.3Update and Delete Data For SQL Server Database Using the Sample Project – SQLUpdateDeleteWizard - 3 To make modifications on step 1 simple, you can first delete all controls from the Faculty form window in the project SQLUpdate-DeleteWizard, and copy all controls from the Faculty form in the project AccessUpdateDeleteWizard. Delete the FacultyBindingSource that is copied to this form. The modifications on step 4 are to build the Update and Delete queries. There are some little differences between building those queries in Microsoft Access database and the SQL Server database. First let’s discuss how to build the Update query. Open Query Builder and perform the following operations: Remove '=@Original' under the Filter column along the faculty_id row, and place a question symbol '?' under the Filter column along the name row in the mid-pane, press the Enter key from the keyboard. Uncheck the Set checkbox for the faculty_id row to remove this item. Your finished update query should match one that is shown in Figure 6-14.

  47. 6.3Update and Delete Data For SQL Server Database Using the Sample Project – SQLUpdateDeleteWizard - 4 Click OK button to continue. In the next window, remove the SELECT query since we do not need that query. Click the Next to go to the next window. Change the function name to UpdateFaculty, click the Next and Finish buttons to close this query builder.

  48. 6.3Update and Delete Data For SQL Server Database Using the Sample Project – SQLUpdateDeleteWizard - 5 Perform the similar operations to build the Delete query, as shown in Figure 6-15, and name the query function as DeleteFaculty. To add the name column into this Delete query as a criterion, click the second row, which is just under the first row faculty_id, from the mid-pane, click the drop-down arrow and select the name column from the list. Also remove the item '=@Original' from the Filter column along the faculty_id row in the mid-pane.

  49. Testing the Project Now you can try to run this project to test the data updating and deleting functionalities. You may encounter some errors, but do not worry and they are easy to be fixed. One error is that the modified project’s name cannot be recognized by your typed DataSet generation file, CSE_DEPTDataSet.Designer.vb, in which the complete DataSet definitions are included. This error can be occurred at lines 2808, 3369, 3953, 4368 and 4741 in that file because we modify the project after this DataSet generation file was created. To fix this error, just change those items to the current project’s name: SQLUpdate-DeleteWizard in that file. Another error is that some buttons in the Faculty form cannot be connected to the associated event procedures - Back, Select and Insert buttons. To fix this error, just attaches the associated event type after each event procedure. For example, for the Select button’s Click event procedure, move the cursor to the end of the header of this event procedure, type the keyword Handles followed by the event type: cmdSelect.Click.

  50. 6.4   Update and Delete Data For Oracle Database Using the Sample Project – OracleUpdateDeleteWizard It is very similar to develop a Visual Basic.NET project to modify data against the Oracle database using the Update and Delete commands, and the only difference is the Data Source to be connected to your applications. Select the Oracle Database and enter the server name and password to finish the adding a new data source into your Visual Basic.NET project. All user interfaces and coding are identical with those coding for the last project.

More Related