1 Introduction to Database Systems CSE 444 Lecture 06 SQL in C#, Project October 5, 2007.

Slides:



Advertisements
Similar presentations
Chapter Information Systems Database Management.
Advertisements

Introduction to Database Processing with ADO.NET.
Java Applets A lab course by Dr. Junaid Ahmed Zubairi SUNY Fredonia.
SUNY Morrisville-Norwich Campus-Week 12 CITA 130 Advanced Computer Applications II Spring 2005 Prof. Tom Smith.
Oracle SQL*plus John Ortiz. Lecture 10SQL: Overview2 Overview  SQL: Structured Query Language, pronounced S. Q. L. or sequel.  A standard language for.
® IBM Software Group © 2006 IBM Corporation The Eclipse Data Perspective and Database Explorer This section describes how to use the Eclipse Data Perspective,
PHP & MySQL Mahak Arora Vivek Bangera. Outline How PHP works Basic scripting in PHP Forms in PHP(GET & POST Variables) SQL basics PHP and MySQL connection.
From VS C# 2010 Programming, John Allwork 1 VS2010 C# Programming - DB intro 1 Topics – Database Relational - linked tables SQL ADO.NET objects Referencing.
CIS 270—App Dev II Big Java Chapter 22 Relational Databases.
Structured Query Language (SQL) A2 Teacher Up skilling LECTURE 2.
CSCI 6962: Server-side Design and Programming
CSE3310: Web training A JumpStart for Project.
CSCI 6962: Server-side Design and Programming JDBC Database Programming.
BIT 286: Web Applications Lecture 04 : Thursday, January 15, 2015 ASP.Net MVC - Models.
XP New Perspectives on Microsoft Office Access 2003 Tutorial 11 1 Microsoft Office Access 2003 Tutorial 11 – Using and Writing Visual Basic for Applications.
If This Bar Is Light Blue – It Is Info That You Should Read! Helpful Hint There Will Often Be A Colored Title Bar At The Top Of A Slide.
Software Engineering 2003 Jyrki Nummenmaa 1 CASE Tools CASE = Computer-Aided Software Engineering A set of tools to (optimally) assist in each.
CSCI3170 Introduction to Database Systems
ADO.NET A2 Teacher Up skilling LECTURE 3. What’s to come today? ADO.NET What is ADO.NET? ADO.NET Objects SqlConnection SqlCommand SqlDataReader DataSet.
PHP meets MySQL.
Database Programming Dr. John Abraham. Data Sources Data source specifies the source of the data for an application. Click on Data from Menu Choose show.
ADO.Net CS795. What is ADO.Net? Database language spoken by managed applications ADO.net database accesses go through modules: data providers –SQL Server.Net.
1 Working with MS SQL Server Textbook Chapter 14.
© FPT SOFTWARE – TRAINING MATERIAL – Internal use 04e-BM/NS/HDCV/FSOFT v2/3 Working with MSSQL Server Code:G0-C# Version: 1.0 Author: Pham Trung Hai CTD.
Introduction to MySQL Lab no. 10 Advance Database Management System.
Java Quiz Bowl A fun review of the Java you should know from CMPT 201 If you don’t know the answers - this week is for you to study up!
Chapter 8 Collecting Data with Forms. Chapter 8 Lessons Introduction 1.Plan and create a form 2.Edit and format a form 3.Work with form objects 4.Test.
© FPT SOFTWARE – TRAINING MATERIAL – Internal use 04e-BM/NS/HDCV/FSOFT v2/3 Working with Disconnected Data The DataSet and SqlDataAdapter ADO.NET - Lesson.
ASP.NET Rina Zviel-Girshin Lecture 5
Damian Tamayo Tutorial DTM Data Generator Fall 2008 CIS 764.
Financial Information Management Changing data in a DB Stefano Grazioli.
Christopher M. Pascucci.NET Programming: Databases & ADO.NET.
Agenda Object Oriented Programming Reading: Chapter 14.
Mauricio Featherman, Ph.D. Washington St. University
SQL John Nowobilski. What is SQL? Structured Query Language Manages Data in Database Management Systems based on the Relational Model Developed in 1970s.
Chapter Fourteen Access Databases and SQL Programming with Microsoft Visual Basic th Edition.
1 11/15/05CS360 Windows Programming ADO.NET Continued.
Task #1 Create a relational database on computers in computer classroom 308, using MySQL server and any client. Create the same database, using MS Access.
ADO.NET FUNDAMENTALS BEGINNING ASP.NET 3.5 IN C#.
1 Introduction to Database Systems CSE 444 Lecture 04: SQL April 7, 2008.
Java: Variables and Methods By Joshua Li Created for the allAboutJavaClasses wikispace.
Working with MySQL A290/A590, Fall /07/2014.
1 Working with MS SQL Server Beginning ASP.NET in C# and VB Chapter 12.
1 Lecture 05 Project: C#, ASP,.NET Friday, January 13, 2006.
Financial Information Management Modifying data in a DB Stefano Grazioli.
DAAD project “Joint Course on OOP using Java” Humboldt University Berlin, University of Novi Sad, ‘Polytehnica’ University of Timisoara, University of.
Retele de senzori Curs 2 - 1st edition UNIVERSITATEA „ TRANSILVANIA ” DIN BRAŞOV FACULTATEA DE INGINERIE ELECTRICĂ ŞI ŞTIINŢA CALCULATOARELOR.
CS 440 Database Management Systems Stored procedures & OR mapping 1.
Databases and SQL CSCI 201L Jeffrey Miller, Ph.D. HTTP :// WWW - SCF. USC. EDU /~ CSCI 201 USC CSCI 201L.
CS320 Web and Internet Programming SQL and MySQL Chengyu Sun California State University, Los Angeles.
Understand Data Definition Language (DDL) Database Administration Fundamentals LESSON 1.4.
Programming with Microsoft Visual Basic 2012 Chapter 14: Access Databases and SQL.
COM621: Advanced Interactive Web Development Lecture 10 PHP and MySQL.
1 Lecture 07 Project Wednesday, October 11, 2006.
Common SQL keywords. Building and using CASE Tools Data Base with Microsoft SQL-Server and C#
Introduction to Database Processing with ADO.NET
Introduction to Database Processing with ADO.NET
CS320 Web and Internet Programming SQL and MySQL
Chapter 12 Information Systems.
Information Systems Database Management
MS-Access (database) how to create blank data base.
Introduction to Database Systems CSE 444 Lecture 04: SQL
Introduction to Database Systems CSE 544
Tonga Institute of Higher Education
CMPT 354: Database System I
CS3220 Web and Internet Programming SQL and MySQL
These slides are for reference only. They are not "lecture notes"
CS3220 Web and Internet Programming SQL and MySQL
Lecture 06 SQL in C#, Project
M S COLLEGE OF ART’S, COMM., SCI. & BMS Advance Web Programming
Presentation transcript:

