UNIT 9.2: Learning Objectives Agile Development – Bruce Feiler on Agile Programming Database access from code – Database Cycle Review – SQL Command Types.

Slides:



Advertisements
Similar presentations
User Controls, Master Pages, GridView. Content User Controls Styles, Themes, Master Pages Working with Data GridView Muzaffer DOĞAN - Anadolu University2.
Advertisements

MIS 3200 – Unit 4 Complex Conditional Statements – else if – switch.
Access - Project 1 l What Is a Database? –A Collection of Data –Organized in a manner to allow: »Access »Retrieval »Use of That Data.
Let’s try Oracle. Accessing Oracle The Oracle system, like the SQL Server system, is client / server. For SQL Server, –the client is the Query Analyser.
Guide to Oracle10G1 Introduction To Forms Builder Chapter 5.
J4www/jea Week 3 Version Slide edits: nas1 Format of lecture: Assignment context: CRUD - “update details” JSP models.
Chapter 12: ADO.NET and ASP.NET Programming with Microsoft Visual Basic.NET, Second Edition.
A Guide to Oracle9i1 Introduction To Forms Builder Chapter 5.
ASP.NET Database Connectivity I. 2 © UW Business School, University of Washington 2004 Outline Database Concepts SQL ASP.NET Database Connectivity.
Coding ADO.NET Objects: Connection, Command, DataReader.
ASP.NET Programming with C# and SQL Server First Edition Chapter 8 Manipulating SQL Server Databases with ASP.NET.
Chapter 14: Advanced Topics: DBMS, SQL, and ASP.NET
A Guide to MySQL 3. 2 Objectives Start MySQL and learn how to use the MySQL Reference Manual Create a database Change (activate) a database Create tables.
Chapter 7 Managing Data Sources. ASP.NET 2.0, Third Edition2.
Figure 1. Hit analysis in 2002 of database-driven web applications Hits by Category in 2002 N = 73,873 Results Reporting 27% GME 26% Research 20% Bed Availability.
Stored Procedures Dr. Ralph D. Westfall May, 2009.
Copyright 2007, Information Builders. Slide 1 Maintain & JavaScript: Two Great Tools that Work Great Together Mark Derwin and Mark Rawls Information Builders.
MIS 3200 – Unit 6.2 Learning Objectives How to move data between pages – Using Query Strings How to control errors on web pages – Using Try-catch.
A Guide to SQL, Eighth Edition Chapter Three Creating Tables.
Database Processing with JSP ISYS 350. Example: Enter CID in a box and retrieve the customer record.
Programming with Microsoft Visual Basic 2012 Chapter 13: Working with Access Databases and LINQ.
Unit 8.2 Learning Objectives How data can be used – The Money Ball Example The Money Ball Example Data Warehouses – The Role of Data Warehouses The Role.
ASP.NET Programming with C# and SQL Server First Edition
UNIT 9.2 Learning Objectives A Real world Application of Databases – The Money Ball Example The Money Ball Example Data Warehouses – The Role of Data Warehouses.
CIS 375—Web App Dev II ASP.NET 10 Database 2. 2 Introduction to Server-Side Data Server-side data access is unique in that Web pages are basically ___________.
Needs for Accessing Database To make your web site more dynamic and maintainable, you can display information on your web pages that are retrieved from.
1 Data Bound Controls II Chapter Objectives You will be able to Use a Data Source control to get data from a SQL database and make it available.
Database Processing with JSP ISYS 350. Example: Enter CID in a box and retrieve the customer record.
Unit 8.3 Learning Objectives Insert users into the ASP.NET Membership system from code Capture data being sent to the database Capture Exceptions that.
U:/msu/course/cse/103 Day 06, Slide 1 CSE students: Do not log in yet. Review Day 6 in your textbook. Think about.
CSCI 6962: Server-side Design and Programming Database Manipulation in ASP.
Sample Application Multi Layered Architecture (n-tier): –Graphical User Interface (GUI): Forms, components, controls The Visual Designer in Visual Studio.
ASP.NET The Clock Project. The ASP.NET Clock Project The ASP.NET Clock Project is the topic of Chapter 23. By completing the clock project, you will learn.
Chapter Thirteen Working with Access Databases and LINQ Programming with Microsoft Visual Basic th Edition.
Command Object’s ExecuteNonQuery Method ISYS 512.
1 CS 3870/CS 5870: Note05 Prog3 Web Application with Database.
DBT544. DB2/400 Advanced Features Level Check Considerations Database Constraints File Overrides Object and Record Locks Trigger Programs.
Microsoft FrontPage 2003 Illustrated Complete Integrating a Database with a Web Site.
Mr. Justin “JET” Turner CSCI 3000 – Fall 2015 CRN Section A – TR 9:30-10:45 CRN – Section B – TR 5:30-6:45.
Database Processing with JSP ISYS 350. Example: Enter CID in a box and retrieve the customer record.
Introduction to KE EMu Unit objectives: Introduction to Windows Use the keyboard and mouse Use the desktop Open, move and resize a.
8 Chapter Eight Server-side Scripts. 8 Chapter Objectives Create dynamic Web pages that retrieve and display database data using Active Server Pages Process.
Coding ADO.NET Objects: Connection, Command, DataReader.
MIS 3200 – Unit 5.1 Iteration (looping) – while loops – for loops Working with List Items.
Architecture Multi Layered Architecture (n-tier): Application: Model Controllers Database Access Graphical User Interface (GUI): Forms, components, controls.
Using ADO.Net to Build a Login System Dr. Ron Eaglin.
1 CS 3870/CS 5870: Note07 Prog 4. Master Pages Creating a master page based on another master page MainMasterPage –For all Progs and Tests Prog4MasterPage.
1 CS 3870/CS 5870: Note07 Prog 4. Master Pages Creating a master page based on another master page MainMasterPage –For all Progs and Tests Prog4MasterPage.
Starting with Oracle SQL Plus. Today in the lab… Connect to SQL Plus – your schema. Set up two tables. Find the tables in the catalog. Insert four rows.
Constraints Review. What is a constraint? Unique – forbids duplicate values Referencial – Foreign key Check Constraint – sets restrictions on data added.
Database Processing with JSP ISYS 350. Example: Enter CID in a box and retrieve the customer record.
Chapter 5 Introduction To Form Builder. Lesson C Objectives  Use sequences to automatically generate primary key values in a form  Create lists of values.
Unit 8.2 Learning Objectives Data Warehouses – The Role of Data Warehouses The Role of Data Warehouses – Group Exercise Accessing Data in Views – Accessing.
Creating Web Pages with Links, Images, and Embedded Style Sheets
Database Processing with JSP ISYS 350. Database Applications Applications Database Server Queries/Updates Results.
Copyright © 2014 Pearson Canada Inc. Ext. 5b-1 Copyright © 2014 Pearson Canada Inc. Application Extension 5b Using Microsoft Access Part 2: Using Information.
1 Adding a Model. We have created an MVC web app project Added a controller class. Added a view class. Next we will add some classes for managing movies.
Visual Basic.NET Comprehensive Concepts and Techniques Chapter 11 Creating Web Applications and Writing Data to a Database.
Common SQL keywords. Building and using CASE Tools Data Base with Microsoft SQL-Server and C#
ASP.NET Programming with C# and SQL Server First Edition
Creating Data Base & Sql Data Source
Unit 9.1 Learning Objectives Data Access in Code
Unit 8.1: Introducing Databases
Unit 8.2 How data can be used Accessing Data in Views
Unit 9.2 Database access from code Database Cycle Review
MIS 3200 – Unit 4 Complex Conditional Statements else if switch.
Unit 9.3 Learning Objectives Review database access in code
Creating Data Base & Sql Data Source
PROG Advanced Web Apps 4/13/2019 Programming Data Pages Wendi Jollymore, ACES.
MIS 3200 – Unit 5.1 Iteration (looping) Working with List Items
Presentation transcript:

UNIT 9.2: Learning Objectives Agile Development – Bruce Feiler on Agile Programming Database access from code – Database Cycle Review – SQL Command Types – Group Exercise on SELECT (Unit 9.1) – INSERT, UPDATE, DELETE – Putting it all together: Execution – Hands on Activity

Agile Programming Based on Bruce Feiler’s video, list at least five characteristics on Agile Programmingvideo

lblOutput.Text= myReader[0].Text csFees…connectionString cmdFees…SQLcommand ["1",“Registration Fee",5.00,”2”, “Vehicle License Fee",7.5,”3”, “Weight Fee“, ] Accessing Data Database server e.g. MS SQL Server SQL SQL DataSource -Connection -Command Views Browser e.g. FireFox Web server e.g. Windows Server HTML ASPX

The Five Grand Steps to Database Access in Code 1.Get READY Add namespaces 2.WHERE the database is Create a Connection String (name, path) 3.WHAT needs to be done Create a Command Object (SQL) 4.EXECUTE! Execute the Command and output data stream into a Reader 5.Loop through the Reader and read the data "1",“Registration Fee",5.00, ”2”, “Vehicle License Fee",7.50, ”3”, “Weight Fee“, csFees myCommand For commands that do not CHANGE the database

SQL Command Types Based on whether or not they AFFECT the database A.SELECT B.INSERT, UPDATE, or DELETE Images source: artistitvalley.com

Handling SELECT commands SELECT commands output data Temporary holder: SqlDataReader The reader needs to be looped through SqlConnection myConnection = new SqlConnection(strConnection); SqlCommand myCommand = new SqlCommand(strSql, myConnection); SqlDataReader myReader = myCommand.ExecuteReader();

Group Exercise string strConnection = ConfigurationManager.ConnectionStrings["cs3200"].ToString(); SqlConnection myConnection = new SqlConnection(strConnection); string strSql = "SELECT [FeeDescription], [Fee] FROM Fees ORDER BY [FeeDescription]"; SqlCommand myCommand = new SqlCommand(strSql, myConnection); myConnection.Open(); SqlDataReader myReader = myCommand.ExecuteReader(); while (myReader.Read()) { string strDescription = myReader[“FeeDescription”].ToString(); decimal decFee = Convert.ToDecimal(myReader[“Fee”]); lblFees.Text += strDescription + " at " + decFee.ToString("C2") + " "; } myReader.Close(); myConnection.Close();

INSERT commands Adds new records to the database Syntax: Best Practices – Include the primary key, unless the primary key is an Identify – Include all fields that don’t allow nulls & have default values – Include any foreign keys – Ensure data to be in the correct data type INSERT INTO tableName (list_of_fields) VALUES (list_of_values) comma separated, enclosed in [ ] in the same order as fields

UPDATE Commands Used to modify existing database records Syntax Best Practice: – Don’t update the primary key – Use the primary key to Identify a single record – Ensure compliance with records that don’t allow nulls – Ensure compliance with foreign keys – Not using a WHERE clause will update all records in the table – If no records are updated, it is because no records qualified UPDATE tableName SET field1=value1 [, …] WHERE fieldX =Y One or more values Which record to update

DELETE Commands Used to remove records from the database Syntax Best Practice: – Omitting the WHERE clause will delete all records in the table – If no records are deleted, it is because no records qualified – Cannot delete records on the ONE side of a 1-to-many relationship – Always confirm a delete actions DELETE FROM tableName WHERE condition

The Execution - Step #4 Use.ExecuteNonQuery(), instead of.ExecuteReader() Syntax: Best Practice: – Syntax for the command and connection object are unchanged – In SQL: use parameters for any data coming from TextFields – Assign values to the parameters – Counter estimates whether the command was successful – Question: What if intCnt =0? int intCnt = myCommand.ExecuteNonQuery(); Number of records affected

Execution i.e. Step #4 (in Code) string strConnection = ConfigurationManager.ConnectionStrings["cs3200"].ToString(); SqlConnection myConnection = new SqlConnection(strConnection); string strSql= "INSERT INTO OUCourses SqlCommand myCommand = new SqlCommand(strSql, myConnection); string strCName = txtCName.Text; System.Data.SqlDbType.NVarChar, 50).Value = strCName; int intCNum = Convert.ToInt32(txtHrs.Text); System.Data.SqlDbType.int).Value = intCNum; int intHrs = Convert.ToInt32(txtHrs.Text); System.Data.SqlDbType.int).Value = intHrs; int intCnt =-1 myConnection.Open(); int intCnt = myCommand.ExecuteNonQuery(); if (intCnt = 0) lblInsert.Text = “One Records was added"; Else lblInsert.Text = “No records were added"; myConnection.Close(); 1 2 3a 4 3b

L2: Hands-on For this exercise we are going to add new fees to the fee table using code 1.Create a new page in your Unit9 folder and call it lastNameU9L2.aspx Be sure that “Please code in separate file” and “Select master page” are checked Add your name and assignment information to the page title 2.Add the following H2 heading to the page INSERTING AND UPDATING DATA FROM CODE

U9L Under the H2 heading and an H3 heading THE FOLLOWING FEES ARE CURRENTLY RECORDED: 4.Add a GridView under the H3 heading 5.Create a SQL DataSource for the GridView Select the fees table you created in Unit8 Select both the FeeDescription and the Fee fields No WHERE and no Advanced features 6.Select a nice format for the GridView and add a Select link (we won’t use it in this exercise but we will use it in U9L2.2)

U9L Below the DataSource, add an H3 title that says ADD A NEW FEE: 8.Below that add The text “New Fee Description” A TextBox named txtFeeDescription A required field validator 9.Below that add The text “New Fee:” A TextBox named txtFee A required field validator Another validator to make sure the number is a positive decimal number

U9L Below that add a button Change the name to btnAdd Change the text to Add new fee 11.Below the button and a Label named lblIsert 12.Below the button and a validation summary Put all the validators, the button and the validation summary in the same validation group Set the validation summary to use the popup window

U9L Double click the button to create a method – Add the database and configuration namespaces at the top of the page – Create a connection object in the new method (exactly the same as in the Unit8 exercises) – Create a string with the following SQL statement – Create a new command object using this SQL string and your connection object – Add parameters to the command object that assign values to the two parameters used in the SQL This works exactly the same was as what you did to create a WHERE clause parameter in Unit 8

U9L2 - 6 – Create a try/catch block – Inside the try Open the connection Enter the following line of code On the following line, check to see if intCnt is >1 (that means that at more than one record was inserted) – If that is true, display the value of intCnt and a message saying “ records were added” – If intCnt isn't’ > 1, display a message saying that one record was inserted Close the connection Close the try block

U9L2 - 7 – Write the catch statement in the form – Inside the catch block, write a message to the label saying you were unable to insert the record and then display the standard Exception message found in ex.Message – Close the catch block – Close the connection again (in case there was an exception) – Databind the GridView – Set the SelectedIndex of the GridView to -1 – Clear the text boxes

U9L Test your page to be sure you can insert new fees 15.Link the page to your portfolio page 16.Upload your ASPPub to ASPNET 17.Put a link to your portfolio page in the dropbox AFTER you test to be sure that everything still works correctly on ASPNET