Đang chuẩn bị nút TẢI XUỐNG, xin hãy chờ
Tải xuống
Tham khảo tài liệu 'mastering sql server 2000- p2', 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ả | 20 I CHAPTER 1 INTRODUCTION TO SQL SERVER 2000 There are a few things to note about this code that will give you a sense of the flexibility of the ADO Recordset object Setting the CursorLocation property of the recordset to adUseClient tells ADO to cache the records locally after they re retrieved. This allows more efficient processing and enables some advanced ADO methods. You can specify that you want a static recordset one that doesn t reflect changes from other users as well as the type of locking in this case optimistic locking to use when you open the recordset. A recordset is a collection of fields each with a name and value. The recordset supports a number of properties including an EOF property that s true at the end of the recordset and a number of methods including a MoveNext method that moves the cursor to the next record. To be neat you can close your ADO objects and set them equal to Nothing to explicitly free the memory they re consuming. Figure 1.11 shows the results of running this procedure. FIGURE 1.11 Data from a Recordset object Editing Data ADO also makes it simple to edit data You can add new records delete existing records or modify the data stored in existing records by calling appropriate methods of a recordset. For example here s some code to modify the recordset we just created Private Sub cmdModify_Click 1 Demonstrate recordset modification Dim cnn As New ADODB.Connection Dim rst As New ADODB.Recordset 1 Open a connection cnn.Open Provider SQLOLEDB.1 _ Data Source local _ User ID sa _ TOUR FOR DEVELOPERS 21 Initial Catalog Northwind Open a recordset on a table rst.CursorLocation adUseClient rst.Open Shippers cnn adOpenStatic _ adLockOptimistic Add a record rst.AddNew rst.Fields CompanyName New Shipper rst.Fields Phone 509 -555-1212 rst.Update Modify the record just added rst.MoveLast rst Phone 509-666-1212 rst.Update Delete the record we ve been playing with rst.MoveLast rst.Delete Tidy up rst.Close cnn.Close Set rst Nothing Set cnn .