03.01.2015 Views

C# 5.0 Programmer's Reference

Visual Studio 2013 C# 5.0 Programmer's Reference

Visual Studio 2013 C# 5.0 Programmer's Reference

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

510 ❘ CHAPTER 23 ADO.NET<br />

Relational Intro<br />

Relational databases are particularly common because they are relatively intuitive<br />

and because they map naturally to the data used by many businesses.<br />

A relational database stores data in tables. Each table contains a collection of records<br />

or rows. Each record contains fields that hold values that belong to a record.<br />

The “relational” part of the name “relational database” refers to the fact that fields<br />

within the tables define relationships among the tables. Typically, records in one<br />

table correspond to records in another table where the two sets of records share<br />

some common value.<br />

For example, this chapter’s examples and exercises use the SchoolData.accdb<br />

Access database file, which is available for download on this book’s website. That<br />

database contains two tables: Students and TestScores.<br />

The Students table has three fields: StudentId, FirstName, and LastName. The<br />

TestScores table also has three fields: StudentId, TestNumber, and Score.<br />

The StudentId field provides the relational link between the two tables. For example,<br />

suppose the student Dean Diamond has the StudentId value 4. Then the Students<br />

table contains a single record with StudentId value 4 that contains Dean’s first and<br />

last names. The TestScores table contains one or more records with StudentId<br />

value 4 that contain Dean’s test scores.<br />

The SchoolData.accdb database also includes some integrity checks. For example, it<br />

won’t let you create a TestScores record with a StudentId that doesn’t exist in the<br />

Students table. (You can’t make test scores for a student that doesn’t exist.) The database<br />

also verifies that Score values are between 0 and 100. (Sorry, no extra credit.)<br />

The examples in Chapter 8 also worked with databases built inside the program’s code so they<br />

didn’t work with databases stored on the computer’s hard drive. The examples in this chapter show<br />

how you can load and query databases stored on disk. When you know how to load data from a<br />

database, you can modify the examples described in Chapter 8 to select data from the database.<br />

This chapter won’t make you a database expert, but it will at least get you started writing database<br />

programs and enable you to use LINQ to query databases.<br />

Selecting a Database<br />

Because database applications are so important, a lot of companies have created databases and<br />

database tools. A small sampling of databases includes Microsoft SQL Server, Microsoft SQL Server<br />

Express, Microsoft Access, MySQL, MariaDB, PostgreSQL, SQLite, Oracle, SAP, dBASE, FoxPro,<br />

IBM DB2, LibreOffice Base, and FileMaker Pro. Some of these are expensive, whereas others are<br />

www.it-ebooks.info

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!