Lesson 34

Programming Databases, Part 1

Database programming is another truly enormous topic, so there isn't room to cover it all here. However, Visual Studio provides tools that make some simple kinds of database programs so easy to write that your education won't be complete until you've written a few.

In this lesson, you learn how to make a simple database application. You learn how to connect to a database, load data, let the user navigate through records, and save any changes.

Connecting to a Database

The first step in building a database program is giving it a connection to the data. You can easily do this interactively at design time, although it requires quite a few steps:

  1. First open the Project menu and select Add New Data Source to display the dialog shown in Figure 34.1. As you can see in the figure, you might want the program to get data from several different places. The data source used in this example is a database, so select Database and click Next.
  2. The dialog's next screen lets you decide whether you want to use a data set or an entity data model for your data. (The entity data model option won't be there if you don't have the entity framework tools installed. You won't be using an entity data model in this lesson, so if that option doesn't appear, don't worry about it.) For this example, ...

Get C# 24-Hour Trainer, 2nd Edition 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.