tailieunhanh - Working with the ADO Recordset Object

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 shows you how to do this. Listing Opening and Retrieving a Recordset for Display Sub OpenRecordsetWithGetStringDisplayExample ByVal txtResults As TextBox Dim cnn As New Dim rstCurr As New OpenNorthwindADOConnection cnn Select from Orders where OrderDate 06 12 97 cnn End Sub Using the OpenNorthwindADOConnection subroutine listing in Listing 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 . 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 shows what you will see. Figure . 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 . Listing Opening and .