Tonga Institute of Higher Education

Slides:



Advertisements
Similar presentations
17. Data Access ADO.Net Architecture New Features of ADO.NET
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.
ADO. NET. What is “ADO.Net”? ADO.Net is a new object model for dealing with databases in.Net. Although some of the concepts are similar to the classical.
ASP.NET Database Connectivity I. 2 © UW Business School, University of Washington 2004 Outline Database Concepts SQL ASP.NET Database Connectivity.
Coding ADO.NET Objects: Connection, Command, DataReader.
ASP.NET Programming with C# and SQL Server First Edition Chapter 8 Manipulating SQL Server Databases with ASP.NET.
Chapter 12 Database Connectivity with ASP.NET JavaScript, Third Edition.
Chapter 11 Introduction to Database Processing. Class 11: Database Processing Use a Visual Studio Wizard to establish a database connection used to load.
Programming with Visual Basic.NET An Object-Oriented Approach  Chapter 8 Introduction to Database Processing.
ODBC, OLE DB, and ADO Introduction Dr. Ron Eaglin.
Chapter 61 Managing Data Sources Introduction to ASP.NET By Kathleen Kalata.
ADO.NET Tools and Wizards. Slide 2 Data Sources Window (Introduction) Use the Data Sources window to Establish a connection Create bound control instances.
1 ASP.NET ASP.NET Rina Zviel-Girshin Lecture 4. 2 Overview Data Binding Data Providers Data Connection Data Manipulations.
Developing Web Applications Using Microsoft ® Visual Studio ® 2008.
A Simple Introduction. What is ADO.net? First the word ADO stands for ActiveX Data Objects And it is an integral part of.Net Framework of Microsoft hence.
Lecture Set 14 B new Introduction to Databases - Database Processing: The Connected Model (Using DataReaders)
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 and Data Access  Introduction to ADO.NET  ADO.NET objects  ADP.NET namespaces  Differences between ADO and ADO.NET.
.NET Data Access and Manipulation ADO.NET. Overview What is ADO.NET? Disconnected vs. connected data access models ADO.NET Architecture ADO.NET Core Objects.
Introduction to MySQL Lab no. 10 Advance Database Management System.
1 Introduction to ADO.NET Microsoft ADO.NET 2.0 Step by Step Rebecca M Riordan Microsoft Press, 2006.
Chapter 3 Introduction to ADO.NET 3.1 The ADO and ADO.NET ActiveX Data Object (ADO) is developed based on Object Linking and Embedding (OLE) and Component.
 It is the primary data access model for.Net applications  Next version of ADO  Can be divided into two parts ◦ Providers ◦ DataSets  Resides in System.Data.
ASP.NET Rina Zviel-Girshin Lecture 5
Module 9: Accessing Relational Data Using Microsoft Visual Studio.NET.
Session 8: ADO.NET. Overview Overview of ADO.NET What is ADO.NET? Using Namespaces The ADO.NET Object Model What is a DataSet? Accessing Data with ADO.NET.
Module 7: Accessing Data by Using ADO.NET
Christopher M. Pascucci.NET Programming: Databases & ADO.NET.
Presented by Joseph J. Sarna Jr. JJS Systems, LLC
Lecture Set 14 B new Introduction to Databases - Database Processing: The Connected Model (Using DataReaders)
 It is the primary data access model for.Net applications  Next version of ADO  Can be divided into two parts ◦ Providers ◦ DataSets  Resides in System.Data.
1 Data Classes- DataView DataGridView Control. Objectives 2  Data Class  DataAdapter  DataReader  DataSet  DataTable  DataView  DataGridView Control.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Outline 25.1 Test-Driving the ATM Application 25.2.
HNDIT Rapid Application Development
ADO.NET FUNDAMENTALS BEGINNING ASP.NET 3.5 IN C#.
Module 4 Introduction ADO.NET.
C# .NET Software Development
Active Data Objects Using.Net ADO.Net Farooq Ahmed Amna Umber Summayya Shehzad.
Module 5 Data Classes DataView – DataGridView Control 1.
Module 2: Using ADO.NET to Access Data. Overview ADO.NET Architecture Creating an Application That Uses ADO.NET to Access Data Changing Database Records.
Data Access. ADO.NET ADO.NET is the primary library for building database solutions within the.NET Framework. ADO.NET does not replace ADO. ADO and OLEDB.
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.
.NET Data Access and Manipulation
Integrating Data Lesson 6.
Common SQL keywords. Building and using CASE Tools Data Base with Microsoft SQL-Server and C#
ASP.NET Programming with C# and SQL Server First Edition
Data Access with ADO.NET
Introduction to ADO.NET
Introduction to Database Processing with ADO.NET
Database, SQL and ADO.NET
Copyright Scott-Jones Publishing, All rights reserved.
Introduction to Database Processing with ADO.NET
Databases.
ADO.NET Framework.
Programming the Web Using ASP.Net
How to Create Login Form using vb.net and SqlServer Database
Lecture 6 VB.Net SQL Server.
Active Data Objects Binding ASP.NET Controls to Data
ADO.NET Accessing Databases in VS.NET
VB.NET Using Database.
ISC440: Web Programming 2 Server-side Scripting PHP 3
מתחברים למסד נתונים היכרות עם ADO.Net.
Lecture Set 14 B new Introduction to Databases - Database Processing: The Connected Model (Using DataReaders)
Database Objects 1/12/2019 See scm-intranet.
Chapter 10 ADO.
Coding ADO.NET Objects: Connection, Command, DataReader
PROG Advanced Web Apps 4/13/2019 Programming Data Pages Wendi Jollymore, ACES.
Active Data Objects Binding ASP.NET Controls to Data
M S COLLEGE OF ART’S, COMM., SCI. & BMS Advance Web Programming
Presentation transcript:

