Chapter 2. C# Data Access to SQL Server

While building an Access database is usually enough to get data access for your application, you are often trying to get at data that already exists. Many times, that data exists in SQL Server or another ODBC database. So, the examples in this chapter will use data that exists in the sample databases provided by Microsoft. When using SQL Server 2008, the sample databases are not installed by default. You can download Northwind or Pubs and install them, but in this chapter, I will be basing the examples on the AdventureWorks database that is available on the Microsoft website.

The nice thing about accessing the data with SQL Server as the backend database is that almost all of your code will still work. So, if you have data in Microsoft Access and you move it to SQL Server, you don’t need to go back to the drawing board on every line of code. Certainly, you will have to make some changes, but you can get Visual Studio to identify them for you.

In this chapter, you’ll take the example from Chapter 2 and make the minimum changes to get the data to work with SQL Server. First, I will cover what needs to be changed and then I will show you a shortcut. To get started, take your directory from the last chapter, which should have been called EditingDatabaseTest, make a copy of it, and paste it into the same folder. When you do this, change the name from EditingDatabaseTest – Copy to EditingDatabaseTest_SQL. You don’t need to change the project ...

Get C# Database Basics 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.