Docstoc

data access

Document Sample
data access Powered By Docstoc
					   Class 10
By Driss Zouak
Agenda
   Databases and Data Access
   Lab
Data!
   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
Databases
   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
Databases
   Come up with an example
   Show how to build a database in
    Access that has 2 tables, using a
    primary key
Databases
   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
      intersection
Databases
   For example
insert into products (Product_Name, Product_Price)
    values (‘Cheesies’, 5.45)
update products set product_name=‘Doritos’,
    product_price = 3.25 where
    product_name=‘Cheesies’
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.
DataSets
   We store the data that is read in a
    dataset
   A dataset can also hold XML
    because it has a schema, like a
    database
   Show the BindXmlDataSet
    example
What is ADO.NET
   The set of classes for handling
    data
   So DataSets, and the database
    pieces are all part of ADO.NET
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
    select)
   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)
ADO.NET
   There are a couple of namespaces
    that are important
       System.Data – DataSet object
       System.Data.SqlClient –for using SQL
        Server
       System.Data.Oledb –for using most dbs
       There are others as well, like
         System.Data.Oracle
         System.Data.ODBC
         System.Data.MySQL
ADO.NET
   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
   Page_Error, Application_Error
   Try and Catch

   And making your own exceptions!
Lab
   Create a database in Access
   Create a table
   Use Access to put data in the
    table
   Read it from a web page with a
    data reader
   Read it with a data adapter
   Write data from your web page
    back to the database

				
DOCUMENT INFO
Shared By:
Categories:
Tags:
Stats:
views:0
posted:9/23/2011
language:English
pages:14