Chapter 2. Data Access
In Chapter 1, you created a couple of forms and some Find buttons, but your forms were left more or less inert; they do not interact with real data.
In this chapter you'll begin to extract data from the Northwind database that comes both with SQL Server and SQL Server Express. You'll use that data to fill in your forms. You'll do this incrementally, adding complexity as you go. You'll put a premium on using data controls provided with Visual Basic 2005 and letting the controls manage the "plumbing" of database interaction for you.
Tip
If you do not have either SQL Server or SQLServer Express you will need to download a copy from Microsoft. There is usually some form of demonstration version available, though the names and conditions change from time to time. As of this writing, SQL Server Express is bundled with all versions of Visual Studio 2005 or is available as a free download on the Microsoft site (http://www.Microsoft.com).
Adding Data to the Customer Page
Return to the first tab of frmCustomerDetails and give each text box a reasonable name (e.g. txtCustomerID, txtCity, and so on).
Tip
This chapter picks up on the code from the previous chapter. If you download the source, however, you'll find that we've created folders with snapshots that represent the state of the code at the end of each chapter.
Create a Data Connection
You need a connection to the database. Before you begin, open the Data Sources Window (Data → Show Data Sources). From this floating, dockable ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access