Asp.net slide6

33 252 0
Asp.net slide6

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

Asp.net slide

Session 11ADO.NET - I Exploring ASP.NET / Session 11 / 2 of 33ReviewAn ASP.NET application is a collection of all the ASP.NET pages, .aspx files, and various other files that are required to provide the essential functionality of the applicationWhen an instance of the HttpApplication class is created, a few events, such as Application_Start, are fired. The event-handlers for these events are stored in a file called Global.asaxThe Application object is a built-in ASP.NET object, that represents an instance of the ASP.NET application In ASP.NET, variables can have two levels of scope:Page-Level VariablesObject-level VariablesObject-level variables are of two types:Application-level variablesSession-level variablesTo ensure that application-level variables are not updated by more than one user simultaneously, the Application object makes use of the Lock() and UnLock() methods. Exploring ASP.NET / Session 11 / 3 of 33Review Contd…The Server object acts as an interface to the HTTP service, and exposes properties and methods of the HTTP serverThe Server object has many methods that are used to control various features of the web server. Some of these methods are:Execute and Transfer() HTMLEncode() UrlEncode() MapPath() The Session object is used to store information about a user, that is retained for the duration of the user session. Exploring ASP.NET / Session 11 / 4 of 33ObjectivesExplain DataSetsExplain and use the .NET Data ProvidersCreate a DataGridExplore DataReader Exploring ASP.NET / Session 11 / 5 of 33Data Connectivity in ADO.NETMost databases can only maintain a small number of connections simultaneouslyPerformance of the application is dependant on the number of usersWeb applications maintaining a continuous connection with a database is not feasible, since it cannot be known when another request for data will be made by the browser When there are many users in an organization and two users need to share the same data, then some means must be created by which these users can pass the data back and forth To tackle the above mentioned issues, Microsoft has created the disconnected data architecture for ADO.NET.Applications using ADO.NET connect to the database only to retrieve or update data Exploring ASP.NET / Session 11 / 6 of 33.NET DATA ProviderCONNECTIONCOMMANDDATA ADAPTERDATA READERADO.NET Object Model DATASET DATATABLEDataRowDataColumnUniqueConstraintForeignKeyConstraintDATABASE Exploring ASP.NET / Session 11 / 7 of 33DataSets DataSet<Dataset name>.Tables.Add(<datatable object name>); Syntax for adding DataTableDataSet is an object, in which the data retrieved from the database can be stored. The DataSet can contain one or more tables, and information about the relationships and constraints. Exploring ASP.NET / Session 11 / 8 of 33DataSets Example<%@ Page Debug = "true" %><%@ Import namespace="System.Data" %><html> <title> DataTable </title><script language="C#" runat="server">void Page_Load(Object sender, EventArgs e){ Response.Write("<center><b><u>Data Table</center></b></u> <br>"); DataSet myds = new DataSet(); DataTable mydt = new DataTable ("Squares"); DataRow mydr; mydt.Columns.Add(new DataColumn ("Numbers",typeof(Int32))); Exploring ASP.NET / Session 11 / 9 of 33DataSets Contd…mydt.Columns.Add(new DataColumn("Squares",typeof(Int32))); for (int i = 0; i < 10; i++) { mydr = mydt.NewRow(); mydr[0] = i; mydr[1] = i * i; mydt.Rows.Add(mydr); }myds.Tables.Add(mydt); dgMyGrid.DataSource = myds.Tables ["Squares"]. DefaultView;dgMyGrid.DataBind(); } </script> Exploring ASP.NET / Session 11 / 10 of 33DataSets Output <form runat="server"> <center><asp:DataGrid id="dgMyGrid" runat= "server"/></center> </form></html> [...]... connection with the database Retrieve and manipulate data in the database Exploring ASP.NET / Session 11 / 11 of 33 Types of NET Data Providers  The four types of NET Data Providers available are     NET NET NET NET Data Data Data Data Provider Provider Provider Provider for for for for SQL Server OLE DB ODBC Oracle Exploring ASP.NET / Session 11 / 12 of 33 Connection Objects In order to get the required... 71000877,'1989-11-11T00:00:00 ')",adocon); Exploring ASP.NET / Session 11 / 16 of 33 Command Objects Contd… Syntax used for updating data is as follows SqlCommand mycommand = new SqlCommand ("UPDATE employee SET job_id=11 WHERE fname='Pedro'", sqlcon); OleDbCommand mycommand = new OleDbCommand ("UPDATE employee SET job_id=11 WHERE fname='Pedro'", adocon); Exploring ASP.NET / Session 11 / 17 of 33 Command Objects... delcom.Connection.Close(); Exploring ASP.NET / Session 11 / 19 of 33 DataGrid    DataGrid control is used for viewing and modifying the records Data source for the DataGrid is specified using the DataSource property, and then the data is bound to the DataGrid using the DataBind() method A DataGrid can be created using the following syntax: Exploring ASP.NET / Session... mysqlcon); DataSet myds = new DataSet(); mysqlcom.Fill(myds, "employee"); Exploring ASP.NET / Session 11 / 21 of 33 DataGrid - Output dgMyGrid.DataSource= myds.Tables ["employee“] DefaultView; dgMyGrid.DataBind(); } 180"; mydv.Sort = "fname ASC"; dbgMyGrid.DataSource =mydv; dbgMyGrid.DataBind(); } Exploring ASP.NET / Session 11... Exploring ASP.NET / Session 11 / 26 of 33 DataReader     A DataReader is used when the records of the query result are viewed one after the other A DataReader is a forward-only, read-only view of the query result A DataReader is used especially when quick access to data is required without storing the extracted data remotely The DataReader does not provide disconnected access to data Exploring ASP.NET. .. mySqlCon.Open(); Exploring ASP.NET / Session 11 / 28 of 33 DataReader Example SqlDataReader mydatareader; mydatareader = mySqlda.ExecuteReader(); if(mydatareader.HasRows) { dbgMyGrid.DataSource = mydatareader; dbgMyGrid.DataBind(); } else Response.Write ("No records found"); mySqlCon.Close(); } Exploring ASP.NET / Session 11... mySqlCon.Close(); } Exploring ASP.NET / Session 11 / 29 of 33 DataReader Output Exploring ASP.NET / Session 11 / 30 of 33 Benefits of ADO.NET Exploring ASP.NET / Session 11 / 31 of 33 ADO VS ADO.NET ADO ADO.NET Data stored in form of recordset Data stored in form of dataset Data in recordset, which is from multiple tables... can be used to display different views / versions of the same table from the DataSet View of a table can also be customized with the help of another useful property of DataView, called Sort Exploring ASP.NET / Session 11 / 23 of 33 DataView Example DataView . Session 11ADO .NET - I Exploring ASP. NET / Session 11 / 2 of 33ReviewAn ASP. NET application is a collection of all the ASP. NET pages, .aspx files, and. Global.asaxThe Application object is a built-in ASP. NET object, that represents an instance of the ASP. NET application In ASP. NET, variables can have two levels of

Ngày đăng: 15/11/2012, 14:44

Từ khóa liên quan

Tài liệu cùng người dùng

Tài liệu liên quan