Creating the Visual Studio Database Project

This project is for both C# and VB NET Users

 

In previous lessons, you learned how to set up a database with one table. In this section, you'll learn how to set up a database with more than one table, and write the code to display the results. Along the way, you'll learn about Foreign Keys, Joins, and Stored Procedures. As before, we'll use SQL Server as our database system.

Create a new Windows Forms App project for VB or C# for this. (If you're using Visual Studio 2019, make sure you select either C# or Visual Basic from the Language dropdown at the top. This will narrow down your choices and ensure that you don't select a different form by mistake. Easy to do!)

For the project name, call it anything you like.

Now create a Service-based database by clicking Project > Add New Item from the menu at the top of Visual Studio:

The Project menu in Visual Studio 2019

From the Add New Item dialog box, select Service-based database. Change the name to StudentsDB.mdf:

The Add New Item Dialog box showing a Service-based database highlighted

Once you have your database, right-click it in the Solution Explorer and select Open:

The Solution Explorer in Visual Studio showing a database highlighted and a sub menu displayed

On the left of Visual Studio, have a look at the Server Explorer and the Data Connections item. (If you can't see the Server Explorer, click the View menu at the top of Visual Studio. From the View menu, select Server Explorer.) It should look like this:

The Server Explorer in Visual Studio showing the database highlighted

We're going to create two tables. One will hold a list of Students and the other will hold information about the courses the student is taking. We'll create the first table in the next lesson below.

Back to the C# NET Contents Page

Back to the VB NET Contents Page