Active Data Objects Binding ASP.NET Controls to Data

Slides:



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

ADO.NET: Working in Disconnected Environment Sergey Baidachni MCT, MCSD, MCDBA.
Direct Data Access, Data Binding. Content Direct Data Access Data Binding Muzaffer DOĞAN - Anadolu University2.
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.
VB.NET Database Access ISYS546. Microsoft Universal Data Access ODBC: Open Database Connectivity –A driver manager –Used for relational databases OLE.
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.
VB.NET Database Access ISYS546. Microsoft Universal Data Access ODBC: Open Database Connectivity –A driver manager –Used for relational databases OLE.
ASP.NET Programming with C# and SQL Server First Edition Chapter 8 Manipulating SQL Server Databases with ASP.NET.
Chapter 8 Binding Data to Web Controls. ASP.NET 2.0, Third Edition2.
Computer Science 317 Database Management Introduction to Web Access to Databases.
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.
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.
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.
CIS 451: Using ASP.NET Objects with SQL Dr. Ralph D. Westfall February, 2009.
Developing Web Applications Using Microsoft ® Visual Studio ® 2008.
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.
1 Introduction to ADO.NET Microsoft ADO.NET 2.0 Step by Step Rebecca M Riordan Microsoft Press, 2006.
 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.
CSCI 6962: Server-side Design and Programming Database Manipulation in ASP.
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.
Module 7: Accessing Data by Using ADO.NET
Chapter 8 Working With Databases in ASP.NET. Listing 8.1 – ShowListControls Uses The SqlDataSource control for estabishing database connectivity and.
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.
Module 3: Performing Connected Database Operations.
 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.
Mauricio Featherman, Ph.D. Washington St. University
Module 3: Working with Local Data. Overview Using DataSets Using XML Using SQL Server CE.
HNDIT Rapid Application Development
ADO.NET FUNDAMENTALS BEGINNING ASP.NET 3.5 IN C#.
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.
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
Introduction to ASP.NET, Second Edition2 Chapter Objectives.
 ADO.NET is an object-oriented set of libraries that allows you to interact with data sources  Commonly, the data source is a database, but it could.
ASP.NET Programming with C# and SQL Server First Edition
Introduction to ADO.NET
Introduction to Database Processing with ADO.NET
Database Programming in .Net The Relational Model
Introduction to Database Processing with ADO.NET
Unit 9.1 Learning Objectives Data Access in Code
ADO.NET Framework.
Programming the Web Using ASP.Net
Lecture 6 VB.Net SQL Server.
Unit 9.2 Database access from code Database Cycle Review
VB.NET Using Database.
Tonga Institute of Higher Education
Bài 5: ADO.NET 5.1. Khái niệm 5.2. Các lớp và không gian tên cơ bản của ADO.NET 5.3. Thao tác với dữ liệu kết nối – Connected 5.4. Thao tác với dữ liệu.
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.
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
Introduction to Database Programming through ADO. NET
Introduction to ADO.Net and Visual Studio Database Tools.
Presentation transcript:

Active Data Objects Binding ASP.NET Controls to Data Jim Fawcett CSE686 – Internet Programming Summer 2005

Support for Data in .Net Connected data access: Use Connection object and Command to connect a DataReader object to database and read iteratively. There are two flavors of these objects, Sql--- and OleDb---. The first are tuned to SQL Server and the second can connect to any database the provides drivers, e.g., Access, SQL, Oracle, … Disconnected data access: Use a SqlDataSource and GridView or DetailsView or DataList or FormView or Repeater and execute an SQL query or stored procedure. Use a Connection and Command to connect a DataAdapter to the database and fill a DataSet with the results. Use a Connection and Command to connect a DataAdaptor to the database and then call Update method of the DataSet.

Data Provider Classes

ADO Application Structure – ASP.Net 1.1

ADO Objects – ASP.Net 1.1

ADO Application Structure – ASP.Net 2.0

ADO Objects - ASP.Net 2.0

Connection Object Methods Properties Open() Close() BeginTransaction() BeginTransaction().Commit() Properties ConnectionString Windows, SQL, or Forms Authentication For Windows authentication: "server=HINDENBURG\\NETSDK;Integrated Security=SSPI; Trusted_Connection=yes; database=pubs“ Also need impersonation code in asp application – see link on CSE686 page. Database, Datasource, State (open | closed) are readonly properties You can drag a connection object onto a form Doesn’t identify a data source

