Programming in Visual Basic 2010: The Very Beginner's Guide: Linq To SQL
Programming in Visual Basic 2010: The Very Beginner's Guide: Linq To SQL
Chapter 14.1
LINQ to SQL
Databases – Part 1
by Jim McKeown
You will learn how to…
2
LINQ to SQL
The world runs on databases
Relational database:
a database with multiple tables and relationships
between tables
Database management system:
4 a database and the software to manage it
Background
Key fields
a field shared by two or more tables in a
database; key fields are the link between tables
in a relational database
5 like, ssan in one table; ssan in a second table.
Background
Database manager:
a person who manages and maintains
databases; not as cool as a programmer, but
almost
6
Background
• In VB, Data Manipulation handled by Language-Integrated Query
(LINQ) and Structured Query Language (SQL); called LINQ to
SQL
• SQL is the language of most databases
• Language-Integrated Query (LINQ) -
• programming implementation that allows SQL
statements to be integrated into a VB program
• Structured Query Language (SQL)
• a database development language that allows for the searching, filtering,
organizing and reports of records from a database
• So, the database stores the data and your VB program provides
the interface to see the data.
• LINQ to SQL:
• the implementation of SQL statements into a program
using the tools available in .NET;
• a seamless way to connect to a database
• Query
• Search into a database;
• Queries
• Return specified fields from selected records, and
• Display them in a specific order
8 •
Background
• Queries determine
• what tables to use
• what records are requested
• what fields in the record to retrieve
• the conditions used to search through the data
10
Connecting to a Database Tutorial
Connecting to a Database
11 Converting to the Database Grid is done for us.
Connecting to a Database Tutorial
• Use NEC.mdb database for the tutorial
• Copy it to your computer and put it in a place
that’s easy to find
• Desktop is fine.
• Open and inspect it but close it before starting the
tutorial
14
Connecting to a Database Tutorial
16
Connecting to a Database Tutorial
Click on link to
Add Project Data Source...
Data Source
Configuration
Wizard
Select
Database;
Click Next
button
19
Connecting to a Database Tutorial
20
Connecting to the Database Tutorial
DataSet:
• A place in memory that holds database records for quick and easy access in a
program;
• A DataSet stores changes, additions and deletions until they are sent back to
update the database
21
Connecting to a Database Tutorial
Data Source
Configuration
Wizard
Click on
New
Connection
22
Connecting to a Database Tutorial
Next two slides together.
Select source of your database
Select Microsoft Access (have other choices…)
Add
Connection
Dialog
26
Connecting to a Database Tutorial
27
Connecting to a Database Tutorial
Local Connection
Warning Dialog
28
Connecting to a Database Tutorial
29
Connecting to a Database Tutorial
Save
Connection
String
Dialog
30
Connecting to a Database Tutorial
Next two slides together
12. Select the Database Objects for the DataSet
Last step (Step 11 in your book)
Determines tables and fields available when your
program runs
Choose
Your
Database
Objects
Screen
See
expansions
32
Connecting to a Database Tutorial
Summary:
34