Mauricio Featherman, Ph.D. Washington St. University

Slides:



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

Data Base. Objective Become familiar with database terminology. Create a project to display data for a single database table. Use a DataGrid control.
Chapter 10 Database Applications Copyright © 2011 by The McGraw-Hill Companies, Inc. All Rights Reserved. McGraw-Hill.
Chapter 18 - Data sources and datasets 1 Outline How to create a data source How to use a data source How to use Query Builder to build a simple query.
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.
Chapter 12: Using ADO.NET 2.0 Programming with Microsoft Visual Basic 2005, Third Edition.
Introduction to Database Processing with ADO.NET.
Chapter 12: ADO.NET and ASP.NET Programming with Microsoft Visual Basic.NET, Second Edition.
Using ADO.NET Chapter Microsoft Visual Basic.NET: Reloaded 1.
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.
ASP.NET Database Connectivity I. 2 © UW Business School, University of Washington 2004 Outline Database Concepts SQL ASP.NET Database Connectivity.
VB.NET Database Access ISYS 812. Microsoft Universal Data Access ODBC: Open Database Connectivity –A driver manager –Used for relational databases OLE.
1 Pertemuan 09 Database Matakuliah: D0524 / Algoritma dan Pemrograman Komputer Tahun: 2005 Versi:
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.
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.
Introduction to ADO.Net and Visual Studio Database Tools ISYS 512.
10-1 aslkjdhfalskhjfgalsdkfhalskdhjfglaskdhjflaskdhjfglaksjdhflakshflaksdhjfglaksjhflaksjhf.
ADO.NET Tools and Wizards. Slide 2 Data Sources Window (Introduction) Use the Data Sources window to Establish a connection Create bound control instances.
Navigating database with windows forms.. Tiered applications  Provide a means to develop many presentations of the same app  Makes changes to the back.
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.
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.
CHAPTER EIGHT Accessing Data Processing Databases.
CHAPTER EIGHT Accessing Data Processing Databases.
1 Introduction to ADO.NET Microsoft ADO.NET 2.0 Step by Step Rebecca M Riordan Microsoft Press, 2006.
 2006 Pearson Education, Inc. All rights reserved Database, SQL and ADO.NET.
© 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.
ASP.NET Rina Zviel-Girshin Lecture 5
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.
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:
Lecture Set 14 B new Introduction to Databases - Database Processing: The Connected Model (Using DataReaders)
1 Chapter 20 – Data sources and datasets Outline How to create a data source How to use a data source How to use Query Builder to build a simple query.
Introduction to ADO.Net and VS Database Tools and Data Binding ISYS 350.
DEV383 The ADO.NET DataSet and You Jackie Goldstein General Manager Renaissance Computer Systems
DataSet Your Database student test score Database Connection Your program needs to establish a connection to the database. Click on “Add New Data Source.”
Databases and ADO.NET Programming Right from the Start with Visual Basic.NET 1/e 11.
Module 3: Working with Local Data. Overview Using DataSets Using XML Using SQL Server CE.
1 11/15/05CS360 Windows Programming ADO.NET Continued.
HNDIT Rapid Application Development
ADO.NET FUNDAMENTALS BEGINNING ASP.NET 3.5 IN C#.
1 Database Programming with ADO.NET Kashef Mughal.
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 2: Using ADO.NET to Access Data. Overview ADO.NET Architecture Creating an Application That Uses ADO.NET to Access Data Changing Database Records.
Chapter Fourteen Access Databases and SQL Programming with Microsoft Visual Basic th Edition.
1 Working with MS SQL Server Beginning ASP.NET in C# and VB Chapter 12.
Chapter 9 Working with Databases. Copyright © 2011 Pearson Addison-Wesley Introduction In this chapter you will learn: – Basic database concepts – How.
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.
Programming with Microsoft Visual Basic 2012 Chapter 14: Access Databases and SQL.
.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.
Programming the Web Using ASP.Net
Lecture 6 VB.Net SQL Server.
Active Data Objects Binding ASP.NET Controls to Data
VB.NET Using Database.
Stores data in different tables
Chapter 10 ADO.
PROG Advanced Web Apps 4/13/2019 Programming Data Pages Wendi Jollymore, ACES.
Chapter 10 Accessing Database Files
Active Data Objects Binding ASP.NET Controls to Data
M S COLLEGE OF ART’S, COMM., SCI. & BMS Advance Web Programming
Presentation transcript:

Mauricio Featherman, Ph.D. Washington St. University Interacting with a Database using Code: DataAdapter’s, DataTables, and DataSets Mauricio Featherman, Ph.D. Washington St. University