1 Introduction to Database Systems CSE 444 Lecture 06 SQL in C#, Project October 5, 2007

2 Outline SQL in C# –Read Chapter 8 –But note that it does not talk about C# Project Phase 1

3 C# - Crash Course Hello World Properties (getters/setters) Enums Partial classes Dataset: DataTable, DataRow Connecting to a database

4 C# - Highlights C# = C++ Sytnax + Java Semantics It is a “safe” language (like Java) Can be embedded in Webpages Can access a database –Complex, but you should see the predecessors !

5 using System; class Hello { static void Main() { Console.WriteLine("Hello world"); } using System; class Hello { static void Main() { Console.WriteLine("Hello world"); } Hello World

6 public class Point { private int x; private string c; public int position { get { return x; } set { x = value; c = “red”; } } public string color { get { return c; } set { c = value; x++; } } public class Point { private int x; private string c; public int position { get { return x; } set { x = value; c = “red”; } } public string color { get { return c; } set { c = value; x++; } } Properties: Getters and Setters Point uvw = new Point(); uvw.position = 55; uvw.color = “green”; uvw.position = uvw.position * 2; if (uvw.color == “green”) … Point uvw = new Point(); uvw.position = 55; uvw.color = “green”; uvw.position = uvw.position * 2; if (uvw.color == “green”) …

7 Indexers Getters and setters with […] public class Stuff { private int x[]; public int this[int i] { get {x[2*i+1]=0; return x[2*i]; } set { x[2*i] = value; x[2*i+1]=1; } } public class Stuff { private int x[]; public int this[int i] { get {x[2*i+1]=0; return x[2*i]; } set { x[2*i] = value; x[2*i+1]=1; } } Stuff uvw = new Stuff(); uvw[12] = 55; uvw[99] = uvw[12]*7 + 2; Stuff uvw = new Stuff(); uvw[12] = 55; uvw[99] = uvw[12]*7 + 2;

8 enum Color: byte { Red = 1, Green = 2, Blue = 4, Black = 0, White = Red | Green | Blue, } enum Color: byte { Red = 1, Green = 2, Blue = 4, Black = 0, White = Red | Green | Blue, } Enum

9 Partial Classes Some fields defined in file 1 Other fields defined in file 2 Why ? We create file 1, you create file 2

10 The DataSet Class This is an important class that allows you to interact with a database DataSet = a “mini” database (cache) in main memory DataTable DataRow

11 DataSet myLocalDB = new DataSet(); /* create inside a table called “books” */..... /* (this is shown on a following slide) */ /* now use “books” */ DataTable x = myLocalDB.Tables[“books”] foreach (DataRow y in x.Rows) { if (y[“title”] == “Harry Potter”) y[“price”]++;; } DataSet myLocalDB = new DataSet(); /* create inside a table called “books” */..... /* (this is shown on a following slide) */ /* now use “books” */ DataTable x = myLocalDB.Tables[“books”] foreach (DataRow y in x.Rows) { if (y[“title”] == “Harry Potter”) y[“price”]++;; } DataSet

12 Connecting to a Database Create or edit web.config file –Specify iisqlsrv, user, password –Give a ‘name’ Create a SqlConnection –refer to ‘name’ Create a SqlDataAdaptor –embed SQL query string Execute the Fill( ) method to run query and store answers in a datarow

13 /* create inside a table called “books” */ SqlConnection c = new SqlConnection(... “name”...); string q = “select title, price year from products where price < 100”; SqlDataAdapter a = new SqlDataAdapter(q, c); DataSet myLocalDB = new DataSet(); a.Fill(myLocalDB, “books”); /* create inside a table called “books” */ SqlConnection c = new SqlConnection(... “name”...); string q = “select title, price year from products where price < 100”; SqlDataAdapter a = new SqlDataAdapter(q, c); DataSet myLocalDB = new DataSet(); a.Fill(myLocalDB, “books”); Connecting to a Database SQL = a string !!! “impedance mismatch”

14 Phase 1 Task 1: Schema design Task 2: Import sample data Task 3: Modify starter code

15 Task 1: Schema Design Official requirement Read the project description Design a “good” database schema

16 Task 1: Schema Design Optional: draw an E/R diagram Create a file: Create a second file: (why ?) CREATE TABLE Customer (... ) CREATE TABLE Invoice (... )... CREATE TABLE Customer (... ) CREATE TABLE Invoice (... )... DROP TABLE Customer DROP TABLE Invoice... DROP TABLE Customer DROP TABLE Invoice...

17 Task 1: Schema Design What you should do: Read description AND look inside the starter code App_code/Provided/… Read the classes, determine the fields…

18 Task 1: Schema Design Things to worry about: Keys/foreign keys: note table order matters! Make sure you represent all the data Null-able or not (don’t worry too much) Things not to worry about: fname or FirstName or PersonFirstName ? varchar(20) or char(200) or varchar(120) ?

19 Task 2: Import Sample Data Create a file: You may need to run this: (why ?) INSERT INTO Customer (... ) VALUES (‘John’, ….) INSERT INTO Customer (... ) VALUES (‘Sue’, ….)... INSERT INTO Customer (... ) VALUES (‘John’, ….) INSERT INTO Customer (... ) VALUES (‘Sue’, ….)... DROP TABLE Customer DROP TABLE Invoice... DROP TABLE Customer DROP TABLE Invoice...

20 Task 3: Modify Starter Code The starter code: C# ASP.NET (you do not need to understand it) It provides a Website for accessing your online store BUT it misses the fragments of code that get the data from the database See

21 Task 3: Modify Starter Code What you have to do: App_Code/Phase1/Billing and Shipping/… Public partial class Customer { /* add your own fields, like: */ private int id, Procedure List GetInvoices() { /* your GetInvoices code goes here */ } Public partial class Customer { /* add your own fields, like: */ private int id, Procedure List GetInvoices() { /* your GetInvoices code goes here */ }

22 Task 3: Modify Starter Code /* your GetInvoices code goes here */ string s = … FROM …. WHERE x.customerId = {0} …”, id); StoreContext store = StoreContext.current; DataSet ds = new DataSet( ); DataTable invoices = store.GetDataTable(s, ds, “invoices”); /* continued on next slide…. */ /* your GetInvoices code goes here */ string s = … FROM …. WHERE x.customerId = {0} …”, id); StoreContext store = StoreContext.current; DataSet ds = new DataSet( ); DataTable invoices = store.GetDataTable(s, ds, “invoices”); /* continued on next slide…. */ Substitutes id for {0} Defined in Provided

23 Task 3: Modify Starter Code /* … continued from previous slide */ List invoiceList new List ( ); foreach(datarow r in invoices.Rows) { invoiceList.Add(new Invoice( r )); } return invoiceList; } /* … continued from previous slide */ List invoiceList new List ( ); foreach(datarow r in invoices.Rows) { invoiceList.Add(new Invoice( r )); } return invoiceList; } Now you need to implement this

24 Task 3: Modify Starter Code public partial class Invoice { public Invoice(DataRow invoiceData) { /* here goes your code, something like that: */ init(invoiceData); /* may need it in several places */ }.. private void init(DataRow invoiceData) { invoiceId = (int) invoiceData[“invoiceId”]; orderDate = (DateTime) invoiceData[“date”];..... public partial class Invoice { public Invoice(DataRow invoiceData) { /* here goes your code, something like that: */ init(invoiceData); /* may need it in several places */ }.. private void init(DataRow invoiceData) { invoiceId = (int) invoiceData[“invoiceId”]; orderDate = (DateTime) invoiceData[“date”];..... In Provided In you SQL

25 Time Estimate Task 1: about 9 tables or so –2 hours or more Task 2: try 2 tuples per table –1 hour Task 3: –Need to find out WHAT to modify in starter code –May need to DROP TABLEs then go to Task 1 –Total time here: anywhere from 2 to 14