Download presentation
Presentation is loading. Please wait.
1
ASP.NET Database Connectivity I
2
2 © UW Business School, University of Washington 2004 Outline Database Concepts SQL ASP.NET Database Connectivity
3
3 © UW Business School, University of Washington 2004 What is a Database? Relational database – RDBMS Relational database is nothing but tables –Inter-related tables
4
4 © UW Business School, University of Washington 2004 Table Columns, attributes, fields, variables Rows, records, tuples Unique identify – primary key Rule: no order for attributed and records!
5
5 © UW Business School, University of Washington 2004 Properties of Tables No order for rows and columns No duplicate rows No duplicate columns Relational integrity –Must have primary key filled by meaningful values (Entity Integrity) –Must have reference foreign keys to link to something that is already there at referential table (Referential Integrity)
6
6 © UW Business School, University of Washington 2004 Primary Keys Primary Key –Uniqueness –Minimality – if key is composite, then no component of it can be eliminated without destroying the uniqueness property –Not allowed to accept nulls
7
7 © UW Business School, University of Washington 2004 SQL Computer language to process relational database Data definition language (DDL): –Create table, alter table, and so on –Used to define a table’s column, add or delete columns, and delete unneeded tables Data manipulation language(DML): –Insert into, update, delete, and select –Used to insert, update, delete, and retrieve data in a table
8
8 © UW Business School, University of Washington 2004 Creating and Dropping Tables CREATE TABLE tableName (field1 dataType, field2 dataType, …) CREATE TABLE tableName (field1 dataType PRIMARY KEY, field2 dataType, …) DROP TABLE tableName
9
9 © UW Business School, University of Washington 2004 Inserting Data Into a Table INSERT INTO TABLE tableName VALUES (value1, value2, …) or INSERT INTO TABLE tableName (field1, field2, …) VALUES ( value1, value2, …)
10
10 © UW Business School, University of Washington 2004 Updating Table Data UPDATE tableName SET field1=value1, fiedl2=value2, … WHERE conditions The WHERE clause gives the condition for selecting which rows (records) are to be updated in the table identified as tableName The SET keyword is followed by the field list to be updated If the WHERE clause is omitted, all rows in the table are updated
11
11 © UW Business School, University of Washington 2004 Deleting Records from a Table DELETE FROM tableName WHERE conditions –This deletes all rows that satisfy the WHERE clause in the statement –If there is no WHERE clause, then all rows in the table are deleted
12
12 © UW Business School, University of Washington 2004 Retrieving Data SELECT field1, field2, … FROM tableName WHERE conditions –The SELECT clause lists the fields retrieved in the query result, separated by commas –The FROM clause lists one or more table names to be used by the query –All fields listed in the SELECT or WHERE clauses must be found in one and only one of the tables listed in the FROM clause
13
13 © UW Business School, University of Washington 2004 An Access Example Select * from customers Select companyname, contactname, address, city From customers
14
14 © UW Business School, University of Washington 2004 It provides Excel-like user interface to display information from a database Syntax: Attributes: datasource – data source object … Methods: Databind() – binding the data from the datasource
15
15 © UW Business School, University of Washington 2004 Dataset Object A dataset object holds data from the DB on the server and is ready to be used to build an ASP.NET page.
16
16 © UW Business School, University of Washington 2004 Data Adapter Purpose: to retrieve a set of data from a data source and place it in a dataset. Instantiating a data adapter: –Dim dataAdapter As System.Data.IDbDataAdapter = New _ System.Data.OleDb.OleDbDataAdapter –Dim dataAdapter As New System.Data.OleDb.OleDbDataAdapter Property: –SelectCommand – statement to select records from DB –InsertCommand –DeleteCommand –UpdateCommand
17
17 © UW Business School, University of Washington 2004 OLE DB Command Purpose: command that can be executed Property: CommandText: SQL statement or procedure Connection: connection object
18
18 © UW Business School, University of Washington 2004 Six Steps to Connect to a DB Create a datagrid control Create a connection object Create a string text to hold SQL statement Create a OLE DB command object and define the SQL command and connection properties Create a data adapter object and define its command property Use the Fill() method to transfer data to data set object
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.