Chapters 12 and 14 - COP 2360 New Little WebSite

Download Report

Transcript Chapters 12 and 14 - COP 2360 New Little WebSite

COP2360 – C# Programming
Chapter 12-14ish – April 1
Announcements

Assignment 4 is due April 3 by midnight
–
You can either upload the assignment as
specified in the FTP document or email it to me
at

–
[email protected]
DO NOT MAIL IT TO MY PBSC Account

It will just be deleted!!
Tonight




Test Review
Exception Handling
Beginning Database Access
Remedial Web Forms (Second half of the
class.)
Exception Handling

Try…Catch…Finally

Code that may create a problem is placed in the try
block

Code to deal with the problem (the exception
handler) is placed in catch blocks
–

catch clause
Code to be executed whether an exception is thrown
or not is placed in the finally block
Try…Catch…Finally

Generic catch clause
–
–


Omit argument list with the catch
Any exception thrown is handled by executing
code within that catch block
Control is never returned into the try block
after an exception is thrown
Using a try…catch block can keep the
program from terminating abnormally
Example Code





No Exception
Generic Exception
Generic Exception with Method
Specific Exception
Make My Own Exception
Introduction to Databases

As data needs increase, text files become
less viable options

Databases store information in records,
fields, and tables

Database - collection of records stored in a
computer in a systematic way, so that a
computer program can consult it to answer
questions
Introduction to Databases

Database management system (DBMS):
computer programs used to manage and
query databases

Example DBMSs include SQL server, Oracle,
and Access
–
Many DBMSs store data in tabular format

Data in tables are related through common data
field keys
Data Providers (continued)

Microsoft SQL Server
–

Oracle
–

Applications using SQL Server 7.0 or later
Applications using Oracle data sources
Object Linking and Embedding Database
(OLE DB)
– Applications that use Microsoft Access databases

Open Database Connectivity (ODBC)
–
Applications supported by earlier versions of Visual Studio
C# Programming: From Problem Analysis to Program Design
9
Data Providers (continued)
Table 14-3 Core classes that make up ADO.NET data providers
C# Programming: From Problem Analysis to Program Design
10
Connecting to the Database
(Microsoft SQL Server)

Add using directive
using System.Data.OleDb;

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 = "Provider=sqloledb;Data
Source=pbsc.c1a7eggjev8o.us-east1.rds.amazonaws.com;Initial
Catalog=REGISTRATION;Persist Security Info=True;User
ID=cop2360;Password=GoPanthers";
OleDbConnection dbConn;
11
dbConn = new OleDbConnection(sConnection);
Our Example Database



Is Located in the Amazon Cloud
Provider=sqloledb;Data
Source=pbsc.c1a7eggjev8o.us-east1.rds.amazonaws.com;Initial
Catalog=REGISTRATION;Persist Security
Info=True;User
ID=cop2360;Password=GoPanthers
Is a representation of a College Transcript
System
The Registration Database
A Basic Select Clause

Let’s Use the Server Explorer in VS2012
SELECT field-names
FROM table-name(s)
WHERE condition clause
Let’s Play With The Data
Let’s Access The Data Through a
Program