COP2360 – C# Programming Chapter 14 – Nov 25, 2015.

Slides:



Advertisements
Similar presentations
Data Base. Objective Become familiar with database terminology. Create a project to display data for a single database table. Use a DataGrid control.
Advertisements

Chapter 10 ADO. What is ADO? ADO is a Microsoft technology ADO stands for ActiveX Data Objects ADO is a programming interface to access data in a database.
Introduction to Database Processing with ADO.NET.
ASP.NET Database Connectivity I. 2 © UW Business School, University of Washington 2004 Outline Database Concepts SQL ASP.NET Database Connectivity.
C# Programming: From Problem Analysis to Program Design1 Working with Databases C# Programming: From Problem Analysis to Program Design 3 rd Edition 14.
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
Chapter 4 Relational Databases Copyright © 2012 Pearson Education, Inc. publishing as Prentice Hall 4-1.
Chapter 12 Database Connectivity with ASP.NET JavaScript, Third Edition.
Chapter 7 Managing Data Sources. ASP.NET 2.0, Third Edition2.
Chapter 4 Relational Databases Copyright © 2012 Pearson Education 4-1.
Overview of Database Access in.Net Josh Bowen CIS 764-FS2008.
Stored Procedures Dr. Ralph D. Westfall May, 2009.
C# programming with database Basic guideline. First step Install SQL Server 2008/2010 (Professional edition if possible) Install Visual Studio 2008/2010.
Advance Computer Programming Java Database Connectivity (JDBC) – In order to connect a Java application to a database, you need to use a JDBC driver. –
CHAPTER 9 DATABASE MANAGEMENT © Prepared By: Razif Razali.
Database System Concepts and Architecture Lecture # 3 22 June 2012 National University of Computer and Emerging Sciences.
Databases From A to Boyce Codd. What is a database? It depends on your point of view. For Manovich, a database is a means of structuring information in.
ASP.NET Programming with C# and SQL Server First Edition
Introduction. 
PHP Programming with MySQL Slide 8-1 CHAPTER 8 Working with Databases and MySQL.
Chapter 15: Using LINQ to Access Data in C# Programs.
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.
Web Services Week 8 Aims: –Using web services as front ends to databases Objectives: –Review of relational databases –Connecting to and querying databases.
HNDComputing – DeMontfort University  DeMontfort University 2011 Database Fundamentals wk2 Database Design ConceptsDatabase Design Concepts Database Design.
Chapter 7 Working with Databases and MySQL PHP Programming with MySQL 2 nd Edition.
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.
Databases From A to Boyce Codd. What is a database? It depends on your point of view. For Manovich, a database is a means of structuring information in.
I Information Systems Technology Ross Malaga 4 "Part I Understanding Information Systems Technology" Copyright © 2005 Prentice Hall, Inc. 4-1 DATABASE.
INFS614, Dr. Brodsky, GMU1 Database Management Systems INFS 614 Instructor: Professor Alex Brodsky
Database Design and Management CPTG /23/2015Chapter 12 of 38 Functions of a Database Store data Store data School: student records, class schedules,
Christopher M. Pascucci.NET Programming: Databases & ADO.NET.
BIT 285: ( Web) Application Programming Lecture 15: Tuesday, February 24, 2015 Microsoft Azure Instructor: Craig Duckett.
1 CS 430 Database Theory Winter 2005 Lecture 2: General Concepts.
INFO1408 Database Design Concepts Week 15: Introduction to Database Management Systems.
Lecture Set 14 B new Introduction to Databases - Database Processing: The Connected Model (Using DataReaders)
Oracle & SQL Introduction. Database Concepts Revision DB? DBMS? DB Application? Application Programs? DBS? Examples of DBS? Examples of DBMS? 2Oracle.
Mauricio Featherman, Ph.D. Washington St. University
CS453: Databases and State in Web Applications (Part 2) Prof. Tom Horton.
NSF DUE ; Wen M. Andrews J. Sargeant Reynolds Community College Richmond, Virginia.
Database Connectivity with ASP.NET. 2 Introduction Web pages commonly used to: –Gather information stored on a Web server database Most server-side scripting.
IS2803 Developing Multimedia Applications for Business (Part 2) Lecture 1: Introduction to IS2803 Rob Gleasure
1 Database Programming with ADO.NET Kashef Mughal.
ECMM6018 Enterprise Networking For Electronic Commerce Tutorial 6 CGI/Perl and databases.
Distribution of Marks For Second Semester Internal Sessional Evaluation External Evaluation Assignment /Project QuizzesClass Attendance Mid-Term Test Total.
Chapter 3: Relational Databases
1 A Very Brief Introduction to Relational Databases.
Chapter 9 Working with Databases. Copyright © 2011 Pearson Addison-Wesley Introduction In this chapter you will learn: – Basic database concepts – How.
MICROSOFT ACCESS – CHAPTER 5 MICROSOFT ACCESS – CHAPTER 6 MICROSOFT ACCESS – CHAPTER 7 Sravanthi Lakkimsety Mar 14,2016.
uses of DB systems DB environment DB structure Codd’s rules current common RDBMs implementations.
The Database Concept and the Database Management System (DBMS) Databases.
ADO .NET from. ADO .NET from “ADO .Net” Evolution/History of ADO.NET MICROSOFT .NET “ADO .Net” Evolution/History of ADO.NET History: Most applications.
SQL Basics Review Reviewing what we’ve learned so far…….
1 Section 1 - Introduction to SQL u SQL is an abbreviation for Structured Query Language. u It is generally pronounced “Sequel” u SQL is a unified language.
Data Resource Management Data Concepts Database Management Types of Databases Chapter 5 McGraw-Hill/Irwin Copyright © 2007 by The McGraw-Hill Companies,
Chapter 12 Introducing Databases. Objectives What a database is and which databases are typically used with ASP.NET pages What SQL is, how it looks, and.
Understanding Core Database Concepts Lesson 1. Objectives.
ASP.NET Programming with C# and SQL Server First Edition
Accessing Databases using Ado.net
Introduction to Database Processing with ADO.NET
Introduction to Database Processing with ADO.NET
Lecture 6 VB.Net SQL Server.
ADO.NET Accessing Databases in VS.NET
Basic Concepts in Data Management
Chapter 8 Working with Databases and MySQL
Database Fundamentals
Teaching slides Chapter 8.
Chapter 10 ADO.
Database Applications
Understanding Core Database Concepts
Presentation transcript:

COP2360 – C# Programming Chapter 14 – Nov 25, 2015

Announcements Three Weeks Left – Next Week ASP.NET (Web) Development Part II of Assignment 5 – December 9 Part III of Assignment 5 Final Exam Review Final Exam Programming Assignment – December 16 Final Exam Please Sign on to Panther Web and complete the Student Assessment for this course!! I might bring better candy to the final if you all do!!

Tonight Database Access Assignment 5 – Part I

Flat File Access to Data Fields are “hard” to define and have to be converted to variables once the data is read Relationships between data difficult to define – For example, our Assignment 4 had Questions and Answers with the Answers being related to specific questions. The best we could do was to have the Answer follow the Questions. – We needed to show which answer was correct, so we used an asterisk. Multiple access to the same information almost impossible – Once a File is opened by a program, it is locked from being opened by other programs. Every file needed it’s own set of definitions to be understandable by the program.

What is a Database A large, integrated collection of data. – Models a real-world enterprise. – Entities a Noun (e.g., students, courses) Attributes – The fields within the Entity – Relationships a Verb that relates two or more Nouns Usually answers a question (e.g., Which courses is Madonna taking this summer?)

What is a Database Management System (DBMS) A software package designed to store and manage databases

Why Use a DBMS? Data independence and efficient access. Reduced application development time. Data integrity and security. Uniform data administration. Concurrent access Data Security/Recoverability

Relational Data Model Main concept: relation, basically a table with rows (sometimes called tuples) and columns. Every relation has a schema, which describes the columns or fields (or attributes) within the table. Both entities and relationships can be described in a relation.

Major Relational Players Oracle – Large scale corporation databases financials inventory Microsoft SQL Server – Small to medium corporation databases – Integrated tightly with other Microsoft products – Similar product support as Oracle MySQL (now owned by Oracle) – #1 Open Source database – used by many social media sites (Facebook, Twitter, etc.)

Data Definition Language (DDL) Used to define the schema and manage the database structure – Create Table – Alter Table – Create Index

Data Manipulation Language (DML) Commands to add, update and delete records in the database – INSERT – UPDATE – DELETE Commands to query the database – SELECT

NoSQL Databases To try and provide for access to massively large data sets, several companies have developed what are named “NoSQL” (for Not Only SQL) databases – Several different models using different data structures. – Basics include the splitting of data into a self defining database across multiple servers. XML of JSON (or other) self defining methods employed As data grows, more small servers can be added instead of having to increase capacity of one server When multiple servers are used, “ACID” is going to severely slow down the update and retrieval processes. – Each version has it’s own unique data definition and data manipulation languages.

Microsoft Visual Studio Database Objects Microsoft SQL Server – Applications using SQL Server 7.0 or later Oracle – Applications using Oracle data sources Object Linking and Embedding Database (OLE DB) – Common layer that can access many different database (including Oracle, SQLServer, Access, MySQL) through the use of connection libraries for each type of database Open Database Connectivity (ODBC) – An earlier layer for accessing many different database types

Microsoft Visual Studio Database Objects Visual Studio has separate libraries for each of the data types – SQL and Oracle layers are more “direct” than OLEDB – but – it locks in the database For the stuff I did in the past, I used OLEDB because the code I had accessed both Oracle and SQLServer databases. If you are for sure only going to support one database platform, (and it’s either Oracle or SQLServer), it would be better to use the one specific for that DBMS.

The FundFriend Database

Let’s Play With The Data Some simple single table queries – Probably the best we can do with this is against Account Let’s link the Account to Friends Let’s link the Account to the Transactions Let’s put them all together. OK – Not expecting you to get this in five minutes!! – All SQL for our Assignment 5 will be done for you.

A Basic Select Clause Let’s Use the Server Explorer in VS2012 SELECT field-names FROM table-name(s) WHERE condition clause

Accessing a Database through VS Manual Set-Up Classes Connection Class – Defines the type and location of the database Command Class – Used to define the command (Select, Insert, Update, Delete) that needs to be executed. DataReader Class – For Select statements, returns one record at a time so that it can be manipulated. DataAdapter Class – For Select statements, holds all records returned by the Select, and can be used to subsequently update the database (although I really don’t like that feature!!)

19 Connecting to the Database (Microsoft SQL Server) Add using directives – using System.Data.Sql; – using System.Data.SqlClient; Instantiate an object of connection class – Send connection string that includes the actual database provider and the data source (name of the database) string sConnection; sConnection Source=(LocalDB)\v11.0;AttachDbFilename=" + Application.StartupPath Security=True"; SqlConnection dbConn = new SqlConnection(sConnection); dbConn.Open();

Once Connected… Set up a Command Class to pass the SQL statements to the database management routines: dbCmd = new SqlCommand(); dbCmd.CommandText = sSQL; dbCmd.Connection = dbConn; For Update type commands, one would then Execute the command and it usually returns the number of records changed. int nRecordsChanged = dbCmd.ExecuteNonQuery()

Retrieving Data If you are retrieving data, you have two choices: – Record by record using a data Reader: dbReader = dbCmd.ExecuteReader(); while (dbReader.Read()) { // Do stuff with the data from the reader } dbReader.Close();

Retreiving Data Or, one can pull the entire result set from the query into a Dataset using a DataAdapter Class dbCmd.CommandText = sSQL; dbCmd.Connection = dbConn; dbTranAdapter = new SqlDataAdapter(); dbTranAdapter.SelectCommand = dbCmd; dbTranSet = new DataSet(); dbTranAdapter.Fill(dbTranSet, "Transactions");

Let’s Access The Data Through a Program Using the Manual Way

“Automated” Data Access in Visual Studio Windows Forms Data Aware Controls can be configured with database connections and SQL and kinda work by magic. – Not a fan because you lose a great deal of control, but will walk through this anyway in case you see this somewhere else. Includes – GridView, Combo Box, Details View

“Magical” database access Creating a “data source” Binding that data source with a data aware control Linking that to the SQL statements for retrieving and updating the data. I will now fail miserably and giving an example of this, but have one already done just in case!!

A Word About LINQ There is a big “disconnect” between application program and database access – The “standard” way of accessing data makes use of libraries that bride the gap between the program and the database But basically you are passing SQL strings to the DBMS and returning datasets that need to be interpreted Several other systems have tried to “Marry” programs to DBMSs. – Java uses JSQL, which basically is a pre-compiler that allows a program to code “SQL” statements are regular programming statements. – And old database access technique call PRO-C did a similar set-up for “C” programs – I have always moved the database calls out of the main program and into classes or web services so all of the crap you have to do is hidden from the main routines.

A Word About Linq With Visual Studio, Microsoft introduced their “Language Integrated Query” which allows a program to “connect” to a data source and then have the columnar information available for direct manipulation by the program. – What we have now requires us to convert the data to C# variables, and the convert it back when we update the database. Goods and Bads – Integration is nice, but it has a cost Some complex things you can do with SQL, you cannot do with LINQ Whatever LINQ looks like, it ends up being SQL, so it may not be as efficient as doing it by hand. But it does make the coding of a program more direct and concise. And it can be used for more than just databases.

Moving On Our Assignment 5 will be to develop a web based application that can run on a smart phone that implements a “PayPal” or “Bill Pay” System. The system will be based on our FundFriend database Tonight, we will do a quick design of what we need to incorporate into the system

FundFriend Web Application This week you must complete the basic screen designs for the system and turn them into Blackboard before next week (it would be tonight, but I’m guessing as I write this that several students won’t be here). That will be worth 3 points. Next week we will go over the basics of Web Development using VS and C#, and then mock up our design in ASP.NET forms. These form designs would then be turned in and will be worth 3 more points. The last week of class, we will do our best to add the actual code to the system to link the forms together and update the database. Whatever we get done that evening before the review will be worth 4 points. Each week I will have a “starting” point so that we are all on the same “page”.

Fund Friend What do we need?