1 11/15/05CS360 Windows Programming ADO.NET Continued.

Slides:



Advertisements
Similar presentations
17. Data Access ADO.Net Architecture New Features of ADO.NET
Advertisements

ADO vs ADO.NET ADOADO.NET Client/server coupledDisconnected collection of data from data server Uses RECORDSET object (contains one table) Uses DATASET.
1 Web-Enabled Decision Support Systems Advance Topics in Database Connectivity Prof. Name Position (123) University Name.
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.
Chapter 12: ADO.NET and ASP.NET Programming with Microsoft Visual Basic.NET, Second Edition.
1 ADO.NET. 2.NET Framework Data Namespaces System.Data –Base set of classes and interfaces for ADO.NET System.Data.Common –Classes shared by the.NET Data.
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.
.NET Mobile Application Development Data in Distributed Systems Accessing Data with.NET.
C# Programming: From Problem Analysis to Program Design1 Working with Databases C# Programming: From Problem Analysis to Program Design 3 rd Edition 14.
Chapter 12 Database Connectivity with ASP.NET JavaScript, Third Edition.
From VS C# 2010 Programming, John Allwork 1 VS2010 C# Programming - DB intro 1 Topics – Database Relational - linked tables SQL ADO.NET objects Referencing.
Chapter 8 Binding Data to Web Controls. ASP.NET 2.0, Third Edition2.
Chapter 9 Using the SqlDataSource Control. References aspx.
ADO.NET – part II August 2004 [ Marmagna Desai]. CONTENTS ADO vs ADO.NET ADO.NET – Managed providers Connecting to Database SqlConnection Selecting Database.
Introduction to ADO.Net and Visual Studio Database Tools ISYS 512.
ADO.NET Tools and Wizards. Slide 2 Data Sources Window (Introduction) Use the Data Sources window to Establish a connection Create bound control instances.
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.
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)
Databases and Data Access  Introduction to ADO.NET  ADO.NET objects  ADP.NET namespaces  Differences between ADO and ADO.NET.
ADO.Net CS795. What is ADO.Net? Database language spoken by managed applications ADO.net database accesses go through modules: data providers –SQL Server.Net.
© Copyright by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Tutorial 30 – Bookstore Application: Client Tier Examining.
.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 Database Development Using Borland Data Providers 2128 Martin Rudy.
1 Introduction to ADO.NET Microsoft ADO.NET 2.0 Step by Step Rebecca M Riordan Microsoft Press, 2006.
Database, SQL, and ADO.NET- Part 1 Session 11 Mata kuliah: M0874 – Programming II Tahun: 2010.
© FPT SOFTWARE – TRAINING MATERIAL – Internal use 04e-BM/NS/HDCV/FSOFT v2/3 Working with Disconnected Data The DataSet and SqlDataAdapter ADO.NET - Lesson.
Objectives In this lesson, you will learn to: *Identify the need for ADO.NET *Identify the features of ADO.NET *Identify the components of the ADO.NET.
1 Introduction to Database Systems CSE 444 Lecture 06 SQL in C#, Project October 5, 2007.
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
ADO.NET Data Access. Page  2 SQL  When we interact with the datasource through ADO.NET we use the SQL language to retrieve,modify,update information.
© FPT SOFTWARE – TRAINING MATERIAL – Internal use 04e-BM/NS/HDCV/FSOFT v2/3 Introduction to ADO.NET ADO.NET - Lesson 01  Training time: 10 minutes  Author:
Presented by Joseph J. Sarna Jr. JJS Systems, LLC
Lecture Set 14 B new Introduction to Databases - Database Processing: The Connected Model (Using DataReaders)
An Introduction to ADO.Net Marmagna Desai.NET Seminar, Fall-2003.
 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.
