Unit 9.3 Learning Objectives Review database access in code

Slides:



Advertisements
Similar presentations
JQuery MessageBoard. Lets use jQuery and AJAX in combination with a database to update and retrieve information without refreshing the page. Here we will.
Advertisements

MIS 3200 – Unit 4 Complex Conditional Statements – else if – switch.
Asp.NET Core Server Controls. Slide 2 Lecture Overview Understanding the types of ASP.NET controls HTML controls ASP.NET (Web) controls.
A Guide to Oracle9i1 Introduction To Forms Builder Chapter 5.
ASP.NET Programming with C# and SQL Server First Edition Chapter 8 Manipulating SQL Server Databases with ASP.NET.
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.
Database Updates Made Easy In WebFocus Using SQL And HTML Painter Sept 2011 Lender Processing Services 1.
BIM211 – Visual Programming Database Operations II 1.
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.
BİL528 – Bilgisayar Programlama II Database Operations II 1.
Creating a Web Site to Gather Data and Conduct Research.
Ts_print in a few easy steps There are four screens: Entities, Data Items, Date, and Report Format.
PHP meets MySQL.
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 ___________.
UNIT 9.2: Learning Objectives Agile Development – Bruce Feiler on Agile Programming Database access from code – Database Cycle Review – SQL Command Types.
MIS 3200 – Unit 4.2 ListItem controls – CheckBoxList – ListBox.
Microsoft Visual Basic 2005 CHAPTER 7 Creating Web Applications.
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.
MIS 3200 – Unit 3 What can computers do – Follow a sequence of instructions – Follow different paths of instructions based on decisions – Do things over.
 Whether using paper forms or forms on the web, forms are used for gathering information. User enter information into designated areas, or fields. Forms.
Database Systems Microsoft Access Practical #3 Queries Nos 215.
1 Chapter 12 – Web Applications 12.1 Programming for the Web, Part I 12.2 Programming for the Web, Part II 12.3 Using Databases in Web Programs.
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.
MIS 3200 – Unit 5.3 Manipulating ListItem controls – Moving ListItems between ListItem controls – Removing ListItems from ListItem controls.
22 November Databases. Presentations Tega: news 1954 Prediction.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Outline 25.1 Test-Driving the ATM Application 25.2.
8 Chapter Eight Server-side Scripts. 8 Chapter Objectives Create dynamic Web pages that retrieve and display database data using Active Server Pages Process.
ADO.NET FUNDAMENTALS BEGINNING ASP.NET 3.5 IN C#.
MIS 3200 – Unit 5.1 Iteration (looping) – while loops – for loops Working with List Items.
Mr. Justin “JET” Turner CSCI 3000 – Fall 2015 CRN Section A – TR 9:30-10:45 CRN – Section B – TR 5:30-6:45.
Using ADO.Net to Build a Login System Dr. Ron Eaglin.
MSOffice Access Microsoft® Office 2010: Illustrated Introductory 1 Part 1 ® Database & Table.
Unit 8.2 Learning Objectives Data Warehouses – The Role of Data Warehouses The Role of Data Warehouses – Group Exercise Accessing Data in Views – Accessing.
21/03/ Working with Controls Text and List Boxes.
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
Y.-H. Chen International College Ming-Chuan University Fall, 2004
Unit 7 Learning Objectives
Unit 9.1 Learning Objectives Data Access in Code
Practical Office 2007 Chapter 10
Data Environment and Grouped Report
Building a User Interface with Forms
Objectives Create an action query to create a table
Incorporating Databases with ADO.NET
Current outstanding balance
Unit 8.2 How data can be used Accessing Data in Views
Unit 9.2 Database access from code Database Cycle Review
Building Configurable Forms
MIS 3200 – Unit 3 What can computers do
Active Orders Supplier Administrator Training Getting Started Activities This training presentation describes the Getting Started activities that will.
Incorporating Databases with ADO.NET
Unit 27 - Web Server Scripting
MIS 3200 – Unit 4 Complex Conditional Statements else if switch.
Conditions and Ifs BIS1523 – Lecture 8.
MIS 3200 – Unit 5.2 ListItem controls and accumulation
Sirena Hardy HRMS Trainer
In Class Programming BIS1523 – Lecture 11.
Microsoft Office Access 2003
Access: Queries IV Participation Project
Adding Record To Your Database
Access: Queries I Participation Project
PROG Advanced Web Apps 4/13/2019 Programming Data Pages Wendi Jollymore, ACES.
MIS 3200 – Unit 5.1 Iteration (looping) Working with List Items
MIS 3200 – Unit 6.1 Moving between pages by redirecting
Group Boxes, Radio buttons and Checked List Boxes
Assignment resource Working with Excel Tables, PivotTables, and Pivot Charts Fairhurst pp The commands on these slides work with the Week 2 Excel.
Tutorial 9 Using Action Queries and Advanced Table Relationships
Lecture Set 10 Windows Controls and Forms
Presentation transcript:

Unit 9.3 Learning Objectives Review database access in code Using Multi-Views to Display Data Hands on exercise: U9L22

Data Access in Code

The Five Grand Steps to Database Access in Code Get READY Add namespaces WHERE the database is Create a Connection String (name, path) WHAT needs to be done Create a Command Object (SQL) EXECUTE! Execute the Command and output data into an int Evaluate the number of records affected csFees myCommand GUI controls allow us to do a great deal but they can’t do everything .NET provides a number of objects that allow us to perform database manipulation in code The database objects are collected into three Namespaces A namespace is a way to uniquely identify a set of programming objects int intCnt = myCommand.ExecuteNonQuery(); For commands that CHANGE the database if (intCnt == 1) lblInsert.Text = “One Records was added"; else lblInsert.Text = “No records were added";

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

Multiview A set of areas whose visibility can be turned on and off to suit needs of the web page. Based on conditions Only on view is visible at a time Visible view is called the ActiveView Other Views can be added to it. Uses indices E.g. ActiveViewIndex

Multiview – Creating Drag a MultiView control to the web page and then Drag one or more Views into the MultiView Name the MultiView use the prefix “mv” Name the Views use the prefix “v” ActiveViewIndex is used to display the desired View ActiveViewIndex is set to -1 to hide all views

Unit 9 – L2.2 For this exercise you are going to make a copy of your U9L2 application and call it lastnameU9L22 Open the page in Design view and add two blank lines after the data source that feeds the GridView Copy a MultiView to the second blank line and change its ID to mvFees Click inside mvFees and press Enter three times Copy a View to the first line in mvFees and change its ID to vAdd

U9L2.2 - 2 Copy another view to the second line in mvFees and change its ID to vUpdate Copy a third view to the third line in mvFees and change its ID to vDelete Click on the mvFees header, look at the properties of the multiview and set the ActiveViewIndex to -1 (meaning, don’t show any view) Your views should look something like this

U9L2.2 - 3 Copy a RadioButtonList to the line before mvFees Change the ID to rblDatabaseRequests Add three ListItems to the radio button lists Change the Text and Value of the items to Add, Update and Delete Select rblDatabaseRequests and checkEnableAutoPostBack Double click rblDatabaseRequests to create a method that will change the active view Add the code to change the method based on which radio button was selected

U9L2.2 – 4: Move in Add Functionality Select all the text, text boxes, buttons and validation controls you used in the L2 assignment and copy them into vAdd

U9L2.2 – 5: Set up Update Click in vUpdate and add text, text boxes, a button and validation similar to those found in vAdd Call the text boxes txtFeeDescription2 and txtFee2 Put all the validators in one group, different from the validation group used in vAdd

U9L2.2 – 6: Update Functionality The record to update in vUpdate must come from the selected row in the GridView, when the user selects a fee. Double click on the GridView to create the gvFees_SelectedIndexChanged method Write the code shown below to copy the fee description and fee from the grid view to the appropriate text boxes. Fill in appropriate cell indices.

U9L2.2 - 7 What is the index of the Update command in the RBL? If this index is selected, then before changing the ActiveViewIndex, confirm that a selection was made in the GridView. If no selection was made then set the label message to remind the user to select a fee from the table. In this case, also reset the selections of the RBL and the active views.

U8L2.2 - 8 Since we will need the FID in order to run the update command, reconfigure the SDS to include it. Change its visibility to false to reduce apparent changes. Double click the Update button and write code (If it reverts to the btnAdd method, delete that from the events list) Create a connection Create a command to update the fee description and fee of the record selected in the grid view Open the connection execute the command display the number of records update display any appropriate error messages Close the connection

U8L2.2 - 9 The code should look something like this

U9L2.2 – 10: Delete functionality As before, the item needs to be selected in the GridView Add the message, ARE YOU SURE YOU WANT TO DELETE THE SELECTED RECORD, to the top area of vDelete Follow that with a RadioButtonList Set the ID to rblDelete Add two ListItems with values Yes and No Double click the rblDatabaseRequest radio button list and locate the code that checks for a SelectedIndex of 2 (Delete)

U9L2.2 - 11 Add code similar to what you have in the Update section – check to be sure a item is selected Double click rblDelete and write code to checks if rblDelete.SelectedIndex is 0 (yes, delete the record). Otherwise, state that no records were deleted and reset the Selected Indices for the RBL: Yes/No, RBL: data request, GV & MV

U9L2.2 - 12 Modify your portfolio page to link to your U8L2.2 assignment Copy your ASPPub back to ASPNET TEST, TEST, TEST to be sure all functions work correctly from ASPNET Submit the link to your portfolio page in the dropbox.