Tonga Institute of Higher Education Data Access Tonga Institute of Higher Education

Introduction Many programs work with large amounts of data Databases are an good place to store data Programs need a way to connect to, get data from and save data to databases ActiveX Data Objects .Net (ADO .Net) provides way to access data from Object Linking and Embedding Database (OLE DB)-compliant data sources such as SQL Server and Oracle.

ADO .Net Components .Net Data Providers – Objects designed for connecting to a database, executing commands and retrieving results Connection Command DataReader DataAdapter

Connection Object Connection Object – Provides connectivity to a data source SQLConnection object – Allows connection to a Microsoft SQL Server 7.0 or later database Located in System.Data.SQLClient namespace OLEDbConnection object – Allows connection to an OLE DB data source Located in System.Data.OleDb namespace Microsoft Access is an OLE DB compliant database

Connection Strings The SQLConnection and OLEDbConnection objects both use connection strings to connect to a data source Connection String – Provides information needed to connect to a database You do not need to include everything in a connection string. Only include what is needed. SQLConnection object SQL Server Initial Catalog=pubs;Data Source=(local);User ID=sa;password=; OLEDbConnection object Oracle Provider=msdaora;Data Source=MyOracleDB;User ID=myUsername;Password=myPassword; Microsoft Access Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\northwind.mdb Provider=Microsoft.Jet.OLEDB.4.0;Data Source=\\tihe1\student.mdb You don’t always need a User ID and Password Local DB Network DB

Opening and Closing Connections Before a Connection object can work with a database, the connection must be opened Use the Open() method After the Connection object is used, the connection must be closed Use the Close() method

Command Object Command Object – Enables the execution of queries and return of data from a data source A Connection object must be specified to connect to a data source A SQL statement must be specified for execution at the data source There are different ways to execute SQL statements ExecuteNonQuery() – Use this when data will not be returned ExecuteReader() – Use this when data will be returned

ExecuteNonQuery Code ExecuteNonQuery does not return anything

Connections, Commands and ExecuteNonQuery Demonstration Connections, Commands and ExecuteNonQuery

DataReader Object DataReader Object – Provides a stream of data from the data source Useful members FieldCount Get<DataType> GetByte GetString And more HasItems Item Read

DataReader and ExecuteReader Code Using a DataReader to display data from database ExecuteReader returns A DataReader Keeps looping until all rows are read Gets string from first index

Connections, Commands and DataReader.ExecuteReader Code Demonstration Connections, Commands and DataReader.ExecuteReader Code

DataSet Object DataSet –An in-memory database Useful members (* covered later) Clear Tables* DataSet

DataTable Object A DataTable object is an in-memory database table. It contains: Rows and columns of data Primary key, foreign key, constraint and relation information about the data Useful members (* covered later) ChildRelations* Clear Columns* Constraints* DataSet NewRow ParentRelations* PrimaryKey TableName DataTables

DataColumn Object A DataColumn object represents a table column Useful members AllowDBNull AutoIncrement AutoIncrementSeed AutoIncrementStep Caption ColumnName DataType DefaultValue MaxLength Ordinal Table Unique DataColumn

DataRow Object A DataRow Object represents a row of data in a table Useful members Item Table DataRow

DataSets, DataTables, DataColumns and DataRows Demonstration DataSets, DataTables, DataColumns and DataRows

DataTableCollection A DataTableCollection contains DataTables Access the DataTableCollection of a DataSet by using the Tables property Useful members Add Count Clear Item Remove

Demonstration DataTableCollection

DataColumnCollection A DataColumnCollection contains DataColumns Access the DataColumnCollection of a DataTable by using the Columns property Useful members Add Count Clear Item Remove

DataColumnCollection Demonstration DataColumnCollection

DataRowCollection A DataRowCollection contains DataRows Access the DataRowCollection of a DataTable by using the Rows property Useful members Add Count Clear Item Remove

Demonstration DataRowCollection

DataAdapter Object DataAdapter – Used to retrieve data from a database and put it in a DataSet. Can also send changes from the DataSet to the database Useful members Fill Update

DataAdapter Code The Fill method opens the Connection if the connection is not already open. If Fill opened the connection, it will also close the connection.

Demonstration DataAdapter Object

Programmatically Creating DataSet Objects DataSets, DataTables, DataRows and DataColumns are all objects We can create and customize all of these objects

Programmatically Creating DataSet Objects Code

Programmatically Creating DataSet Objects Demonstration Programmatically Creating DataSet Objects

DBNull, Nothing and “” There is a difference between having No Data And “” In a database, use null when you have no data In VB.Net Use “” when you have an empty string Use nothing when there is no data in a variable Use dbnull when there is no data in a database field

Demonstration DBNull, Nothing and “”

Storing Single Quotation Marks in a Database We often store SQL queries in a string Dim SQL as String = “Insert into Students (FirstName) values (‘Tevita’)” SQL queries use single quotation marks To store a single quote in a database, use the single quote twice Dim SQL as String = “Insert into Students (FirstName) values (‘Ma’’afu’)”

Storing Single Quotation Marks in a Database Demonstration Storing Single Quotation Marks in a Database

Data Access Exceptions Often, errors occur when databases are used. The name of the file is changed The location of a file is incorrect The program does not have the proper username and password to access the database Common Data Access Exceptions DataException - Exception that is thrown when errors are generated using ADO.NET components. ConstraintException - Exception that is thrown when attempting an action that violates a constraint. NoNullAllowedException - Exception that is thrown when attempting to insert a null value into a column where AllowDBNull is set to false. ReadOnlyException - Exception that is thrown when attempting to change the value of a read-only column.

Data Access Exceptions Demonstration Data Access Exceptions