C# Programming in Depth Prof. Dr. Bertrand Meyer March 2007 – May 2007 Chair of Software Engineering Lecture 10: Database Lisa (Ling) Liu.
Mauricio Featherman, Ph.D. Washington St. University
DEV383 The ADO.NET DataSet and You Jackie Goldstein General Manager Renaissance Computer Systems
ADO.Net CS795. What is ADO.Net? Database language spoken by managed applications ADO.net database accesses go through modules: data providers –SQL Server.Net.
Module 3: Working with Local Data. Overview Using DataSets Using XML Using SQL Server CE.
DataSets Demystified. Who I am Shawn Wildermuth Senior Consultant with Magenic Technologies ( C# MVP INETA.
ADO.NET FUNDAMENTALS BEGINNING ASP.NET 3.5 IN C#.
Module 4 Introduction ADO.NET.
C# .NET Software Development
ADO.NET Objects Data Adapters Dr. Ron Eaglin. Agenda Builds on Information in Part I Should have working knowledge of creating a database connection Continuation.
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.
Introduction to ADO.Net and Visual Studio Database Tools ISYS 350.
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
DAT 390 Advanced ADO.NET Programming Techniques Jackie Goldstein Renaissance Computer Systems
Common SQL keywords. Building and using CASE Tools Data Base with Microsoft SQL-Server and C#
Introduction to Database Processing with ADO.NET
Introduction to Database Processing with ADO.NET
ADO.NET Framework.
© 2016, Mike Murach & Associates, Inc.
Programming the Web Using ASP.Net
ADO.Net and Stored Procedures
Chapter 10 ADO.
PROG Advanced Web Apps 4/13/2019 Programming Data Pages Wendi Jollymore, ACES.
M S COLLEGE OF ART’S, COMM., SCI. & BMS Advance Web Programming
Presentation transcript:

1 11/15/05CS360 Windows Programming ADO.NET Continued

2 11/15/05CS360 Windows Programming DataSets & DataAdapters  SqlDataReader provides stream-based access to the results of database queries  Read-only, forward-only  Could be an inconvenience  ADO.NET provides a set-based access as well as a stream-based access

3 11/15/05CS360 Windows Programming DataSets & DataAdapters  DataSet: in-memory database  SqlDataAdapter: bridge between real database and datasets

4 11/15/05CS360 Windows Programming DataSet  DataTable objects are analogous to tables in a database  DataSet.Tables property lists DataTables  There are also DataRow and DataColumn objects  Ideal for capturing the result of database queries and modifying the data  Useful for caching. How?

5 11/15/05CS360 Windows Programming DataSets vs. DataReaders  Which is better? o It depends

6 11/15/05CS360 Windows Programming DataAdapter Classes  DataSets are mostly initialized from database queries or XML documents  DataSets do not interact with the database directly  DataAdapters perform database queries and create DataTables containing the query results  When working with Microsoft SQL Server, we are concerned with SqlDataAdapter

7 11/15/05CS360 Windows Programming Example SqlDataAdapter adapter = new SqlDataAdapter (“select * from titles”, “server=localhost;database=pubs;uid=sa; pwd=“); DataSet ds = new DataSet(); Adapter.Fill(ds, “Titles”);

8 11/15/05CS360 Windows Programming What Happens? 1. Fill opens a connection to the pubs database using the connection string 2. It performs a query using the query string 3. It creates a DataTable named “Titles” in the DataSet 4. It initializes the DataTable with a schema that matches “titles” in database 5. It retrieves all records produced by the query and writes them to the DataTable 6. It closes the connection to the database

9 11/15/05CS360 Windows Programming DataTable and Friends  A DataSet is a collection of DataTables foreach(DataTable table in ds.Tables) Console.WriteLine(table.TableName);

10 11/15/05CS360 Windows Programming DataTable and Friends  Individual DataTables can be referenced by name or index  DataTables contain DataRows DataTable table = ds.Tables[0]; foreach(DataRow row in table.Rows) Console.WriteLine(row[0]);  Could also use column name instead of index

11 11/15/05CS360 Windows Programming DataTables  You can also enumerate a DataTable’s columns DataTable table = ds.Tables[0]; foreach(DataColumn col in table.Columns) Console.WriteLine(“Name={0}, Type={1}”, col.ColumnName, colDataType);

12 11/15/05CS360 Windows Programming Adding Rows to a Table  Perform a query with DataAdapter.Fill, add records to the resulting DataTable, and write the changes to the database SqlDataAdapter adapter = new SqlDataAdapter ("select * from titles", "server=localhost;database=pubs;uid=sa;pwd="); DataSet ds = new DataSet (); adapter.Fill (ds, "Titles"); DataTable table = ds.Tables["Titles"]; DataRow row = table.NewRow (); row["title_id"] = "JP1001"; row["title"] = "Programming Microsoft.NET"; row["price"] = "59.99"; row["ytd_sales"] = " "; row["type"] = "business"; row["pubdate"] = "May 2002"; table.Rows.Add (row);

13 11/15/05CS360 Windows Programming Searching Records in a DataTable  Use Select DataRow[] rows = table.Select ("title_id = 'JP1001'"); DataRow[] rows = table.Select ("price < 10.00"); // Return all rows where "State" equals CA, TN, or WA DataRow[] rows = table.Select ("state in ('ca', 'tn', 'wa')"); // Return all rows where "State" begins with CA DataRow[] rows = table.Select ("state like 'ca*'");

14 11/15/05CS360 Windows Programming Updating Records in a DataTable SqlDataAdapter adapter = new SqlDataAdapter ( "select * from titles", "server=localhost;database=pubs;uid=sa;pwd="); DataSet ds = new DataSet (); adapter.Fill (ds, "Titles"); DataRow[] rows = table.Select ("ytd_sales > 10000"); foreach (DataRow row in rows) row["price"] = (decimal) row["price"] m;

15 11/15/05CS360 Windows Programming Deleting Records from a Table SqlDataAdapter adapter = new SqlDataAdapter ( "select * from titles", "server=localhost;database=pubs;uid=sa;pwd="); DataSet ds = new DataSet (); adapter.Fill (ds, "Titles"); DataRow[] rows = table.Select ( "ytd_sales < OR isnull (ytd_sales, 0) = 0"); foreach (DataRow row in rows) row.Delete ();

16 11/15/05CS360 Windows Programming Propagating Changes  Inserts, updates, and deletes performed on a DataTable do not automatically propagate back to the database

17 11/15/05CS360 Windows Programming SqlDataAdapter adapter = new SqlDataAdapter ("select * from titles", "server=localhost;database=pubs;uid=sa;pwd="); SqlCommandBuilder builder = new SqlCommandBuilder (adapter); DataSet ds = new DataSet (); adapter.Fill (ds, "Titles"); DataTable table = ds.Tables["Titles"]; DataRow row = table.NewRow (); row["title_id"] = "JP1001"; row["title"] = "Programming Microsoft.NET"; row["price"] = 59.99m; row["ytd_sales"] = ; row["type"] = "business"; row["pubdate"] = new DateTime (2002, 5, 1); table.Rows.Add (row); adapter.Update (table);

18 11/15/05CS360 Windows Programming Update Only Changes  Could specify that only changes be updated // Update the database DataTable delta = table.GetChanges (); adapter.Update (delta);  Not necessary o Update is smart enough

19 11/15/05CS360 Windows Programming CommandBuilder  How does Update physically update the database?  Executes SQL commands o INSERT, UPDATE, DELETE  Manufactured by SqlCommandBuilder

20 11/15/05CS360 Windows Programming DataView SqlDataAdapter adapter = new SqlDataAdapter ("select * from titles", "server=localhost;database=pubs;uid=sa;pwd="); DataSet ds = new DataSet (); adapter.Fill (ds, "Titles"); DataView view = new DataView (ds.Tables["Titles"]); view.Sort = "title ASC"; MyDataGrid.DataSource = view; MyDataGrid.DataBind ();

21 11/15/05CS360 Windows Programming Summary  Completed Chapter 12  Next Time o XML o Multithreading