Share this Page URL

Chapter 5. Using Visual Basic to Automat... > Using an Object Model - Pg. 186

Using Visual Basic to Automate Your Database The Recordset Object 186 After you've established a connection, you can retrieve a set of records or perform other actions on the database. With the Recordset object, you can add, delete, update, and otherwise work with records in the database (provided the recordset isn't set up to prevent you from updating or editing records). The Recordset object has a number of properties and methods that let you work with the data. We'll demonstrate a few of them shortly. The Fields Collection and the Field Object You use a Recordset object's Fields collection to gain access to the fields in the recordset. The Fields collection has properties and methods that are common to collections, including Item and Append. You use the Item property to identify a particular field you want to work with and the Append method to add a field to the Fields collection and the recordset. The Field object has a Value property that you can use to get or set the value of that field. You can use other field properties to find information about a field such as its data type, its name, its size, and so on. Here are two examples of how you can work with data in tables by using ADO. Work with data using ADO 1. 2. 3. 4. Open the HelloWorld5 database if it isn't already open. In the Database window, double-click the form named ADO Demonstration. In the text box labeled Country, enter Spain. In the text box labeled Launch Date, enter 3/1/2004. Click the Add Record button. You'll see the MarketingCampaigns table open in Datasheet view with the new record added: