Chapter 13. Databases
Introduction
Although Visual Basic 2005 is a flexible programming language that can be used to write a variety of applications, most developers use it to craft database-centric business programs. Interacting with a database is an essential part of Visual Basic development. Fortunately, Visual Basic includes ADO.NET, the primary database-interaction tool for the .NET Framework. ADO.NET is a “disconnected” system; it connects to SQL Server, Oracle, and other databases, but only long enough to transfer the data it needs to manage things in local memory. Older systems, such as ADO and DAO, either allowed both connected and disconnected sessions, or were fully connected. While the new fully disconnected method used in ADO.NET is a change from these older systems, it’s turned out to be quite powerful and flexible. ADO.NET also includes new features not available in earlier database-interaction technologies.
The recipes in this chapter often use the System.Data
namespace. Each recipe assumes that
any source file containing database-specific code also includes the
following statement:
Imports System.Data
Although ADO.NET supports multiple database platforms, all the source code in this chapter targets the SQL Server database. The concepts are the same for all providers, although some class names vary.
13.1. Connecting to a Data Provider
Problem
You are writing an application that interacts with a database, and you need to connect to it to run some queries.
Solution
Use ...
Get Visual Basic 2005 Cookbook now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.