Other Data Objects


If you want a simple program that can display and modify data, then the solution described in the previous sections may be good enough. In that case, you should let Visual Basic do most of the work for you, and you don’t need to dig into the lower-level details of database access.

You can also use objects similar to those created by Visual Basic to build your own solutions. On the one hand, you can create your own DataSet, TableAdapter, BindingSource, and BindingNavigator objects to bind controls to a database.

On the other hand, if you need to manipulate the database directly with code, it doesn’t necessarily make sense to create all these objects. If you simply want to modify a record programmatically, it certainly doesn’t make sense to create DataGridView, BindingNavigator, and BindingSource objects.

For cases such as this, Visual Basic provides several other kinds of objects that you can use to interact with databases. These objects fall into the following four categories:

  • Data containers hold data after it has been loaded from the database into the application much as a DataSet does. You can bind controls to these objects to automatically display and manipulate the data.

  • Connections provide information that lets the program connect to the database.

  • Data adapters move data between a database and a data container.

  • Command objects provide instructions for manipulating data. A command object can select, update, insert, or delete data in the database. It can also execute stored procedures in the database.

Data container and adapter classes are generic and work with different kinds of databases, while different types of connection and command objects are specific to different kinds of databases. For example, the connection objects OleDbConnection, SqlConnection, OdbcConnection, and OracleConnection work with Object Linking and Embedding Database (OLE DB); SQL Server, including Microsoft Data Engine (MSDE); Open Database Connectivity (ODBC); and Oracle databases, respectively. The SQL Server and Oracle objects work only with their specific brand of database, but they are more completely optimized for those databases and may give better performance.

Aside from the different database types they support, the various objects work in more or less the same way. The following sections explain how an application uses those objects to move data to and from the database. They describe the most useful properties, methods, and events provided by the connection, transaction, data adapter, and command objects.

Later sections describe the DataSet and DataView objects and tell how you can use them to bind controls to display data automatically.




Visual Basic 2005 with  .NET 3.0 Programmer's Reference
Visual Basic 2005 with .NET 3.0 Programmer's Reference
ISBN: 470137053
EAN: N/A
Year: 2007
Pages: 417

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