By Driss Zouak
Databases and Data Access
What’s the difference between a database
and a datastore?
There are several types of data stores: Flat files,
structured files (like XML Files) and databases
A Database is a particular type of datastore that
has table based structure. Today, most
databases are Relational Databases and are
based on an industry standard called SQL.
What is SQL?
It is a structured language and querying and
interacting with a relational database
Database has tables, which consist of rows
and columns. Very similar to an Excel sheet.
Another way to think of a table is that it is an
object, where each column is a property.
Every row is an instantiation of that with
particular values for each column.
Columns have a name and a datatype
You can have a special column that is used
for IDs, that automatically increments the id
to the next one every time you an add item
Come up with an example
Show how to build a database in
Access that has 2 tables, using a
So what can you do with a table?
Insert new rows into it
Update existing rows in it
Delete rows from it
Select rows from it
Select rows from it and another table,
either getting the union or the
insert into products (Product_Name, Product_Price)
values (‘Cheesies’, 5.45)
update products set product_name=‘Doritos’,
product_price = 3.25 where
Delete from products where product_name=‘Doritos’
Select * from products
Select * from products where product_price > 3.00
You can do a select that covers multiple tables, it’s
called a join.
We store the data that is read in a
A dataset can also hold XML
because it has a schema, like a
Show the BindXmlDataSet
What is ADO.NET
The set of classes for handling
So DataSets, and the database
pieces are all part of ADO.NET
So how do we get at the data?
We need a connection to the database
This is responsible for making sure we log into
the database properly (user id and password),
and that we connect to the right database
Then we need a command (insert, update, delete or
If we do a select, we will be getting data back, but
we have a choice
We can either get all of the data back that we asked
for now (using DataAdapter and DataSet) or we can
get a reader back (DataReader, which reads one row
at a time)
There are a couple of namespaces
that are important
System.Data – DataSet object
System.Data.SqlClient –for using SQL
System.Data.Oledb –for using most dbs
There are others as well, like
Let’s look at DBWebApplication
In a database, commands can be put
together into functions called stored
procedures, which you can call from
ADO.NET as well.
Add this to your web.config
Next Class will include
Error handling and Exception handling
Try and Catch
And making your own exceptions!
Create a database in Access
Create a table
Use Access to put data in the
Read it from a web page with a
Read it with a data adapter
Write data from your web page
back to the database