Manipulating Data with Objects

Once you have created tables, you'll need a way to manipulate them. That involves entering data into tables and retrieving data from them, as well as inspecting and modifying the structure of tables. To manipulate the structure of a table, use data-definition commands (covered in Chapter 2). To manipulate data, use one of two objects provided by the .NET framework: DataSet or DataReader.

A DataSet object typically represents a subset of records retrieved from the database. It is conceptually similar to a table (or, in some cases, a group of related tables) but includes some important distinctive properties of its own. DataSets can easily be represented as XML data and are well suited for using remote data (as when you pass a result set from a server to a client, for example, or when you transfer data between two back-end systems). With VB.NET, datasets aren't limited to holding data retrieved from a database. For example, a dataset can be used to manage data contained in an XML document or configuration file, or dynamically created from user-defined data in advanced situations.

As with ADO, VB.NET and ADO.NET provide a way to have a dataset that is either connected or disconnected. In a disconnected dataset, information is placed in the dataset, and that dataset is returned to the application that asked for it. At that point, the connection to the database is closed, and the database knows nothing about what happens to the data until the application tells it to do something. For example, suppose that you present a user with a form that contains data that she can change. When she clicks on the button to update the data, the application has to reconnect to the database and execute code that will change the data. Using a connected dataset lets you "lock in" the data being used and update the information in the database almost instantaneously. We discuss this technique in detail in Chapter 5.

A DataReader object is similar to a DataSet object, but it has different performance characteristics and capabilities. One difference is that, as its name signifies, the DataReader reads data; therefore it is a read-only means of accessing data. The DataReader also lacks a straightforward way to represent data as XML.

To keep things simple as well as reflect real-world best practices in this book we generally use the DataReader object when performing basic data access operations, reserving DataSet for situations where we really need it, such as constructing data-driven Web Services (discussed in Chapter 12).

DataSets are represented as objects, just as the typical ADODB.Recordset is an object that you might have previously worked with in Visual Basic. And like other types of Visual Basic objects, DataSet objects have their own properties and methods. We return to a discussion of objects that manipulate data later in this chapter and throughout this book. For now you need only to understand that the .NET framework uses objects to provide a clean, consistent, and relatively simple way for you to take advantage of sophisticated database functionality in your applications.



Database Access with Visual Basic. NET
Database Access with Visual Basic .NET (3rd Edition)
ISBN: 0672323435
EAN: 2147483647
Year: 2003
Pages: 97

Similar book on Amazon

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net