ITS 328 CHAPTER 3: STORING DATA IN MEMORY 1. Storing Data in Memory After today you will be able to: ◦Explain how a DataTable stores data ◦Add new data.

Slides:



Advertisements
Similar presentations
Database Basics. What is Access? Database management system Computer-based equivalent of a manual database Makes it easy to organize and update information.
Advertisements

MS-Access XP Lesson 1. Introduction to MS-Access Database Management System Software (DBMS) Store data in databases Database is a collection of table.
The Librarian Web Page Carol Wolf CS396X. Create new controller  To create a new controller that can manage more than just books, type ruby script/generate.
SIS – NBS Online Specimen Tracking System Training
MS-Access XP Lesson 2. Input Mask Property 1.Field : Phone No Data Type : Number Input Mask : Character 0 represent a single digit and phone.
Chapter 18 - Data sources and datasets 1 Outline How to create a data source How to use a data source How to use Query Builder to build a simple query.
1 Web-Enabled Decision Support Systems Advance Topics in Database Connectivity Prof. Name Position (123) University Name.
Guide to Oracle10G1 Introduction To Forms Builder Chapter 5.
Introduction to Databases CIS 5.2. Where would you find info about yourself stored in a computer? College Physician’s office Library Grocery Store Dentist’s.
A Guide to SQL, Seventh Edition. Objectives Understand the concepts and terminology associated with relational databases Create and run SQL commands in.
Microsoft Visual Basic 2012 CHAPTER TEN Incorporating Databases with ADO.NET.
Introduction to Structured Query Language (SQL)
Project Implementation for COSC 5050 Distributed Database Applications Lab5.
CST JavaScript Validating Form Data with JavaScript.
Microsoft Visual Basic 2005 CHAPTER 8 Using Procedures and Exception Handling.
Chapter 3 Maintaining a Database
With Microsoft Office 2007 Intermediate© 2008 Pearson Prentice Hall1 PowerPoint Presentation to Accompany GO! with Microsoft ® Office 2007 Intermediate.
Chapter 5 Java Script And Forms JavaScript, Third Edition.
Programming with Microsoft Visual Basic 2012 Chapter 13: Working with Access Databases and LINQ.
Chapter 11 Introduction to Database Processing. Class 11: Database Processing Use a Visual Studio Wizard to establish a database connection used to load.
© 2008 The McGraw-Hill Companies, Inc. All rights reserved. ACCESS 2007 M I C R O S O F T ® THE PROFESSIONAL APPROACH S E R I E S Lesson 4 – Creating New.
With Microsoft Access 2007 Volume 1© 2008 Pearson Prentice Hall1 PowerPoint Presentation to Accompany GO! with Microsoft ® Access 2007 Volume 1 Chapter.
Microsoft Visual Basic 2012 Using Procedures and Exception Handling CHAPTER SEVEN.
Copyright © 2001 by Wiley. All rights reserved. Chapter 10: Advanced Database Operations Revising Vintage Videos Setting RecordSource at run time DBGrid.
AL-MAAREFA COLLEGE FOR SCIENCE AND TECHNOLOGY INFO 232: DATABASE SYSTEMS CHAPTER 7 INTRODUCTION TO STRUCTURED QUERY LANGUAGE (SQL) Instructor Ms. Arwa.
Microsoft Visual Basic 2008 CHAPTER 8 Using Procedures and Exception Handling.
Chapter 4 The Relational Model 3: Advanced Topics Concepts of Database Management Seventh Edition.
ADO.NET Tools and Wizards. Slide 2 Data Sources Window (Introduction) Use the Data Sources window to Establish a connection Create bound control instances.
WEEK 3 AND 4 USING CLIENT-SIDE SCRIPTS TO ENHANCE WEB APPLICATIONS.
Microsoft Access Get a green book. Page AC 2 Define Access Define database.
LiveCycle Data Services Introduction Part 2. Part 2? This is the second in our series on LiveCycle Data Services. If you missed our first presentation,
Chapter 6 Generating Form Letters, Mailing Labels, and a Directory
Microsoft Visual Basic 2010: Reloaded Fourth Edition Chapter Twelve Access Databases and LINQ.
Chapter 8 iComponents and Parameters. After completing this chapter, you will be able to perform the following: –Create iMates –Change the display of.
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.
1 By: Nour Hilal. Microsoft Access is a database software where data is stored in one or more Tables. A Database is a group of related Tables. Access.
Introduction to Database Development Using Borland Data Providers 2128 Martin Rudy.
Using Client-Side Scripts to Enhance Web Applications 1.
JavaScript, Fourth Edition Chapter 5 Validating Form Data with JavaScript.
JAVA: An Introduction to Problem Solving & Programming, 5 th Ed. By Walter Savitch and Frank Carrano. ISBN © 2009 Pearson Education, Inc., Upper.
Java Script: Arrays (Chapter 11 in [2]). 2 Outline Introduction Introduction Arrays Arrays Declaring and Allocating Arrays Declaring and Allocating Arrays.
7 1 Chapter 7 Introduction to Structured Query Language (SQL) Database Systems: Design, Implementation, and Management, Seventh Edition, Rob and Coronel.
WHAT IS A DATABASE? A DATABASE IS A COLLECTION OF DATA RELATED TO A PARTICULAR TOPIC OR PURPOSE OR TO PUT IT SIMPLY A GENERAL PURPOSE CONTAINER FOR STORING.
Microsoft Access 2010 Chapter 10 Administering a Database System.
Copyright 2007, Paradigm Publishing Inc. ACCESS 2007 Chapter 2 BACKNEXTEND 2-1 LINKS TO OBJECTIVES Creating Related Tables Creating Related Tables Determining.
FrontPage Tutorial Part 2 Creating a Course Web Site.
Advanced SQL: Triggers & Assertions
Chapter 9 Constraints. Chapter Objectives  Explain the purpose of constraints in a table  Distinguish among PRIMARY KEY, FOREIGN KEY, UNIQUE, CHECK,
Oracle 11g: SQL Chapter 4 Constraints.
Chapter 4 Constraints Oracle 10g: SQL. Oracle 10g: SQL 2 Objectives Explain the purpose of constraints in a table Distinguish among PRIMARY KEY, FOREIGN.
1 Chapter 20 – Data sources and datasets Outline How to create a data source How to use a data source How to use Query Builder to build a simple query.
Oracle Data Integrator Data Quality (Integrity Control)
Chapter 3 Automating Your Work. It is frustrating when you have to type the same passage of text repeatedly. For example your name and address. Word includes.
Constraints Lesson 8. Skills Matrix Constraints Domain Integrity: A domain refers to a column in a table. Domain integrity includes data types, rules,
Chapter 24 I’m Suffering from Information Overload (Access Databases) Clearly Visual Basic: Programming with Visual Basic nd Edition.
Modify Tables and FieldsModify Tables and Fields Lesson 4 © 2014, John Wiley & Sons, Inc.Microsoft Official Academic Course, Microsoft Word Microsoft.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved Address Book Application Introducing Database Programming.
Adding, editing, and deleting items using CONTENTdm Administration.
8 Copyright © 2005, Oracle. All rights reserved. Managing Schema Objects.
Resource Review Excel formula basics Demonstrate how to enter manual formulas Examine some of the available functions and their usage Discuss the.
CONDITIONAL FORMATTING AND CUSTOM NUMBER FORMATS LEC 5 1.
Database (Microsoft Access). Database A database is an organized collection of related data about a specific topic or purpose. Examples of databases include:
N5 Databases Notes Information Systems Design & Development: Structures and links.
Chapter 5 Validating Form Data with JavaScript
Microsoft Visual Basic 2010: Reloaded Fourth Edition
ADO.NET Framework.
Data Validation and Protecting Workbook
Unit 8.2 How data can be used Accessing Data in Views
Tonga Institute of Higher Education
Lecture Set 10 Windows Controls and Forms
Presentation transcript:

