CIS-266
MidtermStudy Guide
Midterm
Open book, open notes True/False, Multiple Choice, Fill In,
Short Answer Bring a pen or pencil
Class Library
Stores all classes and interfaces of the .NET language
Namespaces – sections within the library that contain classes, structures, enumerations, delegates, interfaces
Class Library - Types
Refer to classes, structures, enumerations, delegates, interfaces, data types
Value types: each holds own value Reference types: points to location
MDI
Projects can contain Multiple parent forms Multiple child form Independent forms (the splash
screen) When you close a parent form, all of
its children close A child cannot wander out of its
parent’s area
The Window Menu
Create a Window menu for parent forms List open child windows Allow users to arrange child windows Window Layout Options this.LayoutMdi(MdiLayout.TileVertical) this.LayoutMdi(MdiLayout.TileHorizontal
) this.LayoutMdi(MdiLayout.Cascade)
Context Menus
Also called shortcut or popup menus Use the regular menu designer to
create a menu Assign the top-level menu name to
the ContextMenu property of the form and/or controls on the form
OOP Terminology-Abstraction A model of an object that determines
Characteristics -> properties Behaviors -> methods
OOP Terminology-Encapsulation Combination of characteristics of an
object along with its behaviors ? one “package”
Data hiding Properties and procedures are hidden Programmer controls “exposure” of
properties and methods available to other objects
OOP Terminology-Inheritance The ability to create a new class from
an existing class The existing (original) class is called
the base, superclass, or parent The inherited class is called the
derived, subclass, or child A derived class has an “is a”
relationship with its base class
OOP Terminology-Inheritance Inheritance supports reusability Place common code in a base class Derived classes can call shared
functions
OOP Terminology - Polymorphism
Methods with identical names have different implementations
The Select method is different for radio buttons, check boxes, and list boxes
Allows a single class to have more than one method with different argument lists
Multitier Applications
Three-tier applications are popular Presentation tier Business tier Data tier
Goal is to write components that can be replaced without replacing other components
“Plug-in” new components
Throwing and Catching Exceptions
The system throws an exception when a run-time error occurs
Your program can catch the exception and take an action
Use the Try/Catch block to enclose code that could cause an exception
OR Ignore the exception
What Exception to Throw?
Use existing .NET Framework exception classes
Create your own exception that inherits from existing exceptions
Use the System.ApplicationException class when you throw your own exceptions from application code
Variables
Instance variables (properties) are values associated with each new instance of an object
Use static (shared) variables (properties) for data common to class
Creating an Enumeration
An enum is a list of named constants The data type of the constants must
be integer (short, long, byte)
Collections
Container for a group of like items Need to be able to Add, Remove Include an Item Property to return an
individual member Typically the default property
ADO.NET
Microsoft’s latest database object model
Allows .Net programmers to use a standard set of objects to refer to data from any source
Uses disconnected datasets with common data representation (data types) from multiple sources
ADO.NET Providers
Data Providers manipulate the data using SQL statements or stored procedures
SQLClient for SQL Server OracleClient for Oracle databases OleDbClient for all other database
formats An ODBC provider is available for
older apps
Data Provider Objects
Connection object – link to a data source
Command object – stores and executes SQL statements
DataAdapter object – handles retrieving and updating data in a DataSet object Includes commands and connection
TableAdapter expands the capabilities of a DataAdapter
ADO.NET Components
DataSet Object holds a copy of the data in memory
Dataset object can be populated with data from many sources
Regardless of the data source, code handles DataSet objects the same
Dataset objects hold one or more DataTable objects and DataRelation objects
Use the DataSet object
To transfer data between tiers To manipulate the data without an
open connection To relate data from multiple sources To bind data to a Windows form
XML Schema File
Describes the fields, data types, and constraints
View dataset schema in the .xsd file found in the Solution Explorer
Connection String
Stored in app.config (XML file) Connection string with a local
database specifies a |DATA| directory Database file is copied from project
folder to bin folder when run project
Form Contents
Dataset manages data in memory Table adapter manages the requests
for data (both in/out of db) Can include multiple SELECT
statements Table adapter manager controls how
to manage data changes to table and related tables In relational database order of edits
matters
Form Contents - 2
Data grid view provides on screen display of data
Includes built in tools – sorting, adjusting table
Binding navigator manages navigation of rows/editing
Binding source connects form/controls to data set Serves as “glue” to make sure the contents of
each field in each row properly displayed in controls
Binding
Complex data binding happens when dealing with rows and columns (grid, list controls)
Simple data binding is for a control connected to a single column
Reading/Writing Data
Getting data: Table adapter (or data adapter) has a FILL method that executes the SELECT statement
An argument specifies where the data should end up in memory
Saving data: Table adapter (or data adapter) has an
UPDATE method Table adapter manager has an UPDATE ALL
that manages the execution of updates to related tables
Reading/Writing Data - 2
Ensure that all validation is done (this.Validate)
Ensure that no editing is going on before use Update (bindingsource.EndEdit)
Referential integrity means order matters
Exceptions
Have exception classes for each data provider (SQL Server, Oracle, OLEDB, ODBC)
Reading the Number property of SQL Server exception objects refers to the specific error from SQL Server
Typical exceptions in ADO.Net not provider based DB Concurrency - row in table is different that the
original version (optimistic concurrency) Data Exception - generic exception from provider Constraint Exception violates validation rules No null allowed - required field is missing a value
Data Grid Exceptions
Data grid can generate exceptions Value in cell doesn't match
requirements in data column (Null, invalid type)
Can find the location of an exception by Row and Column (index values)
Refreshing Data
After save data, may want to "refresh" the dataset - make sure what's in memory is same as what was saved, especially when have identity columns
Populating Combo Boxes with Data Set the DataSource property Connects to the dataset Set the DisplayMember property Connects to the field name Use the ValueMember if want to refer
to a different field than the one displayed
The SelectedValue specifies the field that receives the selection