SlideShare a Scribd company logo
1 of 44
Data
Representation
in C#
Michael Heron
Introduction
 In the last lecture we looked at how event driven
application in .NET work.
 I’ll leave it (mostly) up to you to get to grips with
C# syntax.
 In this lecture we’re going to discuss the .NET data
model in relation to objects (which you know) and
ADO .NET (which you probably don’t.
 ADO .NET is the database engine at the core of
.NET.
 As mentioned in previous lectures, data
representation is key to eventual success with a
system.
C# Objects
 C# objects look very much like Java objects.
 Down to the syntax.
 The prime differentiators are:
 Declaration of a class within a namespace.
 Accessors handled as properties.
 Properties provide a syntactically consistent
method of handling getting and setting of
attributes.
 Rather than the convention driven methods of
Java.
Class and Properties
using System;
namespace SimpleClassExample
{
class Person
{
private string name;
private int age;
public int Age
{
get
{
return age;
}
set
{
age = value;
}
}
}
}
Making Use Of Objects
using System;
namespace SimpleClassExample
{
class Program
{
static void Main(string[] args)
{
Person me = new Person();
me.Age = 80;
me.Name = "Michael";
me.adjustAge (1);
Console.WriteLine(me.Name + " is " + me.Age + " years
old");
}
}
}
Encapsulation
 All of the hard work of connecting to a
database in C# is encapsulated in the
data objects you work with.
 All you need to learn is how these objects
work, not how they interface with specific
databases.
 This means that once you have written
the code to work with one database, it’s
easy to change it to work with another.
Bespoke Data
 In the next lecture we’ll be talking about
how to hook up a program to a
database.
 This is a powerful technique.
 Before we get to that though, let’s talk a
little bit about why we may want to do it.
 And why we might not, on occasion.
 It’s the difference between using a
standard data layer (a database), and a
more bespoke data solution (hand-rolled
classes).
Bespoke Data Advantages
 Certain contexts demand bespoke
data implementation.
 Databases are optimised for certain kinds
of file IO, but are costly for other operations.
 Fast paced 3D games would be a good deal
less fast-paced with a database back-end.
 Very complex, tightly integrated data
manipulation is much easier to do with a
bespoke data model.
 Bespoke models give you a lot of scope for
context specific optimization.
Database Advantages
 Databases on the other hand, have
advantages of their own.
 They are already optimized for what they do.
 Large file IO, searching, sorting, etc
 Other people are constantly working on
improving them.
 A fix in the engine is a fix in your code too.
 They offer a structured standard for
interrogation.
 You can easily provide many different views of a
database because they all communicate with SQL.
Bespoke Versus Database
 When would you choose one over
another?
 The criteria I use is ‘how much does it matter to
me how the data is stored?
 For a simple web-based ecommerce
system, a database is a clear choice with
clear benefits.
 For a complex simulation, bespoke data
structures are probably better.
 It is the application itself that will dictate
this to you.
Examples
 You are a Scientist (doing science). You
want to run a variation of Conway’s
Game of Life to investigate properties of
emergent behaviour.
 Bespoke or Database?
 You are a businessperson (doing
business). You want to put up an online
catalogue that shows your wares and lets
people order them.
 Bespoke or Database?
Designing A Data Layer
 An ideal application allows for the data
representation to be abstracted from the
application itself.
 So you can change how data is represented,
and it doesn’t matter.
 This is sometimes known as an ‘3 tier’
architecture.
 Bespoke data representations do not
easily allow this.
 You need to write a translation layer of your
own.
 ADO .NET permits the use of several
underlying databases, (mostly) seamlessly.
MVC
The MVC is a design pattern that
runs through the module.
 Separate out the view from the controller
from the model.
 Or more usually, separate out the
view/controller from the model.
 Within the MVC, you can profitably look to
separate out data representation from
‘business logic’
 Through the incorporation of a dedicated
data layer.
ADO .NET
 All of this leads us to the .NET way of doing
databases.
 ADO .NET
 ADO .NET’s communication with
databases is based on two key elements.
 The Data Provider Framework
 The Data Set
 The data provider framework handles the
work of connecting to an actual
database.
 The Data Set handles the work of
communicating with applications.
ADO .NET
http://msdn.microsoft.com/en-us/library/27y4ybxw(VS.71).aspx
ADO .NET
 It is possible to interact with a database in
two ways.
 Using the Data Reader, which is real-time.
 Using Datasets, which are a snapshot of an
underlying data representation.
 We’ll be doing the latter.
 Some example code on The Interwebs may use
the former. Be mindful of this.
 Data sets offer a good deal of flexibility.
 They allow for database representation to be
interchangeable with XML representation.
Data Sets
 As mentioned, data sets offer a snapshot
of the underlying data source.
 This is a disconnected, memory resident
representation.
 Think of it as making a copy of the data for your
own purposes.
 Datasets do not permit you to play with
‘live ammunition’.
 If you change things in the dataset, your
underlying database does not change until you
tell it to.
Data Sets
 This creates some complications.
 What happens if you have two data-sets
pointing to the same database, and they
have both been changed?
 ADO .NET also offers the facility for
merging data-sets together to deal with
such situations.
 Not something you should have to do, but
again something to be mindful of.
Data Sets
 One of the biggest benefits of Data Sets is
that they permit the access of underlying
data in the same style as associative
arrays.
 Or ‘hashmaps’, or ‘mappings’, whatever
term you may prefer.
 This greatly simplifies the task of
interacting with an underlying database.
 SQL, for all its power, is not an easy
language with which to Get Things Done.
Objects and Databases
 When you make a connection to a
database in ADO .NET, it translates the
database into objects you can
manipulate.
 These objects often have other objects as
part of their makeup.
 Effective working within ADO .NET requires
you to be conversant with how these
work.
Objects and Databases
 A lot of the work you do in setting up a
database is done through Visual Studio
itself.
 What it’s doing though is creating and
setting objects for you.
 When it comes time to do anything ‘clever’
with our databases, we’ll need to make use
of the objects.
Step One: Making The
Database Available
 Choose ‘server explorer’
from the view menu.
 Add a new data
connection.
 Right click on the server
explorer and choose ‘add
connection’
 It will ask you where the
database is located.
Step One: Making The
Database Available
 If you have no u/p
information, leave
it as is.
 Press ‘test
connection’ to
make sure that
the connection
works.
 Then press ‘ok’.
 Your database is
then available in
the server explorer
under ‘data
connections’.
The Server Explorer
 The Server Explorer gives you an ‘in IDE’
view of the data and database.
 You can modify the table, execute queries,
or enter data as needed.
 Right click on the table you want to alter,
and choose ‘retrieve data’
Step 2: Data Adapter
 Step two is to create a data adapter to
extract information from the database.
 The data adapter defines the specific
information required by your application.
 In cases of very large complex databases, it
is vital to simplify data access routines.
 Essentially a data adapter acts as a filter
between the database and your
application.
Step 2: Data Adapter
 In the C# .NET toolbox is a tab
that says ‘data’.
 This tab contains GUI components
that represents aspects of the
ADO .NET architecture.
 The OleDBDataAdapter control
lets us use the data connection
wizard to set up an adapter.
 If it’s not there, it needs to be
added in manually.
Step 2: Data Adapter
 The wizard guides you through the
process of setting up the adapter.
 Step one, it asks which data connection to use.
 You can choose from any nodes on the server
explorer.
 Step two, it asks how to access the database.
 Choose ‘use SQL statements’.
 Step three, it asks what SQL statement to use.
 For now, we’re simply going to use a ‘select * from
Customer’ statement.
Step 2: Data Adapter
 Once these three steps have been taken, the data
adapter is configured.
 It will create an instance of the object in the
‘invisible controls’ part of the IDE.
 This control can be accessed in code the same
way as any other control.
 It just doesn’t appear explicitly on the form.
 Once you have this, we can move onto step 3.
Step 3: Dataset
 The next step is to create an object that
represents the data we wish to use in our
program.
 This object is called a dataset.
 The dataset is a snapshot of some specific
part of the database.
 It can come from tables
 It can come from queries
 It can come from SQL statements.
Step 3: Dataset
 To create a dataset,
we must click on the
form to make sure it is
active.
 Right click on the
form to bring up the
context sensitive
menu, and select
generate dataset.
 This will bring up the
generation dialog.
Step 3: Dataset
 We are going to create a new dataset, so
enter a identifier for the dataset in the
‘new’ box.
 By convention, datasets have a ds prefix.
 Ours will be called dsCustomer
 The list of tables to be used for the
dataset comes from the data adapter on
your form.
 Click on ‘ok’ to generate the dataset… it
will appear in the component tray along
with the data adapter.
Voila!
 Once you have the dataset generated,
you have a framework in your application
suitable for linking up to controls.
 In this lecture, we will look only at using
standard text boxes as data aware
controls.
 Next week we’ll look at some more
complex examples.
Displaying Data
 ADO .NET doesn’t simply dump an Access
table in your application.
 Instead, you have to explicitly decide what
controls are to display which parts of the
database.
 Most controls in C# can be bound to a
database.
 One control especially suited to this is the
textbox control.
Displaying Data
 Textboxes have many properties associated with
them.
 A category of these properties are known as data
properties.
 We use these to link the textbox to the dataset.
 textBox1.DataBindings.Add (new Binding ("Text",
dsCustomer1, "Customer.FirstName"));
 textBox2.DataBindings.Add (new Binding("Text",
dsCustomer1, "Customer.SurName"));
Displaying Data
 Click on the text link under the data
category.
 It will bring up a list of datasets
defined on the form.
 They each have a little + beside them.
 We can expand this tree until we
find the field we want to display in
the text box.
Displaying Data
 We do this for each field we want to
display on the form.
 As said previously, many controls can make
use of the same dataset.
 If we set up all our controls in this way and
then run, nothing will appear in the next
box.
 We’re not done yet.
One Last Step
 Finally, we need to add some code to our
application to set up the dataset and link
it to the adapter.
 You thought we’d done that already?
 We must manually fill the dataset from the
adapter. We do that with the following
lines of code:
YourDataset.Clear()
YourDataAdapter.Fill(YourDataSet)
One Last Step
 For example, with a dataset called
dsMyStuff and a data adapter called
OleDBDataAdapter1:
dsMyStuff.Clear()
OleDBDataAdapter1.Fill (dsMyStuff)
 Where you do this depends on when you
want the dataset filled.
 In the load event of a form is good if you
want it done immediately.
Navigation
 Okay, we’ve set up the controls and
are displaying some data.
 How do we navigate through it?
 ADO .NET keeps track of information
about the current record and total
number of records in a dataset
through use of an object called a
CurrencyManager.
 Each form in C# has a BindingContext
object that keeps track of all the
CurrencyManager objects.
Navigation
 The specifics of this are unimportant.
 All we want to know is ‘how to we
navigate through records?’.
 Despite the complex structure, the code
to navigate through controls is pretty
simple.
 We can access the BindingContext for a
dataset on a form using the this keyword.
Navigation
 Consider a form with a dataset called
dsPeople and a table in that dataset
called Persons:
this.BindingContext [dsPerson1,
“Person”]
 A BindingContext has some useful
properties for us to use:
 Position
 Count
Navigation
 The position property determines where in
the dataset we currently are.
 The count property holds how many
records are in the dataset.
 We can manipulate the position property
to move forwards and backwards
through the dataset.
Navigation
 Next:
this.BindingContext[dsCustomer1, "Customer"].Position += 1;
 Previous:
this.BindingContext[dsCustomer1, "Customer"].Position -= 1;
 Last:
this.BindingContext[dsCustomer1, "Customer"].Position =
this.BindingContext[dsCustomer1, "Customer"].Count - 1;
 First:
this.BindingContext[dsCustomer1, "Customer"].Position = 0;
 These code extracts can be bound to buttons
allowing the user to navigate through the
datasets.
Conclusion
 Data Representation is an important
concept.
 Something the more nerdy amongst us
often lose sleep over.
 In any application you have a choice
between bespoke representation and a
database engine.
 You should decide which of these to use on
the basis of your application.

More Related Content

What's hot

Visual Basic.Net & Ado.Net
Visual Basic.Net & Ado.NetVisual Basic.Net & Ado.Net
Visual Basic.Net & Ado.NetFaRid Adwa
 
Ado.net session10
Ado.net session10Ado.net session10
Ado.net session10Niit Care
 
Graph db as metastore
Graph db as metastoreGraph db as metastore
Graph db as metastoreHaris Khan
 
Introduction to database with ms access.hetvii
Introduction to database with ms access.hetviiIntroduction to database with ms access.hetvii
Introduction to database with ms access.hetvii07HetviBhagat
 
Introduction to ado
Introduction to adoIntroduction to ado
Introduction to adoHarman Bajwa
 
Apply hibernate to model and persist associations mappings in document versio...
Apply hibernate to model and persist associations mappings in document versio...Apply hibernate to model and persist associations mappings in document versio...
Apply hibernate to model and persist associations mappings in document versio...csandit
 
Asp.net interview questions
Asp.net interview questionsAsp.net interview questions
Asp.net interview questionsAkhil Mittal
 
Jdbc Dao it-slideshares.blogspot.com
Jdbc Dao it-slideshares.blogspot.comJdbc Dao it-slideshares.blogspot.com
Jdbc Dao it-slideshares.blogspot.comphanleson
 
Disconnected Architecture and Crystal report in VB.NET
Disconnected Architecture and Crystal report in VB.NETDisconnected Architecture and Crystal report in VB.NET
Disconnected Architecture and Crystal report in VB.NETEverywhere
 
Ado.Net Architecture
Ado.Net ArchitectureAdo.Net Architecture
Ado.Net ArchitectureUmar Farooq
 
The METL Process in Investment Banking
The METL Process in Investment BankingThe METL Process in Investment Banking
The METL Process in Investment BankingAntony Benzing
 
Doctrine 2 - Introduction
Doctrine 2 - IntroductionDoctrine 2 - Introduction
Doctrine 2 - IntroductionDiego Lewin
 

What's hot (16)

Visual Basic.Net & Ado.Net
Visual Basic.Net & Ado.NetVisual Basic.Net & Ado.Net
Visual Basic.Net & Ado.Net
 
Ado.net session10
Ado.net session10Ado.net session10
Ado.net session10
 
Graph db as metastore
Graph db as metastoreGraph db as metastore
Graph db as metastore
 
Introduction to database with ms access.hetvii
Introduction to database with ms access.hetviiIntroduction to database with ms access.hetvii
Introduction to database with ms access.hetvii
 
Introduction to ado
Introduction to adoIntroduction to ado
Introduction to ado
 
Apply hibernate to model and persist associations mappings in document versio...
Apply hibernate to model and persist associations mappings in document versio...Apply hibernate to model and persist associations mappings in document versio...
Apply hibernate to model and persist associations mappings in document versio...
 
Asp.net interview questions
Asp.net interview questionsAsp.net interview questions
Asp.net interview questions
 
Database Basics
Database BasicsDatabase Basics
Database Basics
 
Jdbc Dao it-slideshares.blogspot.com
Jdbc Dao it-slideshares.blogspot.comJdbc Dao it-slideshares.blogspot.com
Jdbc Dao it-slideshares.blogspot.com
 
ASP.NET 09 - ADO.NET
ASP.NET 09 - ADO.NETASP.NET 09 - ADO.NET
ASP.NET 09 - ADO.NET
 
Ado
AdoAdo
Ado
 
Ebook5
Ebook5Ebook5
Ebook5
 
Disconnected Architecture and Crystal report in VB.NET
Disconnected Architecture and Crystal report in VB.NETDisconnected Architecture and Crystal report in VB.NET
Disconnected Architecture and Crystal report in VB.NET
 
Ado.Net Architecture
Ado.Net ArchitectureAdo.Net Architecture
Ado.Net Architecture
 
The METL Process in Investment Banking
The METL Process in Investment BankingThe METL Process in Investment Banking
The METL Process in Investment Banking
 
Doctrine 2 - Introduction
Doctrine 2 - IntroductionDoctrine 2 - Introduction
Doctrine 2 - Introduction
 

Viewers also liked

C# Application program UNIT III
C# Application program UNIT IIIC# Application program UNIT III
C# Application program UNIT IIIMinu Rajasekaran
 
DISE - Windows Based Application Development in C#
DISE - Windows Based Application Development in C#DISE - Windows Based Application Development in C#
DISE - Windows Based Application Development in C#Rasan Samarasinghe
 
tybsc it asp.net full unit 1,2,3,4,5,6 notes
tybsc it asp.net full unit 1,2,3,4,5,6 notestybsc it asp.net full unit 1,2,3,4,5,6 notes
tybsc it asp.net full unit 1,2,3,4,5,6 notesWE-IT TUTORIALS
 
Why Java Sucks and C# Rocks (Final)
Why Java Sucks and C# Rocks (Final)Why Java Sucks and C# Rocks (Final)
Why Java Sucks and C# Rocks (Final)jeffz
 
3 Tier Architecture
3 Tier Architecture3 Tier Architecture
3 Tier Architectureguestd0cc01
 
3 Tier Architecture
3  Tier Architecture3  Tier Architecture
3 Tier ArchitectureWebx
 

Viewers also liked (9)

C# Application program UNIT III
C# Application program UNIT IIIC# Application program UNIT III
C# Application program UNIT III
 
DISE - Windows Based Application Development in C#
DISE - Windows Based Application Development in C#DISE - Windows Based Application Development in C#
DISE - Windows Based Application Development in C#
 
C#.NET
C#.NETC#.NET
C#.NET
 
tybsc it asp.net full unit 1,2,3,4,5,6 notes
tybsc it asp.net full unit 1,2,3,4,5,6 notestybsc it asp.net full unit 1,2,3,4,5,6 notes
tybsc it asp.net full unit 1,2,3,4,5,6 notes
 
C# basics
 C# basics C# basics
C# basics
 
Why Java Sucks and C# Rocks (Final)
Why Java Sucks and C# Rocks (Final)Why Java Sucks and C# Rocks (Final)
Why Java Sucks and C# Rocks (Final)
 
Programming in c#
Programming in c#Programming in c#
Programming in c#
 
3 Tier Architecture
3 Tier Architecture3 Tier Architecture
3 Tier Architecture
 
3 Tier Architecture
3  Tier Architecture3  Tier Architecture
3 Tier Architecture
 

Similar to PATTERNS07 - Data Representation in C#

Introduction to database with ms access(DBMS)
Introduction to database with ms access(DBMS)Introduction to database with ms access(DBMS)
Introduction to database with ms access(DBMS)07HetviBhagat
 
Chapter 3: ado.net
Chapter 3: ado.netChapter 3: ado.net
Chapter 3: ado.netNgeam Soly
 
PATTERNS08 - Strong Typing and Data Validation in .NET
PATTERNS08 - Strong Typing and Data Validation in .NETPATTERNS08 - Strong Typing and Data Validation in .NET
PATTERNS08 - Strong Typing and Data Validation in .NETMichael Heron
 
Style Intelligence Evaluation Documentation
Style Intelligence Evaluation DocumentationStyle Intelligence Evaluation Documentation
Style Intelligence Evaluation DocumentationArleneWatson
 
Sql interview question part 5
Sql interview question part 5Sql interview question part 5
Sql interview question part 5kaashiv1
 
Oracle to vb 6.0 connectivity
Oracle to vb 6.0 connectivityOracle to vb 6.0 connectivity
Oracle to vb 6.0 connectivityrohit vishwakarma
 
Accessing data within VB Applications
Accessing data within VB ApplicationsAccessing data within VB Applications
Accessing data within VB Applicationsrobertbenard
 
ASP.NET Unit-3.pdf
ASP.NET Unit-3.pdfASP.NET Unit-3.pdf
ASP.NET Unit-3.pdfabiraman7
 
Nhibernate Part 1
Nhibernate   Part 1Nhibernate   Part 1
Nhibernate Part 1guest075fec
 
Bank mangement system
Bank mangement systemBank mangement system
Bank mangement systemFaisalGhffar
 
Introduction to sql server
Introduction to sql serverIntroduction to sql server
Introduction to sql serverVinay Thota
 

Similar to PATTERNS07 - Data Representation in C# (20)

unit 3.docx
unit 3.docxunit 3.docx
unit 3.docx
 
PPT temp.pptx
PPT temp.pptxPPT temp.pptx
PPT temp.pptx
 
Introduction to database with ms access(DBMS)
Introduction to database with ms access(DBMS)Introduction to database with ms access(DBMS)
Introduction to database with ms access(DBMS)
 
Database fundamentals
Database fundamentalsDatabase fundamentals
Database fundamentals
 
Chapter 3: ado.net
Chapter 3: ado.netChapter 3: ado.net
Chapter 3: ado.net
 
Chapter 14
Chapter 14Chapter 14
Chapter 14
 
PATTERNS08 - Strong Typing and Data Validation in .NET
PATTERNS08 - Strong Typing and Data Validation in .NETPATTERNS08 - Strong Typing and Data Validation in .NET
PATTERNS08 - Strong Typing and Data Validation in .NET
 
Introduction to ado.net
Introduction to ado.netIntroduction to ado.net
Introduction to ado.net
 
Style Intelligence Evaluation Documentation
Style Intelligence Evaluation DocumentationStyle Intelligence Evaluation Documentation
Style Intelligence Evaluation Documentation
 
Dbms unit i
Dbms unit iDbms unit i
Dbms unit i
 
Sql interview question part 5
Sql interview question part 5Sql interview question part 5
Sql interview question part 5
 
Oracle to vb 6.0 connectivity
Oracle to vb 6.0 connectivityOracle to vb 6.0 connectivity
Oracle to vb 6.0 connectivity
 
Accessing data within VB Applications
Accessing data within VB ApplicationsAccessing data within VB Applications
Accessing data within VB Applications
 
ASP.NET Unit-3.pdf
ASP.NET Unit-3.pdfASP.NET Unit-3.pdf
ASP.NET Unit-3.pdf
 
Nhibernate Part 1
Nhibernate   Part 1Nhibernate   Part 1
Nhibernate Part 1
 
Bo df b_layer
Bo df b_layerBo df b_layer
Bo df b_layer
 
Schema webinar
Schema webinarSchema webinar
Schema webinar
 
Bank mangement system
Bank mangement systemBank mangement system
Bank mangement system
 
Introduction to sql server
Introduction to sql serverIntroduction to sql server
Introduction to sql server
 
Ado.Net Tutorial
Ado.Net TutorialAdo.Net Tutorial
Ado.Net Tutorial
 

More from Michael Heron

Meeple centred design - Board Game Accessibility
Meeple centred design - Board Game AccessibilityMeeple centred design - Board Game Accessibility
Meeple centred design - Board Game AccessibilityMichael Heron
 
Musings on misconduct
Musings on misconductMusings on misconduct
Musings on misconductMichael Heron
 
Accessibility Support with the ACCESS Framework
Accessibility Support with the ACCESS FrameworkAccessibility Support with the ACCESS Framework
Accessibility Support with the ACCESS FrameworkMichael Heron
 
ACCESS: A Technical Framework for Adaptive Accessibility Support
ACCESS:  A Technical Framework for Adaptive Accessibility SupportACCESS:  A Technical Framework for Adaptive Accessibility Support
ACCESS: A Technical Framework for Adaptive Accessibility SupportMichael Heron
 
Authorship and Autership
Authorship and AutershipAuthorship and Autership
Authorship and AutershipMichael Heron
 
Text parser based interaction
Text parser based interactionText parser based interaction
Text parser based interactionMichael Heron
 
GRPHICS08 - Raytracing and Radiosity
GRPHICS08 - Raytracing and RadiosityGRPHICS08 - Raytracing and Radiosity
GRPHICS08 - Raytracing and RadiosityMichael Heron
 
GRPHICS07 - Textures
GRPHICS07 - TexturesGRPHICS07 - Textures
GRPHICS07 - TexturesMichael Heron
 
GRPHICS05 - Rendering (2)
GRPHICS05 - Rendering (2)GRPHICS05 - Rendering (2)
GRPHICS05 - Rendering (2)Michael Heron
 
GRPHICS04 - Rendering (1)
GRPHICS04 - Rendering (1)GRPHICS04 - Rendering (1)
GRPHICS04 - Rendering (1)Michael Heron
 
GRPHICS03 - Graphical Representation
GRPHICS03 - Graphical RepresentationGRPHICS03 - Graphical Representation
GRPHICS03 - Graphical RepresentationMichael Heron
 
GRPHICS02 - Creating 3D Graphics
GRPHICS02 - Creating 3D GraphicsGRPHICS02 - Creating 3D Graphics
GRPHICS02 - Creating 3D GraphicsMichael Heron
 
GRPHICS01 - Introduction to 3D Graphics
GRPHICS01 - Introduction to 3D GraphicsGRPHICS01 - Introduction to 3D Graphics
GRPHICS01 - Introduction to 3D GraphicsMichael Heron
 
GRPHICS09 - Art Appreciation
GRPHICS09 - Art AppreciationGRPHICS09 - Art Appreciation
GRPHICS09 - Art AppreciationMichael Heron
 

More from Michael Heron (20)

Meeple centred design - Board Game Accessibility
Meeple centred design - Board Game AccessibilityMeeple centred design - Board Game Accessibility
Meeple centred design - Board Game Accessibility
 
Musings on misconduct
Musings on misconductMusings on misconduct
Musings on misconduct
 
Accessibility Support with the ACCESS Framework
Accessibility Support with the ACCESS FrameworkAccessibility Support with the ACCESS Framework
Accessibility Support with the ACCESS Framework
 
ACCESS: A Technical Framework for Adaptive Accessibility Support
ACCESS:  A Technical Framework for Adaptive Accessibility SupportACCESS:  A Technical Framework for Adaptive Accessibility Support
ACCESS: A Technical Framework for Adaptive Accessibility Support
 
Authorship and Autership
Authorship and AutershipAuthorship and Autership
Authorship and Autership
 
Text parser based interaction
Text parser based interactionText parser based interaction
Text parser based interaction
 
SAD04 - Inheritance
SAD04 - InheritanceSAD04 - Inheritance
SAD04 - Inheritance
 
GRPHICS08 - Raytracing and Radiosity
GRPHICS08 - Raytracing and RadiosityGRPHICS08 - Raytracing and Radiosity
GRPHICS08 - Raytracing and Radiosity
 
GRPHICS07 - Textures
GRPHICS07 - TexturesGRPHICS07 - Textures
GRPHICS07 - Textures
 
GRPHICS06 - Shading
GRPHICS06 - ShadingGRPHICS06 - Shading
GRPHICS06 - Shading
 
GRPHICS05 - Rendering (2)
GRPHICS05 - Rendering (2)GRPHICS05 - Rendering (2)
GRPHICS05 - Rendering (2)
 
GRPHICS04 - Rendering (1)
GRPHICS04 - Rendering (1)GRPHICS04 - Rendering (1)
GRPHICS04 - Rendering (1)
 
GRPHICS03 - Graphical Representation
GRPHICS03 - Graphical RepresentationGRPHICS03 - Graphical Representation
GRPHICS03 - Graphical Representation
 
GRPHICS02 - Creating 3D Graphics
GRPHICS02 - Creating 3D GraphicsGRPHICS02 - Creating 3D Graphics
GRPHICS02 - Creating 3D Graphics
 
GRPHICS01 - Introduction to 3D Graphics
GRPHICS01 - Introduction to 3D GraphicsGRPHICS01 - Introduction to 3D Graphics
GRPHICS01 - Introduction to 3D Graphics
 
GRPHICS09 - Art Appreciation
GRPHICS09 - Art AppreciationGRPHICS09 - Art Appreciation
GRPHICS09 - Art Appreciation
 
2CPP18 - Modifiers
2CPP18 - Modifiers2CPP18 - Modifiers
2CPP18 - Modifiers
 
2CPP17 - File IO
2CPP17 - File IO2CPP17 - File IO
2CPP17 - File IO
 
2CPP16 - STL
2CPP16 - STL2CPP16 - STL
2CPP16 - STL
 
2CPP15 - Templates
2CPP15 - Templates2CPP15 - Templates
2CPP15 - Templates
 

Recently uploaded

VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnAmarnathKambale
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providermohitmore19
 
Define the academic and professional writing..pdf
Define the academic and professional writing..pdfDefine the academic and professional writing..pdf
Define the academic and professional writing..pdfPearlKirahMaeRagusta1
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension AidPhilip Schwarz
 
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...Shane Coughlan
 
The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is insideshinachiaurasa2
 
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesVictorSzoltysek
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisamasabamasaba
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerThousandEyes
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...panagenda
 
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfonteinmasabamasaba
 
The Top App Development Trends Shaping the Industry in 2024-25 .pdf
The Top App Development Trends Shaping the Industry in 2024-25 .pdfThe Top App Development Trends Shaping the Industry in 2024-25 .pdf
The Top App Development Trends Shaping the Industry in 2024-25 .pdfayushiqss
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Steffen Staab
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Modelsaagamshah0812
 
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrainmasabamasaba
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...ICS
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️Delhi Call girls
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplatePresentation.STUDIO
 

Recently uploaded (20)

VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learn
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
Define the academic and professional writing..pdf
Define the academic and professional writing..pdfDefine the academic and professional writing..pdf
Define the academic and professional writing..pdf
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
 
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
OpenChain - The Ramifications of ISO/IEC 5230 and ISO/IEC 18974 for Legal Pro...
 
The title is not connected to what is inside
The title is not connected to what is insideThe title is not connected to what is inside
The title is not connected to what is inside
 
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
%in kaalfontein+277-882-255-28 abortion pills for sale in kaalfontein
 
The Top App Development Trends Shaping the Industry in 2024-25 .pdf
The Top App Development Trends Shaping the Industry in 2024-25 .pdfThe Top App Development Trends Shaping the Industry in 2024-25 .pdf
The Top App Development Trends Shaping the Industry in 2024-25 .pdf
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation Template
 

PATTERNS07 - Data Representation in C#

  • 2. Introduction  In the last lecture we looked at how event driven application in .NET work.  I’ll leave it (mostly) up to you to get to grips with C# syntax.  In this lecture we’re going to discuss the .NET data model in relation to objects (which you know) and ADO .NET (which you probably don’t.  ADO .NET is the database engine at the core of .NET.  As mentioned in previous lectures, data representation is key to eventual success with a system.
  • 3. C# Objects  C# objects look very much like Java objects.  Down to the syntax.  The prime differentiators are:  Declaration of a class within a namespace.  Accessors handled as properties.  Properties provide a syntactically consistent method of handling getting and setting of attributes.  Rather than the convention driven methods of Java.
  • 4. Class and Properties using System; namespace SimpleClassExample { class Person { private string name; private int age; public int Age { get { return age; } set { age = value; } } } }
  • 5. Making Use Of Objects using System; namespace SimpleClassExample { class Program { static void Main(string[] args) { Person me = new Person(); me.Age = 80; me.Name = "Michael"; me.adjustAge (1); Console.WriteLine(me.Name + " is " + me.Age + " years old"); } } }
  • 6. Encapsulation  All of the hard work of connecting to a database in C# is encapsulated in the data objects you work with.  All you need to learn is how these objects work, not how they interface with specific databases.  This means that once you have written the code to work with one database, it’s easy to change it to work with another.
  • 7. Bespoke Data  In the next lecture we’ll be talking about how to hook up a program to a database.  This is a powerful technique.  Before we get to that though, let’s talk a little bit about why we may want to do it.  And why we might not, on occasion.  It’s the difference between using a standard data layer (a database), and a more bespoke data solution (hand-rolled classes).
  • 8. Bespoke Data Advantages  Certain contexts demand bespoke data implementation.  Databases are optimised for certain kinds of file IO, but are costly for other operations.  Fast paced 3D games would be a good deal less fast-paced with a database back-end.  Very complex, tightly integrated data manipulation is much easier to do with a bespoke data model.  Bespoke models give you a lot of scope for context specific optimization.
  • 9. Database Advantages  Databases on the other hand, have advantages of their own.  They are already optimized for what they do.  Large file IO, searching, sorting, etc  Other people are constantly working on improving them.  A fix in the engine is a fix in your code too.  They offer a structured standard for interrogation.  You can easily provide many different views of a database because they all communicate with SQL.
  • 10. Bespoke Versus Database  When would you choose one over another?  The criteria I use is ‘how much does it matter to me how the data is stored?  For a simple web-based ecommerce system, a database is a clear choice with clear benefits.  For a complex simulation, bespoke data structures are probably better.  It is the application itself that will dictate this to you.
  • 11. Examples  You are a Scientist (doing science). You want to run a variation of Conway’s Game of Life to investigate properties of emergent behaviour.  Bespoke or Database?  You are a businessperson (doing business). You want to put up an online catalogue that shows your wares and lets people order them.  Bespoke or Database?
  • 12. Designing A Data Layer  An ideal application allows for the data representation to be abstracted from the application itself.  So you can change how data is represented, and it doesn’t matter.  This is sometimes known as an ‘3 tier’ architecture.  Bespoke data representations do not easily allow this.  You need to write a translation layer of your own.  ADO .NET permits the use of several underlying databases, (mostly) seamlessly.
  • 13. MVC The MVC is a design pattern that runs through the module.  Separate out the view from the controller from the model.  Or more usually, separate out the view/controller from the model.  Within the MVC, you can profitably look to separate out data representation from ‘business logic’  Through the incorporation of a dedicated data layer.
  • 14. ADO .NET  All of this leads us to the .NET way of doing databases.  ADO .NET  ADO .NET’s communication with databases is based on two key elements.  The Data Provider Framework  The Data Set  The data provider framework handles the work of connecting to an actual database.  The Data Set handles the work of communicating with applications.
  • 16. ADO .NET  It is possible to interact with a database in two ways.  Using the Data Reader, which is real-time.  Using Datasets, which are a snapshot of an underlying data representation.  We’ll be doing the latter.  Some example code on The Interwebs may use the former. Be mindful of this.  Data sets offer a good deal of flexibility.  They allow for database representation to be interchangeable with XML representation.
  • 17. Data Sets  As mentioned, data sets offer a snapshot of the underlying data source.  This is a disconnected, memory resident representation.  Think of it as making a copy of the data for your own purposes.  Datasets do not permit you to play with ‘live ammunition’.  If you change things in the dataset, your underlying database does not change until you tell it to.
  • 18. Data Sets  This creates some complications.  What happens if you have two data-sets pointing to the same database, and they have both been changed?  ADO .NET also offers the facility for merging data-sets together to deal with such situations.  Not something you should have to do, but again something to be mindful of.
  • 19. Data Sets  One of the biggest benefits of Data Sets is that they permit the access of underlying data in the same style as associative arrays.  Or ‘hashmaps’, or ‘mappings’, whatever term you may prefer.  This greatly simplifies the task of interacting with an underlying database.  SQL, for all its power, is not an easy language with which to Get Things Done.
  • 20. Objects and Databases  When you make a connection to a database in ADO .NET, it translates the database into objects you can manipulate.  These objects often have other objects as part of their makeup.  Effective working within ADO .NET requires you to be conversant with how these work.
  • 21. Objects and Databases  A lot of the work you do in setting up a database is done through Visual Studio itself.  What it’s doing though is creating and setting objects for you.  When it comes time to do anything ‘clever’ with our databases, we’ll need to make use of the objects.
  • 22. Step One: Making The Database Available  Choose ‘server explorer’ from the view menu.  Add a new data connection.  Right click on the server explorer and choose ‘add connection’  It will ask you where the database is located.
  • 23. Step One: Making The Database Available  If you have no u/p information, leave it as is.  Press ‘test connection’ to make sure that the connection works.  Then press ‘ok’.  Your database is then available in the server explorer under ‘data connections’.
  • 24. The Server Explorer  The Server Explorer gives you an ‘in IDE’ view of the data and database.  You can modify the table, execute queries, or enter data as needed.  Right click on the table you want to alter, and choose ‘retrieve data’
  • 25. Step 2: Data Adapter  Step two is to create a data adapter to extract information from the database.  The data adapter defines the specific information required by your application.  In cases of very large complex databases, it is vital to simplify data access routines.  Essentially a data adapter acts as a filter between the database and your application.
  • 26. Step 2: Data Adapter  In the C# .NET toolbox is a tab that says ‘data’.  This tab contains GUI components that represents aspects of the ADO .NET architecture.  The OleDBDataAdapter control lets us use the data connection wizard to set up an adapter.  If it’s not there, it needs to be added in manually.
  • 27. Step 2: Data Adapter  The wizard guides you through the process of setting up the adapter.  Step one, it asks which data connection to use.  You can choose from any nodes on the server explorer.  Step two, it asks how to access the database.  Choose ‘use SQL statements’.  Step three, it asks what SQL statement to use.  For now, we’re simply going to use a ‘select * from Customer’ statement.
  • 28. Step 2: Data Adapter  Once these three steps have been taken, the data adapter is configured.  It will create an instance of the object in the ‘invisible controls’ part of the IDE.  This control can be accessed in code the same way as any other control.  It just doesn’t appear explicitly on the form.  Once you have this, we can move onto step 3.
  • 29. Step 3: Dataset  The next step is to create an object that represents the data we wish to use in our program.  This object is called a dataset.  The dataset is a snapshot of some specific part of the database.  It can come from tables  It can come from queries  It can come from SQL statements.
  • 30. Step 3: Dataset  To create a dataset, we must click on the form to make sure it is active.  Right click on the form to bring up the context sensitive menu, and select generate dataset.  This will bring up the generation dialog.
  • 31. Step 3: Dataset  We are going to create a new dataset, so enter a identifier for the dataset in the ‘new’ box.  By convention, datasets have a ds prefix.  Ours will be called dsCustomer  The list of tables to be used for the dataset comes from the data adapter on your form.  Click on ‘ok’ to generate the dataset… it will appear in the component tray along with the data adapter.
  • 32. Voila!  Once you have the dataset generated, you have a framework in your application suitable for linking up to controls.  In this lecture, we will look only at using standard text boxes as data aware controls.  Next week we’ll look at some more complex examples.
  • 33. Displaying Data  ADO .NET doesn’t simply dump an Access table in your application.  Instead, you have to explicitly decide what controls are to display which parts of the database.  Most controls in C# can be bound to a database.  One control especially suited to this is the textbox control.
  • 34. Displaying Data  Textboxes have many properties associated with them.  A category of these properties are known as data properties.  We use these to link the textbox to the dataset.  textBox1.DataBindings.Add (new Binding ("Text", dsCustomer1, "Customer.FirstName"));  textBox2.DataBindings.Add (new Binding("Text", dsCustomer1, "Customer.SurName"));
  • 35. Displaying Data  Click on the text link under the data category.  It will bring up a list of datasets defined on the form.  They each have a little + beside them.  We can expand this tree until we find the field we want to display in the text box.
  • 36. Displaying Data  We do this for each field we want to display on the form.  As said previously, many controls can make use of the same dataset.  If we set up all our controls in this way and then run, nothing will appear in the next box.  We’re not done yet.
  • 37. One Last Step  Finally, we need to add some code to our application to set up the dataset and link it to the adapter.  You thought we’d done that already?  We must manually fill the dataset from the adapter. We do that with the following lines of code: YourDataset.Clear() YourDataAdapter.Fill(YourDataSet)
  • 38. One Last Step  For example, with a dataset called dsMyStuff and a data adapter called OleDBDataAdapter1: dsMyStuff.Clear() OleDBDataAdapter1.Fill (dsMyStuff)  Where you do this depends on when you want the dataset filled.  In the load event of a form is good if you want it done immediately.
  • 39. Navigation  Okay, we’ve set up the controls and are displaying some data.  How do we navigate through it?  ADO .NET keeps track of information about the current record and total number of records in a dataset through use of an object called a CurrencyManager.  Each form in C# has a BindingContext object that keeps track of all the CurrencyManager objects.
  • 40. Navigation  The specifics of this are unimportant.  All we want to know is ‘how to we navigate through records?’.  Despite the complex structure, the code to navigate through controls is pretty simple.  We can access the BindingContext for a dataset on a form using the this keyword.
  • 41. Navigation  Consider a form with a dataset called dsPeople and a table in that dataset called Persons: this.BindingContext [dsPerson1, “Person”]  A BindingContext has some useful properties for us to use:  Position  Count
  • 42. Navigation  The position property determines where in the dataset we currently are.  The count property holds how many records are in the dataset.  We can manipulate the position property to move forwards and backwards through the dataset.
  • 43. Navigation  Next: this.BindingContext[dsCustomer1, "Customer"].Position += 1;  Previous: this.BindingContext[dsCustomer1, "Customer"].Position -= 1;  Last: this.BindingContext[dsCustomer1, "Customer"].Position = this.BindingContext[dsCustomer1, "Customer"].Count - 1;  First: this.BindingContext[dsCustomer1, "Customer"].Position = 0;  These code extracts can be bound to buttons allowing the user to navigate through the datasets.
  • 44. Conclusion  Data Representation is an important concept.  Something the more nerdy amongst us often lose sleep over.  In any application you have a choice between bespoke representation and a database engine.  You should decide which of these to use on the basis of your application.