ITS 328 CHAPTER 3: STORING DATA IN MEMORY 1

Storing Data in Memory After today you will be able to: ◦Explain how a DataTable stores data ◦Add new data rows to a table ◦Examine, update, and remove existing values in a table row ◦Explain how ADO.NET differentiates between pending and final data values ◦Integrate data verification code into your DataTable object 2

Today’s Exercise Chapter 3 CSharp Project ◦Open Chapter 3 CSharp.sln in files folder Add DataRow programmatically (p.41) Fill Form Display Fields (p.43) Edit a DataRow (p.43) Validating Content (p.54) 3

Creating a Table (Chapter 2) Create a Table ◦DataTable someTable = new DataTable("Customer"); Add a Column ◦someTable.Columns.Add("ExpireDate", typeof(DateTime)); Add Column with Constraints ◦DataColumn newColumn;// Use to specify properties ◦newColumn = someTable.Columns.Add("FullName", typeof(string)); ◦newColumn.MaxLength = 30; ◦newColumn.AllowDBNull = false; ◦newColumn.Unique = true; 4

Adding Constraints to Columns (Chapter 2) DataColumn newColumn;// Use to specify properties newColumn = someTable.Columns.Add("FullName", typeof(string)); newColumn.MaxLength = 30; newColumn.AllowDBNull = false; newColumn.Unique = true; newColumn.Caption = "Student Name"; 5

Adding Data Create a new row object ◦DataRow oneRow = someTable.NewRow(); Store the actual data values in the row object ◦oneRow.Item[2] = "Joe Schmoe"; ◦oneRow["FullName"] = "Joe Schmoe"; Add the row object to the table ◦someTable.Rows.Add(oneRow);// Adds to end of table ◦someTable.Rows.InsertAt(oneRow,0);// Inserts at beginning of table Add data directly, without row object ◦someTable.Rows.Add(new Object[] {1L, DateTime.Parse("12/31/2016"), "Joe Schmoe"}); 6

Exercise Part 1 – Adding Rows (P. 41) Open Chapter 3 CSharp project ◦Contains two Windows.Forms classes: AccountManager and AccountDetail Open AccountManager.cs (F7 from AccountManager Design window) Locate the Load Form event handler AccountManager_Load Review Creation of Table ◦oneColumn for adding constraints to columns ◦ColumnChanging event handlers for specifying business rules ◦Primary Key ◦Optional Columns 7

Exercise Part 1 – Adding Rows (P. 41) Below "// Build some sample data rows." comment, add: ◦CustomerAccounts.Rows.Add(new Object[] {1L, "Blue Yonder Airlines", true, 500m, DateTime.Parse("1/1/2007")}); ◦CustomerAccounts.Rows.Add(new Object[] {2L, "Fourth Coffee", true, 350m, DateTime.Parse("7/25/2009")}); ◦CustomerAccounts.Rows.Add(new Object[] {3L, "Wingtip Toys", false}); ◦Yourself active with a $100 annual fee starting tomorrow. Notice foreach adding Items to the AllAccounts ListBox component 8

Exercise Part 2 – Modifying Rows (P. 43) Examine ActAdd_Click() and ActEdit_Click() button event handlers ◦Each Invokes AccountDetail().EditAccount(ref editRecord, table) Open AccountDetail.cs [Design] ◦Load event handler fills the fields from DataRow from AccountManager ◦Properties and Events including AccountDetail Load event handler ◦Identify Components: AccountID, AccountName, AnnualFee, StartDate Arguments ◦eventRecord and CustomerAccounts are arguments from AccountManager ◦whichAccount and baseTable are parameters in AccountDetail ◦AccountEntry and AccountTable are instance names 9

Exercise Part 2 – Fill Form Code (P. 43) In AccountDetail_Load() add: if (AccountEntry != null) { AccountID.Text = string.Format("{0:0}", AccountEntry["ID"]); ActiveAccount.Checked = (bool)AccountEntry["Active"]; if (DBNull.Value.Equals(AccountEntry["FullName"]) == false) AccountName.Text = (string)AccountEntry["FullName"]; if (DBNull.Value.Equals(AccountEntry["AnnualFee"]) == false) AnnualFee.Text = string.Format("{0:0.00}", (decimal)AccountEntry["AnnualFee"]); if (DBNull.Value.Equals(AccountEntry["StartDate"]) == false) StartDate.Text = string.Format("{0:d}", (DateTime)AccountEntry["StartDate"]); } Search Google for "c# string.format" 10

Exercise Part 2 – Click OK Code (P. 43) Below workArea.BeginEdit(); add: workArea["Active"] = ActiveAccount.Checked; if (AccountName.Text.Trim().Length == 0) workArea["FullName"] = DBNull.Value; else workArea["FullName"] = AccountName.Text.Trim(); if (AnnualFee.Text.Trim().Length == 0) workArea["AnnualFee"] = DBNull.Value; else workArea["AnnualFee"] = decimal.Parse(AnnualFee.Text); if (StartDate.Text.Trim().Length == 0) workArea["StartDate"] = DBNull.Value; else workArea["StartDate"] = DateTime.Parse(StartDate.Text); 11

Deleting Rows Use Remove() or RemoveAt() methods to remove DataRow objects. Remove() accepts row instance as argument: ◦DataRow oneRow = someTable.Rows[0]; ◦someTable.Rows.Remove(oneRow); RemoveAt() accepts index position as argument ◦someTable.Rows.RemoveAt(0); Clear() removes all the rows ◦someTable.Rows.Clear(); 12

Batch Processing Allows a batch of changes before committing to any of them Preferable when changes occurring across multiple rows must be collectively valid After updates are complete ◦someTable.AcceptChanges();// Commit all row changes ◦someTable.RejectChanges();// Reject changes since last commit Use DataRow.BeginEdit() to postpone data checks and exceptions until DataRow.EndEdit(); 13

Exception-Based Errors Assigning data of the wrong data type to a column value. Supplying string data to a column that exceeds the maximum length defined in the column’s DataColumn.MaxLength property. Attempting to store a NULL value in a primary key column. Adding a duplicate value in a column that has its Unique property set. Operation that violates one of the table’s custom (e.g., relational) constraints. 14

Validation-Based Errors DataTable Column and Row Change Event Handlers ◦ColumnChanging, RowChanging, RowDeleting, TableNewRow ◦ColumnChanged, RowChanged, RowDeleted, TableClearing, TableCleared Example Check Age column for valid range: private void Applicant_ColumnChanging(Object sender, System.Data.DataColumnChangeEventArgs e) { // Check the Age column for a valid range. if (e.Column.ColumnName == "Age") { if ((int)e.ProposedValue 29) e.Row.SetColumnError(e.Column,"Applicant's age falls outside the allowed range."); } 15

Exercise Part 3 – Validate Content (P. 54) Follow the directions on Page 54 checking Annual Fee and Start Date. In the CustomerAccounts_ColumnChanging event handler, add: if (e.Column.ColumnName == "AnnualFee") { // Annual fee may not be negative. if (DBNull.Value.Equals(e.ProposedValue) == false) { if ((decimal)e.ProposedValue < 0m) e.Row.SetColumnError(e.Column, "Annual fee may not be negative."); } } else if (e.Column.ColumnName == "StartDate") { // Start date must be on or before today. if (DBNull.Value.Equals(e.ProposedValue) == false) { if (((DateTime)e.ProposedValue).Date > DateTime.Today) e.Row.SetColumnError(e.Column, "Start date must occur on or before today."); } 16

Exercise Part 3 – Validate Content (P. 54) In the CustomerAccounts_RowChanging event handler, add the following: if (e.Row.HasVersion(DataRowVersion.Proposed) == true) { if (((bool)e.Row["Active", DataRowVersion.Proposed] == true) && (DBNull.Value.Equals(e.Row["StartDate", DataRowVersion.Proposed]) == true)) e.Row.RowError = "Active accounts must have a valid start date."; } Run the program to confirm it works. Make sure the instructor confirms your program works before you leave 17