Edit Data and Update Changes That Are Made to an ADO.NET
Số trang: 10
Loại file: pdf
Dung lượng: 36.51 KB
Lượt xem: 1
Lượt tải: 0
Xem trước 2 trang đầu tiên của tài liệu này:
Thông tin tài liệu:
4,1 Chỉnh sửa dữ liệu và cập nhật thay đổi Đó là xứ cho một đối tượng ADO.NET DataSet danh mục và xem dữ liệu dễ dàng. Những gì bạn thực sự cần phải làm là để có thể chỉnh sửa và cập nhật dữ liệu.
Nội dung trích xuất từ tài liệu:
Edit Data and Update Changes That Are Made to an ADO.NET 4.1 Edit Data and Update Changes That Are Made to an ADO.NET DataSet ObjectListing and viewing data is easy. What you really need to do is to be able to edit andupdate data. You know you can use the DataSet object and some of its objects andmethods to perform this task. How do you edit and update data using the DataSet object?TechniqueIn this How-To, you will use the DataAdapter, DataSet, DataTable, and DataRowobjects. You have experienced some of the properties and methods of each of theseobjects before. In this chapter, you are going to be using the following properties andmethods that are shown in Table 4.1.Table 4.1. DataAdapter, DataSet, DataTable, and DataRow Properties and MethodsObject /Method Property DescriptionDataAdapter Fill Fills DataSet and DataTable objects.CommandBuilde GetUpdateComman Creates an Update command and places it intor d the data adapters UpdateCommand property.DataAdapter UpdateCommand Holds the SQL statement for the update.DataAdapter Close Closes the connection off the UpdateCommand. The syntax is dataadapter.UpdateCommand.Connect.Close() .DataAdapter Update Performs the update command against the dataset.DataSet Tables Represents a collection of tables found within a dataset.DataSet Rows Contains a collection of rows within a specified table in a dataset.DataSet AcceptChanges Sends the changes back to the server.DataRow ToString Retrieves the data from the column that is specified in the DataRow and returns it as a string value.DataRow BeginEdit Begins the editing of a DataRow, allowing you to replace values in the columns.DataRow EndEdit Completes the editing of a DataRow.You will see these objects with their properties and methods used in the following steps.StepsOpen and run the VB.NET-Chapter 4 solution. From the main form, click on thecommand button with the caption How-To 4.1. When the form loads, click on the LoadList button to display the customers that begin with the letter A. Click the Edit button.You will notice that the fields have now taken on a sunken look. Place the cursor into theCity field and change the value to Dunkirk. Now click Save. If you move off the recordand move back on, you will notice that the value has been saved.This form looks similar to the form created in Chapter 1. The difference is that this timeyou will not be using controls that are bound at design time. You can see the form inFigure 4.1. 1. Create a new Windows Form. 2. Add the following controls, setting the properties as listed in Table 4.2. Table 4.2. Controls Property Settings Object Property Setting Label Name Label1 Caption Customer TextBox Name txtCustLimit Text A Button Name btnLoadList Caption Load List ListBox Name lstCustomers Label Caption Customer ID Label Caption Company Name Label Caption Contact Label Caption Contact Title Label Caption Address Label Caption City Label Caption Region Label Caption Country Label Caption Phone Label Caption Fax TextBox Name txtCustomerID TextBox Name txtCompanyName TextBox Name txtContact TextBox Name txtContactTitle TextBox Name txtAddress TextBox Name txtCity TextBox Name txtRegion TextBox Name txtPostalCode TextBox Name txtCountry TextBox Name txtPhone TextBox Name txtFax Button Name btnEdit Caption &Edit Button Name btnSave Caption &Save Button Name btnCancel Caption &Cancel3. Note Notice that the Text property of the text boxes is not being set at design time. In Chapter 1, Developing Windows Forms Using Bound Controls, they were set to columns of a dataset that was included on the form. In this How-To, they will be set at run-time.4. In the class module for the form, add the following three Private declarations just below the line of code that reads Windows Form Designer generated code. These three objects will be used throughout the form.5. Dim mdsCustIndiv As New DataSet()6. Dim modaCustIndiv As OleDb.OleDbDataAdapter7. Dim mdrCustIndiv As DataRow8. Enter the following code as the Click event for btnLoadList:9. Private Sub btnLoadList_Click(ByVal sender As System.Object, _10. ByVal e As System.EventArgs) Handles btnLoadList.Click11.12. -- Move the loading of the list to a subroutine for13. additional(calls)14. LoadList()15.16. End S ...
Nội dung trích xuất từ tài liệu:
Edit Data and Update Changes That Are Made to an ADO.NET 4.1 Edit Data and Update Changes That Are Made to an ADO.NET DataSet ObjectListing and viewing data is easy. What you really need to do is to be able to edit andupdate data. You know you can use the DataSet object and some of its objects andmethods to perform this task. How do you edit and update data using the DataSet object?TechniqueIn this How-To, you will use the DataAdapter, DataSet, DataTable, and DataRowobjects. You have experienced some of the properties and methods of each of theseobjects before. In this chapter, you are going to be using the following properties andmethods that are shown in Table 4.1.Table 4.1. DataAdapter, DataSet, DataTable, and DataRow Properties and MethodsObject /Method Property DescriptionDataAdapter Fill Fills DataSet and DataTable objects.CommandBuilde GetUpdateComman Creates an Update command and places it intor d the data adapters UpdateCommand property.DataAdapter UpdateCommand Holds the SQL statement for the update.DataAdapter Close Closes the connection off the UpdateCommand. The syntax is dataadapter.UpdateCommand.Connect.Close() .DataAdapter Update Performs the update command against the dataset.DataSet Tables Represents a collection of tables found within a dataset.DataSet Rows Contains a collection of rows within a specified table in a dataset.DataSet AcceptChanges Sends the changes back to the server.DataRow ToString Retrieves the data from the column that is specified in the DataRow and returns it as a string value.DataRow BeginEdit Begins the editing of a DataRow, allowing you to replace values in the columns.DataRow EndEdit Completes the editing of a DataRow.You will see these objects with their properties and methods used in the following steps.StepsOpen and run the VB.NET-Chapter 4 solution. From the main form, click on thecommand button with the caption How-To 4.1. When the form loads, click on the LoadList button to display the customers that begin with the letter A. Click the Edit button.You will notice that the fields have now taken on a sunken look. Place the cursor into theCity field and change the value to Dunkirk. Now click Save. If you move off the recordand move back on, you will notice that the value has been saved.This form looks similar to the form created in Chapter 1. The difference is that this timeyou will not be using controls that are bound at design time. You can see the form inFigure 4.1. 1. Create a new Windows Form. 2. Add the following controls, setting the properties as listed in Table 4.2. Table 4.2. Controls Property Settings Object Property Setting Label Name Label1 Caption Customer TextBox Name txtCustLimit Text A Button Name btnLoadList Caption Load List ListBox Name lstCustomers Label Caption Customer ID Label Caption Company Name Label Caption Contact Label Caption Contact Title Label Caption Address Label Caption City Label Caption Region Label Caption Country Label Caption Phone Label Caption Fax TextBox Name txtCustomerID TextBox Name txtCompanyName TextBox Name txtContact TextBox Name txtContactTitle TextBox Name txtAddress TextBox Name txtCity TextBox Name txtRegion TextBox Name txtPostalCode TextBox Name txtCountry TextBox Name txtPhone TextBox Name txtFax Button Name btnEdit Caption &Edit Button Name btnSave Caption &Save Button Name btnCancel Caption &Cancel3. Note Notice that the Text property of the text boxes is not being set at design time. In Chapter 1, Developing Windows Forms Using Bound Controls, they were set to columns of a dataset that was included on the form. In this How-To, they will be set at run-time.4. In the class module for the form, add the following three Private declarations just below the line of code that reads Windows Form Designer generated code. These three objects will be used throughout the form.5. Dim mdsCustIndiv As New DataSet()6. Dim modaCustIndiv As OleDb.OleDbDataAdapter7. Dim mdrCustIndiv As DataRow8. Enter the following code as the Click event for btnLoadList:9. Private Sub btnLoadList_Click(ByVal sender As System.Object, _10. ByVal e As System.EventArgs) Handles btnLoadList.Click11.12. -- Move the loading of the list to a subroutine for13. additional(calls)14. LoadList()15.16. End S ...
Tìm kiếm theo từ khóa liên quan:
công nghệ máy tính phần mềm kỹ thuật lập trình lập trình dữ liệu Edit Data and Update ChangesGợi ý tài liệu liên quan:
-
Kỹ thuật lập trình trên Visual Basic 2005
148 trang 264 0 0 -
NGÂN HÀNG CÂU HỎI TRẮC NGHIỆM THIẾT KẾ WEB
8 trang 206 0 0 -
Giới thiệu môn học Ngôn ngữ lập trình C++
5 trang 194 0 0 -
6 trang 190 0 0
-
Bài giảng Nhập môn về lập trình - Chương 1: Giới thiệu về máy tính và lập trình
30 trang 164 0 0 -
Luận văn: Nghiên cứu kỹ thuật giấu tin trong ảnh Gif
33 trang 153 0 0 -
Báo cáo thực tập Công nghệ thông tin: Lập trình game trên Unity
27 trang 118 0 0 -
Giáo trình về phân tích thiết kế hệ thống thông tin
113 trang 114 0 0 -
LUẬN VĂN: Tìm hiểu kỹ thuật tạo bóng cứng trong đồ họa 3D
41 trang 108 0 0 -
Bài giảng Kỹ thuật lập trình - Chương 10: Tổng kết môn học (Trường Đại học Bách khoa Hà Nội)
67 trang 106 0 0