Steps to Retrieve Data Web Form Data Adapter or Data Base Connection TableAdapter Data Base Connection Dataset Windows Form Specific file Connection specifies userID, password, database type and name Runs the fill operation (filling the dataset with the required data) RAM-copy of actual data, can contain multiple tables Bound controls display data 2

Steps to Update Data Web Form Data Base Connection Dataset Windows TableAdapter or Data Adapter w/ Command- Builder Web Form Data Base Connection Dataset Windows Form Tables within a dataset have data which needs to be sent to the database The specified database table gets updated DataAdapter- Or TableAdapter performs the SQL updates TableAdapter or DataAdapter uses the connection info to push the changes to the right database and server Form controls are bound to dataset and update data in a dataset 3

ADO.NET Architecture Data Base TableAdapter or DataAdapter Fill dataset with data retrieved from the database The Commands below are used in DataAdapter.Update TableAdapter or DataAdapter DataTables are created, filled with data, and added to the DataSet in the RAM of the PC SelectCommand used in DataAdapter.Fill Data Base Connection Connection String Take updated data from dataset and send it to the database VB forms are used to update the data in the dataset. The dataAdapters sends this in-memory data back to the db. UpdateCommand InsertCommand DeleteCommand

ADO.NET Theory In multi-user databases, often its more efficient for programs to interact with in-memory data rather than interact directly with a database. This is the reason for using dataset’s and the datatable which resides within them When the user wants to push their changes back to the database, the dataAdapter does this very efficiently in batch mode (in bulk). For projects which use code, a dataAdapter does the fetching and updating work. For projects which use a datasource wizard a TableAdapter does the work (their about the same thing)

DataAdapters (DA’s) … Are a bundle of SQLCommands, which fetch the data running a SQL (structured query language) Select command, or update the database using Insert, Delete, or Update commands You have to create dataAdapters telling them which table of data to fetch (the entire table or a subset) (ex: Public shared DA as new SQLDataAdapter(“Select * from Sales”, conn) (ex: Public shared DA as new SQLDataAdapter(“Select * from Sales where Region = ‘West’) ”, conn) Here the database table name is Sales and the connection (conn) is used. (The connection is already connected).

DataAdapter.Fill(DataSet, “DataTableName”) OK what’s the DA doing? Opens the connection to the database Executes the .selectcommand (SQL SELECT statement) of the dataAdapter (probably fetch a subset of the data) Creates a dataTable in the specified dataset passing in the schema from the database table specified in the Select statement, and the tablename you specify Adds the dataTable to the dataset’s table collection (list) Fills the rows collection of the dataTable with the retrieved data from the database Closes the connection to the database

DataAdapter’s best buddy DA’s best friend is the commandbuilder (it’s a helper class) which helps out by generating a lot of code (sweet!) YOU simply need to create the commandbuilder and “connect it” to the DataAdapter (here daJobs) Ex: Public shared New SqlCommandBuilder(daJobs) If you associate a commandbuilder with a dataAdapter, the commandbuilder will auto-generate appropriate SQLCommands for you based on the table’s schema’s

DataAdapter.Update(DataSet, “DataTableName”) OK what’s the DA doing? So when the .update method gets run each row of the dataTable specified in the update statement are examined for changes for added rows the dataAdapter fires its .InsertCommand for modified rows the dataAdapter fires its .UpdateCommand for deleted rows the dataAdapter fires its .DeleteCommand for original unchanged rows the dataAdapter skips to the next row So every row in the dataTable is examined and the appropriate action is taken. Wait! What if the dataTable is hundred’s of thousands of records? Well dataAdapters are insanely fast!

Datasets (DS) DataSets are a container for dataTables so that the dataTables can be related to each other (have foreign key relationships) The dataset holds the structure of each table (column names and data types) and the relationships between them. In a VB project you can see this content looking at the .xsd file. Word of caution, If you use wizards to create a dataset, after doing so, don’t change any column names, data types in your database. The snapshot of the schema (the .xsd file) won’t work anymore. You’ll have to delete all the objects the wizard created. FYI if you have a dataset with 2 tables then you’ll need 2 dataAdapters and 2 commandbuilders.

Datatables The data in Datasets actually resides in the rows of its datatables. The columns collection of the dataTable holds the schema information. This info is the same as stored in the database structure. Once we get the DataAdapter to fill the Datatables of a Dataset, we can bind controls to it using their .datasource property Because the datatables hold the actual data, when dataAdapters fetch data they push it into a dataTable. And, when dataAdapters push updates back to the database they actually look through the rows of the datatable looking for the changes that need to get implemented. OK enough specifics for now!