1 / 38

ASP.NET & ADO.NET

ASP.NET & ADO.NET. Presented By : Muhammad Atif Hussain Head of I.T. (Takaful Pakistan Limited) Technologies Consultant (AUC Technologies) MCS(KU) MSCS(SZABIST) MCP MCAD MCSD MCTS (Windows, Web, Distributed Applications) MCPD (Enterprise Applications) MCT(Microsoft Certified Trainer).

berit
Download Presentation

ASP.NET & ADO.NET

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. ASP.NET & ADO.NET Presented By : Muhammad Atif HussainHead of I.T. (Takaful Pakistan Limited)Technologies Consultant (AUC Technologies)MCS(KU)MSCS(SZABIST)MCPMCADMCSDMCTS (Windows, Web, Distributed Applications)MCPD (Enterprise Applications)MCT(Microsoft Certified Trainer)

  2. Introduce Microsoft® ADO.NET Show the evolution of ADO to ADO.NET Introduce the primary components of ADO.NET Agenda

  3. Differences Between ADO and ADO.NET Benefits of ADO.NET ADO.NET Core Concepts and Architecture The ADO.NET Object Model The DataSet and Data Views Managed Providers Contents

  4. ADO.NET and the .NET Framework Microsoft .NET Framework Web Services User Interface Data and XML ADO.NET XML ... ... Base Classes Common Language Runtime

  5. ADO Designed for connected access Tied to the physical data model The RecordSet is the central data container RecordSet is one (1) table that contains all the data Retrieving data from > 1 table or source requires a database JOIN Data is “flattened”: lose relationships; navigation is sequential Data types are bound to COM/COM+ data types Data sharing via COM marshalling Problems marshalling through firewalls (DCOM, binary) ADO v/s ADO.NET

  6. ADO.NET Designed for disconnected access Can model data logically! The DataSet replaces the RecordSet DataSet can contain multiple tables Retrieving data from > 1 table or source does not require a JOIN Relationships are preserved: navigation is relational Data types are only bound to XML schema No data type conversions required XML, like HTML, is plaintext: “Firewall friendly” ADO v/s ADO.NET

  7. Interoperability through use of XML (more later!) Open standard for data that describes itself Human readable and decipherable text Used internally but accessible externally Can use XML to read and write and move data Scalability through the disconnected DataSet Connections are not maintained for long periods Database locking does not occur Locking support with ServiceComponents Optimistic locking otherwise Works the way the Web works: “Hit and Run!” Maintainability Separation of data logic and user interface Benefits of ADO.NET

  8. Typed programming—a programming style Uses end-user words: Easier to read and write Statement completion in Microsoft Visual Studio.NET Safer: Provides compile-time checking Examples: Untyped:Table("Customer")("Jones").Column(“Balance”) Typed:myDataSet.Customer("Jones").Balance Wizard support Generates queries for you Graphical way to select data you want to work with XML Designer (for creating DataSets) Visual Studio Enhancement

  9. The ADO.NET Object Model Objects of System.Data .NET data providers ADO.NET namespace hierarchy Organizes the object model Includes: System.Data System.Data.OleDb System.Data.Common System.Data.SqlClient System.Data.SqlTypes System.Data.OracleClient Core Concept and Architecture

  10. ADO.NET related Namespaces ADO.NET System.Data .SqlClient .Common .OleDb .OracleClient

  11. Contains the basis and bulk of ADO.NET Data-centric namespace Provides the means to work on and with your data! Classes and methods to manipulate your data Ability to create views of your data Means to logically represent your data Enables the use of XML to view, share, and store data System.Data Namespace

  12. Contains the “main” classes of ADO.NET In-memory cache of data In-memory cache of a database table Used to manipulate a row in a DataTable Used to define the columns in a DataTable Used to relate 2 DataTables to each other Used to create views on DataSets Introducing the Objects System.Data DataSet DataTable DataRow DataColumn DataRelation DataViewManager

  13. DataSet DataRow(s) DataColumn Constraint(s) Relations DataRelation DataRelation Putting the Object Together Tables DataTable DataView DataViewManager DataTable DataTable

  14. An in-memory cache of data from a data source Common way to represent and manipulate data Universal data container Not just for use with databases Logical or physical representation of data Designed to be disconnected from the data source Connect, execute query, disconnect Can use XML To read and write data To read and write XMLSchema Working Data - The Dataset

  15. Collections are used to add & remove tables & relations Properties of Interest: Tables: Returns the collection of DataTable objects Relations: Returns the collection of DataRelations Namespace: Gets or sets the namespace of the DataSet Using Properties Samples: myDataSet.Tables.Add( myTable ); myDataTableCollection = myDataSet.Tables Properties and Methods of Interest

  16. Al About Data! Universal Data Container DataSet: It’s not just for Databases

  17. May be mapped to a physical table in the data source Can be related to one another through DataRelations Optimistic concurrency or locking - model Properties of Interest: Columns: Returns ColumnsCollection of DataColumns Rows: Returns DataRow objects as a RowsCollection ParentRelations: Returns the RelationsCollection Constraints: Returns the table’s ConstraintsCollection DataSet: Returns the DataSet of the DataTable PrimaryKey: Gets the DataColumns that make up the table’s primary key The DataTable

  18. Create a DataTable and add it to a DataSet System.Data -- Dataset and DataTable DataSet ds = new DataSet(); // Create DataTable object: “Customers”. DataTable dt= new DataTable( “Customers” ); // Create and add columns to the table // 1. Explicitly create and Add a DataColumn DataColumn dc; dc = new DataColumn( “CustID”, Type.GetType("System.Int16")); dt.Columns.Add( dc ); // 2. Implicitly Create and Add columns (DataColumn). dt.Columns.Add( “First_Name”,Type.GetType("System String”)); dt.Columns.Add( “Last_Name”, Type.GetType("System String”)); // Add the DataTable object to the DataSet ds.Tables.Add( dt );

  19. Used to create logical relations between your data Create relations between two (2) DataTable objects Requires a DataColumn object from each DataTable The DataType of both DataColumns must be the same Cannot relate a Int32 DataColumn and a String DataColumn The relation is named (by you!) DataRelation dr=new DataRelation( “myRelation”,...) Makes relational navigation possible RelationsCollection used to hold/group them Accessed through the DataSet’s Relations property Relating Data - The DataRelation

  20. Creating Relations with DataRelation // Building on the DataTable example earlier... // Get the DataTable DataColumns we want to relate...DataColumn parentCol, childCol; parentCol= DataSet.Tables["Customers"].Columns["CustID"];childCol = DataSet.Tables["Orders“].Columns["CustID"]; // Create DataRelation with the name “CustomerOrders”... DataRelation dr = new DataRelation("CustomersOrders", parentCol, childCol); // Add the relation to the DataSet... ds.Relations.Add( dr );

  21. DataSet can read/write XML for its data and/or schema You can create or modify data in a DataSet using XML You can create or modify the DataSets schema using XML XML-related DataSet methods for reading: ReadXml: Reads an XML schema and data into the DataSet ReadXmlSchema: Reads an XML schema into the DataSet And for writing: WriteXml, WriteXmlSchema GetXml, GetXmlSchema Namespace property: sets the namespace for serialization Full support for SQL Server-style DiffGrams XML and the Dataset

  22. Methods of Reading and Writing XML // Code for creating the DataSet mds and loading the // DataSet from a data source not shown. String oFile = “C:\\My_ADO.NET\\myXmlOutput.xsd”; String iFile = “C:\\My_ADO.NET\\myXmlInput.xsd”; // Write the DataSet’s XMLSchema to an XML Document mds.WriteXmlSchema( oFile ); // Read/Upload XML Data into the DataSet mds.ReadXml( iFile); // modify the data // ... // Write the existing Data to an XML Document mds.WriteXml( "C:\\My_ADO.NET\\myXmlData.txt", XmlWriteMode.DiffGram);

  23. DataSet DataRow(s) DataColumn Constraint(s) Relations DataRelation DataRelation Dataset, DataRelation, DataView… Tables DataView DataTable DataViewManager DataViewSettings DataViewSetting DataViewSetting DataTable DataTable

  24. Create multiple views on DataTable objects Bindable to user interface controls Properties of Interest: Table: Retrieves or sets the associated DataTable Sort: Gets or sets the table’s sort columns and sort order RowFilter: Gets or sets the expression used to filter rows RowStateFilter: Gets or sets the row state filter None, Unchanged, New, Deleted, ModifiedCurrent, and others Viewing Data - The DataView

  25. Creating DataView by Example // Code for myTable “Customers” with “Name” column not shown DataView view1 = new DataView( myTable ); DataView view2 = new DataView( myTable ); // Creates Ascending view of Customers by “Name” view1.Sort = “Name ASC”; // Set the view to show only modified (original) rows view2.RowStateFilter= DataViewRowState.ModifiedOriginal; // Bind to UI element(s)... DataGrid myGrid = new DataGrid(); myGrid.SetDataBinding( view1, “Customer”); //...

  26. Similar to a DataView but DataSet oriented Used to create multiple views on a DataSet Ability to automatically set filters on the tables Properties of Interest: DataViewSettings: Gets the DataView for on each DataTable DataSet: Gets or sets the DataSet to be viewed CreateDataView method Creates a DataView on a DataTable Viewing More Data - DataViewManager

  27. DataViewManager By Example // Create the DataViewManager & views... DataViewManager dvMgr = new DataViewManager( myDS ); dvMgr.CreateDataView( ds.Tables[“Orders"] ); dvMgr.DataViewSettings[“Orders"].Sort = “CustID ASC"; dvMgr.CreateDataView( ds.Tables[“Customers"] ); dvMgr.DataViewSettings[“Customers"].Sort = “Name DESC"; // Bind to a UI elements/controls... dataGrid1.DataSource = viewMgr; dataGrid1.DataMember = "Table1"; dataGrid2.DataSource = viewMgr; dataGrid2.DataMember = "Table2"; // Update the control with the data... dataGrid1.Update(); dataGrid2.Update();

  28. A collection of classes for accessing data sources: Microsoft SQL Server™ 2000-2005, SQL Server 7, and MSDE Any OLE Database (OLE DB) providers Including: Oracle, JET, and SQL OLE DB Providers Establish connection between DataSets and data stores Two .NET data providers: ADO: via the System.Data.OleDb namespace SQL Server: via the System.Data.SqlClient namespace System.Data.OleDb is the .NET data provider The (ADO).NET Data Provides

  29. .NET Data Providers Hierarchy .CommonContains classes shared by both System.Data .OleDb .SqlClient SqlCommandSqlConnectionSqlDataReaderSqlDataAdapter OleDbCommandOleDbConnectionOleDbDataReaderOleDbDataAdapter

  30. Represent a unique session with a data source Create, open, close a connection to a data source Functionality and methods to perform transactions OleDbConnection example: OleDBConnection and SqlConnection String conStr="Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=NWIND_RW.MDB";OleDbConnection aConn = new OleDbConnection(conStr);aConn.Open(); // Execute Queries using OleDbDataAdapter ClassaConn.Close();

  31. Data-driven applications Fetch data Format data in a programmer-friendly way Format data in a user-friendly way Forward data to the browser Submit data Catch server-generated values Refresh the view for the user ADO.NET and ASP.NET

  32. Data-Binding DataGrid and other controls Sorting and Filtering ADO.NET views Aggregates ADO.NET in-memory objects (DataColumn, DataTable, DataRelation) User Interface ASP.NET controls and state maintenance Technical Aspects

  33. Automatic association between a data source and the user interface of a control Definition of a set of feasible sources ADO.NET container objects can be associated with data-bound controls Iterative and list-bound controls Data-Bindings

  34. Building data to controls • DataSource property • DataBind method // data loading DataTable __dataTable; __dataTable = __dataHandler.Load(); // data binding DDList.DataSource = __dataTable; DDList.DataTextField = "Name"; DDList.DataValueField = "empID"; DDList.DataBind();

  35. The DataGrid Control Elements: header, footer, items, pager Columns: bound, button, hyperlink, template, edit Cell customization using templates and data-bound expressions Paging and sorting Store the value of the key field per each displayed row Bindable Grids of Data

  36. Can you afford caching? The Cache object for data storage Let the grid do the hard work The output caching mechanism for pages Do you need up-to-date information? Minimize the bandwidth for SQL queries Need sorting? Do the hard work of pagination yourself Let the grid do the annoying work Pagination

  37. ? Questions

More Related