Danh mục

Practical Database Programming With Visual C#.NET- P12

Số trang: 50      Loại file: pdf      Dung lượng: 1.04 MB      Lượt xem: 17      Lượt tải: 0    
Hoai.2512

Hỗ trợ phí lưu trữ khi tải xuống: 16,000 VND Tải xuống file đầy đủ (50 trang) 0
Xem trước 5 trang đầu tiên của tài liệu này:

Thông tin tài liệu:

Tham khảo tài liệu practical database programming with visual c#.net- p12, công nghệ thông tin, cơ sở dữ liệu phục vụ nhu cầu học tập, nghiên cứu và làm việc hiệu quả
Nội dung trích xuất từ tài liệu:
Practical Database Programming With Visual C#.NET- P12 7.5 Runtime Objects Method 573actions such as updating data and deleting data. Among them, two popular methods arewidely applied: 1. Update or delete records from the desired data table in the DataSet, and then call the DataAdapter.Update() method to update the updated or deleted records from the table in the DataSet to the table in the database. 2. Build the update or delete commands using the Command object, and then call the Command’s method ExecuteNonQuery() to update or delete records in the database. Or you can assign the built command object to the UpdateCommand or DeleteCommand properties of the DataAdapter and call the ExecuteNonQuery() method from the UpdateCommand or DeleteCommand property. The first method is to use the so-called DataSet-DataAdapter method to build adata-driven application. DataSet and DataTable classes can have different roles whenthey are implemented in a real application. Multiple DataTables can be embedded intoa DataSet and each table can be filled, inserted, updated, and deleted by using thedifferent properties of a DataAdapter such as the SelectCommand, InsertCommand,UpdateCommand, or DeleteCommand when the DataAdapter’s Update() methodis executed. The DataAdapter will perform the associated operations based on the modi-fications you made for each table in the DataSet. For example, if you deleted rowsfrom a table in the DataSet, then call this DataAdapter’s Update() method. This methodwill perform a DeleteCommand based on your modifications. This method is relativlysimple since you do not need to call some specific methods such as the ExecuteNonQuery()to complete these data queries. However, this simplicity brings some limitations foryour applications. For instance, you cannot access different data tables individually toperform multiple specific data operations. This method is very similar to the secondmethod we discussed in Part I; therefore, we will not continue the discussion for thismethod. The second method allows us to use each object individually, which means that youdo not have to use the DataAdapter to access the Command object or use the DataTabletogether with the DataSet. This provides more flexibility. In this method, no DataAdapteror DataSet is needed, and you only need to create a new Command object with a newConnection object, and then build a query statement and attach some useful parametersinto that query for the new created Command object. Then you can update or delete dataagainst any data table by calling the ExecuteNonQuery() method, which belongs to theCommand class. We will concentrate on this method in this part. In this section, we provide three sample projects named SQLUpdataDeleteRTObject,AccUpdataDeleteRTObject, and OracleUpdataDeleteRTObject to illustrate how toupdate or delete records in three different databases using the runtime object method.Because of the coding similarity between these three databases, we will concentrate onupdating and deleting data in the SQL Server database using the sample projectSQLUpdataDeleteRTObject first, and then illustrate the coding differences betweenthese databases by using the real codes for the rest of two sample projects. In addition to those three sample projects, we will also discuss data updating anddeleting in our sample databases using the LINQ to SQL query method. A sample projectLINQSQLUpdateDelete will be developed in this chapter to show readers how to buildan actual data-driven project to update and delete data against our sample databasesusing the LINQ to SQL query method.574 Chapter 7 Data Updating and Deleting with Visual C#.NET7.6 UPDATE AND DELETE DATA FOR SQL SERVER DATABASE USING RUNTIME OBJECTSNow let’s first develop the sample project SQLUpdataDeleteRTObject to update anddelete data in the SQL Server database using the runtime objects method. Recall inSections 5.19.2.3 to 5.19.2.7 in Chapter 5, we discussed how to select data for the Faculty,Course, and Student Form windows using the runtime objects method. For the FacultyForm, a regular runtime selecting query is performed, and for the Course Form, a runtimejoined-table selecting query is developed. For the Student table, the stored proceduresare used to perform the runtime data query. Similarly in this part, we divide this discussion into two sections: 1. Update and delete data in the Faculty table from the Faculty Form window using the runtime objects method. 2. Update and delete data in the Faculty table from the Faculty Form using the runtime stored procedure method. In order to avoid duplication of the coding, we will modify an existing project namedSQLInsertRTObject developed in Chapter 6 to create our new project ...

Tài liệu được xem nhiều: