Đang chuẩn bị liên kết để tải về tài liệu:
Working with the ADO Recordset Object
Đang chuẩn bị nút TẢI XUỐNG, xin hãy chờ
Tải xuống
Làm việc với ADO Recordset Object Các đối tượng trung tâm trong mô hình đối tượng ADODB là đối tượng Recordset. Bạn sẽ được sử dụng đối tượng này khi bạn muốn thao tác hồ sơ cùng một lúc, mang lại một bộ hồ sơ mà để làm việc | Working with the ADO Recordset Object The central object in the ADODB object model is the Recordset object. You will be using this object when you want to manipulate records one at a time or bring back a set of records with which to work. With ADO when you declare the type of variable you are going to use you can instantiate it at the same time with the New keyword. Displaying Records by Using GetString For debugging purposes you can also dump the whole recordset into a string variable for display. Listing A.4 shows you how to do this. Listing A.4 basRecordsetExamples.vb Opening and Retrieving a Recordset for Display Sub OpenRecordsetWithGetStringDisplayExample ByVal txtResults As TextBox Dim cnn As New ADODB.Connection Dim rstCurr As New ADODB.Recordset OpenNorthwindADOConnection cnn rstCurr.Open Select from Orders where OrderDate 06 12 97 cnn ADODB.CursorTypeEnum.adOpenForwardOnly txtResults.Text rstCurr.GetString rstCurr.Close End Sub Using the OpenNorthwindADOConnection subroutine listing in Listing A.3 a connection object is referenced and that is passed to the Open method of a Recordset object. Tip Notice that the cursor type returned will be ADODB.CursorTypeEnum.adOpenForwardOnly. Because all that is happening is the data being dumped to a string using this cursor type makes sense. This will give you the best performance. Some other choices include adOpenDynamic adOpenKeyset adOpenStatic and adOpenUnspecified. You can run this example by clicking on the button labeled Open a Recordset with GetString Display on the main form. Figure A.5 shows what you will see. Figure A.5. The GetString method is handy for checking out data. Editing and Updating Records You can use several methods to perform editing and updating of records in code. Unlike the last section in which you could open the recordset as a Forward Only type cursor you will want to open it as a Dynamic type cursor. You can see this in Listing A.5. Listing A.5 basRecordsetExamples.vb Opening and .