Command Object Used to connect Connection Object to DataReader or a DataAdapter object and execute commands. Methods ExecuteNonQuery() Executes command defined in CommandText property, e.g., UPDATE, DELETE, INSERT, CREATE TABLE, ALTER COLUMN, … Used for operations that do not return a row of data ExecuteReader(CommandBehavior) Returns a DataReader instance attached to the resulting rowset Assumes you’ve defined a command that implies a query, using CommandText property ExecuteScalar() Executes query defined in CommandText and returns the first column of the first row of resulting rowset. Ignores the rest. Properties Connection connection string defining Server and database CommandText Text of SQL query CommandType StoredProcedure | TableDirect | Text (SQL Query) Parameters Arguments for stored procedures Transaction Transaction in which command will execute

DataReader Object Supports one-way, forward-only, access to data. Once data has been read, must be closed and re-created to access data again. DataReader lasts as long as the connection is open. It can’t be persisted to session. Methods Read() Returns one row and advances current row pointer GetXXX() GetBoolean, GetInt16, GetChars, GetString, GetValue, … 37 different methods for specific XXX types GetFieldType Returns type of specified column GetSchemaTable Returns DataTable describing structure of data NextResult Advances current row pointer Close() Closes DataReader Properties this[string] Specifies column in row by name, returns value this[int] Specifies column in row by index, returns value FieldCount Number of columns in current row Item Value of a column RecordsAffected Number of rows changed, inserted, or deleted Normally, a DataReader is returned from a command object, ready to bind to a display control. You get one from the command method ExecuteReader().

Data Adapter Object Used to: Methods Properties extract data from data source and populate tables in a DataSet Push changes in DataSet back to source Methods Fill(DataSet, Table) Loads data from source into DataSet FillSchema(DataSet, SchemaType) Update() Returns modified data to source Properties SelectCommand SQL Select text UpdateCommand SQL Update command text InsertCommand SQL Insert command text DeleteCommand SQL Delete command text TableMappings Map for source and DataSet columns

DataSet Object Used for Disconnected manipulation of a source’s data. Read-write, can access tables in any order, as often as you like. Lasts only as long as the page that created it, unless persisted to session or some other mechanism. Methods AcceptChanges Commits pending changes to DataSet Clear() Empties all Tables ReadXML(XmlReader) Reads XML data into DataSet WriteXML(XmlWriter) Writes DataSet data to XML file HasChanges() boolean returns true if pending changes AbandonChanges() Reverts to unchanged state Properties Tables collection ds.Tables[tableStr].Rows[3]["Responsible Individual"] = userID; Relations collection Relationships between Tables in DataSet Normally, you don’t fill the DataSet, a DataAdapter does that.

DataTable Object Holds records from a source per TableMapping DataSets hold DataTable members in Table Collection. Properties Rows Rows collection Columns Columns collection TableName Name used in code DataSet Tables Collection Methods Tables.Add(TableName) Tables.Add(DataTable) Tables.AddRange(TableArray) DataTable Rows Collection Properties and Methods Item Value of a specified column Add(DataRow) method to add a new row DataTable Columns Collection Properties ColumnName DataType

SqlDataSource Used to connect Connection Object to GridView or DetailsView or DropDownList or … objects and execute commands. Methods DataBind() Calls Select(), called by view controls DataBind() method. Delete(), Insert(), Select(), Update() Executes command defined DeleteCommand, InsertCommand, SelectCommand, or UpdateCommand Properties ConnectionString connection string defining Server and database Commands DeleteCommand, InsertCommand, SelectCommand, UpdateCommand CommandTypes DeleteCommandType, … StoredProcedure | Text (SQL Query) Parameters DeleteParameters, … Arguments for stored procedures

Managing Data Coherency DataSets support disconnect operation. When processing is complete, changes are sent back to the database. In a multi-user environment, that obviously can cause problems. Strategies to avoid coherency problems: Lock records, so others can read but not update. ADO.Net does not directly provide locks You can: SqlTransaction t = conn.BeginTransaction(IsolationLevel.Serializable); some code here t.Commit(); Do this in a try, catch block with finalizer that does the commit so you don’t leave a bunch of records locked indefinately if your code throws an exception. Build the update procedure so that it fails if the affected records where last changed after you read the data. Then go and negotiate. Allow only one person to update any given area of the data model, partitioned in some reasonable way for the business.

References Pro ASP.NET 2.0 in C# 2005, MacDonald & Szpuszta, Apress, 2006 Programming Microsoft .Net, Jeff Prosise, Microsoft Press, 2002 Professional C#, Robinson et. al., Wrox Press, 2002 www.w3schools.com/sql/default.asp