Post on 25-Dec-2015
Agenda Overview of .NET Data Access using ADO.NET ASP.NET
Web Forms Web Services Web Applications
Development Tools
.Introduction From http://www.microsoft.com/net/basics/: Microsoft .NET
Microsoft software for connecting information, people, systems, and devices. .NET provides XML-based interoperability and is being incorporated across Microsoft's clients, servers, services, and tools. For example, products like Microsoft Windows® and Microsoft Office will use .NET to connect with other systems and applications. For developers, .NET is manifested in the programming model delivered in the Microsoft .NET Framework.
Microsoft .NET Framework An integral Windows component that enables building and running
the next generation of software applications and Web services. It includes technologies for Web services and Web applications (ASP.NET), data access (ADO.NET), smart client applications (Windows Forms), and many others.
.NET Blueprint
Open Internet ProtocolsOpen Internet ProtocolsSOAP, SCL, DISCOSOAP, SCL, DISCO
HTTP, SMTP, XML, WAP, XSDHTTP, SMTP, XML, WAP, XSD
Your Application Your Application and Web Serviceand Web Service
Your Application Your Application and Web Serviceand Web Service
.NET .NET FrameworkFramework
.NET .NET FrameworkFramework
Windows Windows CE, ME, CE, ME,
2000, .NET2000, .NET
Windows Windows CE, ME, CE, ME,
2000, .NET2000, .NETO
pera
tions
Ope
ratio
nsO
pera
tions
Ope
ratio
ns
End-UserEnd-UserClientsClients
End-UserEnd-UserClientsClients
OtherOtherApplicationsApplications Using Your Using Your
ServiceService
OtherOtherApplicationsApplications Using Your Using Your
ServiceService
OrchestrationOrchestrationOrchestrationOrchestration
Your Internal ServicesYour Internal ServicesYour Internal ServicesYour Internal Services
.NET Enterprise .NET Enterprise ServersServers
.NET Enterprise .NET Enterprise ServersServers
.NET MyServices.NET MyServices.NET MyServices.NET MyServices
Public Web ServicesPublic Web ServicesPublic Web ServicesPublic Web Services
Visual Visual Studio.NETStudio.NET
Visual Visual Studio.NETStudio.NET
Inside the .NET Framework
Common Language Runtime
Base Framework
Data and XML
Web Services User Interface
VB C++ C#
ASP.NET
Perl Eiffel Cobol
Active Server Pages .NET•High-productivity environment for building and running Web services
Secure, integrated class libraries•Unifies programming models across languages
•Enables cross-language integration
•Factored for extensibility
•Designed for tools
Common Language Runtime
•Executes code, maintains security, handles component “plumbing” and dependencies
An Alphabet Soup CLR – Common Language Runtime CTS – Common Type System (C)IL – (Common) Intermediate Language
also known as: MIL – Microsoft Intermediate Language
CLS – Common Language Specification GC – Garbage Collector
Common Language Runtime
Co
mm
on
Lan
gu
age
Ru
nti
me
Co
mm
on
Lan
gu
age
Ru
nti
me
FrameworksFrameworks
Class loader and layoutClass loader and layout
IL t
o
IL t
o
na
tiv
e c
od
e n
ati
ve
co
de
co
mp
ilers
co
mp
ilers
GC, stack walk, code managerGC, stack walk, code manager
Se
curi
tyS
ecu
rity
Ex
ecu
tio
nE
xec
uti
on
Su
pp
ort
Su
pp
ort
Base ClassesBase Classes
Dramatically simplify application development
Provide a robust and secure execution environment
Support multiple programming languages
Simplify deployment and management
Common Type System Static (compile time) typed Object-Oriented
fields, methods, nested types, properties, etc. Object Based – everything is an object Independent of the underlying physical
platform Key feature when addressing program
platform independence
Managed and Unmanaged Code Managed Code – code compiled to IL
Safe Type-checked Bound-checked No need to worry about memory management – Garbage
collection. No more pointers and segmentation faults (Actually,
everything is a pointer but a safe one) Platform Independent
Unmanaged Code – native code .Net makes it possible to integrate both.
.NET Languages The .NET Platform is Language Neutral
• All .NET languages perform the same• You can leverage your existing skills
Microsoft provides:• VB, C++, C#, JScript
Third-parties are building• APL, COBOL, Pascal, Eiffel, Haskell, ML,
Oberon, Perl, Python, Scheme, Smalltalk
Base Classes Hierarchically organized into namespaces Namespace is just a unit of logical/physical
organization Base namespace : System .NET comes with a large set of base classes
implementing IO, Graphics, Networking, Data Access, Security, etc.
A very rich set of classes that can support projects of significant complexity
Other Interesting Topics Assemblies Metadata Execution Model Interoperability Common Language Specification
Agenda Overview of .NET Data Access using ADO.NET ASP.NET
Web Forms Web Services Web Applications
Development Tools
Why do we Need to Access Data Data access is the heart of any real-world
application Services are dynamic
Require large amounts of data to be filtered and processed
Generate data during its process of execution Provide various functionalities based on the
accumulated data
Data Access Architecture A Data Source (DS)
stores, organizes and manages data
Client (C) establishes a connection with the DS
C accesses DS using SQL
DS processes request and returns result
On the Windows Platform, the preferred and most often used DS is Microsoft SQL Server. Its current version is 2000.
Data SourceClient
SELECT * FROM PRODUCTS WHERE PRD_ID = 2489393
Basic Classes .Net framework provides ready classes for accessing a variety
of data sources Namespaces:
System.Data (general data access classes) System.Data.SqlClient (MSSQL specific classes)
Most important classes: SqlConnection SqlCommand SqlDataReader SqlDataAdapter DataSet DataTable
Establishing and Terminating a Connection
Create an instance of the SqlConnection object Call its Open method. Execute a request Close the connection when done Topics not covered: Connection String, Connection Pooling
SqlConnection myConnection = new SqlConnection("server=(local)\NetSDK;database=pubs;Trusted_Connection=yes");
myConnection.Open();
…. Do Something …
myConnection.Close();
Issuing Commands
Create an instance of SqlCommand, specifying the SQL command text and the connection to be used
Execute the command and store the result Many other possible ways to execute a command
Parameters Different result types
SqlConnection myConnection = new SqlConnection("server=(local)\NetSDK;database=pubs;Trusted_Connection=yes");
SqlCommand myCommand = new SqlCommand("select * from Authors", myConnection); myConnection.Open();DataSet ds = new DataSet();
myCommand.Fill(ds, "Authors"); myConnection.Close();
Storing Retrieved Data Different ways to retrieve and store data Depend on data type and application needs Most versatile class: DataSet Other useful classes:
SqlDataReader SqlDataAdapter
Recommended Practice Stored Procedures
SQL code stored directly in the database server Compiled, optimized, faster Elegant encapsulation and isolation of code
Example: Creating the Stored Procedure
CREATE Procedure GetAuthors
AS SELECT * FROM Authors
Invoking a Stored Procedure// create the command command = new SqlCommand();// attach the stored procedure namecommand.CommandText = “GetAuthors”;// set the type to: StoredProcedurecommand.CommandType = CommandType.StoredProcedure;// attach the connectioncommand.Connection = myConnection;// open the connectionmyConnection.Open();// create a DataSet objectDataSet ds = new DataSet(); // Execute the command and fill the DataSetmyCommand.Fill(ds, "Authors"); // Close the connectionmyConnection.Close();
Agenda Overview of .NET Data Access using ADO.NET ASP.NET
Web Forms Web Service Web Applications
Web Services
What is it All About? A programming framework built on the common language
runtime that can be used on a server to build powerful Web applications
Enhanced Performance Powerful Simple Secure Provides for rapid development Manageable Makes web programming “REAL” programming. Supports different types of clients
Request and Response Objects Request Object – provides access to the
client’s request: Request parameters Type of browser, operating system, ip, etc., Cookiesstring name = (string)Request.QueryString[“name”];
Response Object – used to generate the response for the client:Response.Write(“Hello World”)
Agenda Overview of .NET Data Access using ADO.NET ASP.NET
Web Forms Web Service Web Applications
Development Tools
Web Forms A scalable common language runtime
programming model that can be used on the server to dynamically generate Web pages
Automate the management of a page’s state across different round trips to the server.
Simple, fast, and elegant mechanism to generate dynamic content
A Basic Form<html> <head> <link rel="stylesheet"href="intro.css"> </head>
<body>
<center>
<form action="intro2.aspx" method="post">
<h3> Name: <input id="Name" type=text>
Category: <select id="Category" size=1> <option>psychology</option> <option>business</option> <option>popular_comp</option> </select>
</h3>
<input type=submit value="Lookup">
<p>
</form>
</center>
</body></html>
Beginning Scripting<%@ Page Language="C#"%>
<html> <head> <link rel="stylesheet"href="intro.css"> </head> <body> <center> <form action="intro2.aspx" method="post">
<h3> Name: <input id="Name" type=text>
Category: <select id="Category" size=1> <option>psychology</option> <option>business</option> <option>popular_comp</option> </select>
</h3> <input type=submit value="Lookup"> <p> <% for (int i=0; i <8; i++) { %> <font size="<%=i%>"> Welcome to ASP.NET </font> <br> <% }%> </form> </center>
</body></html>
Server Controls While we can do all just by using <% and
%>, by using this method we: Have no clean programming style Have to manually manage state across requests
Can use Server controls instead: Just like regular HTML tags with a small
difference: runat=“server”
<asp:label runat=“server” text=“Hello World” />
ASP.NET Web Form<%@ Page Language="C#"%>
<html> <head> <link rel="stylesheet"href="intro.css"> </head>
<body>
<center>
<form action="intro4.aspx" method="post" runat=server>
<h3> Name: <asp:textbox id="Name" runat="server"/>
Category: <asp:dropdownlist id="Category" runat=server> <asp:listitem>psychology</asp:listitem> <asp:listitem>business</asp:listitem> <asp:listitem>popular_comp</asp:listitem> </asp:dropdownlist>
</h3>
<asp:button text="Lookup" runat="server"/>
</form>
</center>
</body></html>
Lists, Data and Data Binding Data Binding – associating a data source with
a control Intoduction and Examples DataGrid DataList Repeater
Server Controls ASP.NET comes with a set of 45 standard
server controls. Cover most HTML elements and operations ASP.NET makes it possible to develop
custom controls, known also as user controls Introduction to User Controls
Code-Behind Web Forms ASP.NET supports two methods of authoring
dynamic pages. page code is physically declared within the
originating .aspx file. An alternative approach--known as the code-behind
method--enables the page code to be more cleanly separated from the HTML content into an entirely separate file.
Example: Code Result
Agenda Overview of .NET Data Access using ADO.NET ASP.NET
Web Forms Web Services Web Applications
Development Tools
Introduction WWW is evolving very quickly
Static Pages Somewhat Dynamic Pages Latest: Programmable Web Sites
Provide programming access to different functionalities exported by the web sites Turn the web site into a service – an entitity perfoming something on demand
XML Web Services – define mechanisms, standards and protocols to expose and access functionality Services specify what they offer Clients find this information and execute requests
Based on XML – powerful and extensible mechanism to define and organize data Curent Web Services Protocols and Languages:
WSDL – Web Service Definition Language SOAP – Simple Object Access Protocol
Basic Constructs The .NET framework provides a namespace
System.Web.Services with classes to be used for the construction of xml web services
Most important class: System.Web.Services.WebService
To create a web service – inherit the above class, write some methods to be exposed and prefix them with [WebMethod]. Tell your clients where they can find the service.
A Simple Web Service<%@ WebService Language="C#"
Class="HelloWorld" %>
using System;using System.Web.Services;
public class HelloWorld : WebService {
[WebMethod] public String SayHelloWorld() {
return "Hello World"; }
}
Agenda Overview of .NET Data Access using ADO.NET ASP.NET
Web Forms Web Services Web Applications
Development Tools
Overview ASP.NET Framework applications consist of
everything under one virtual directory of the Web server
Application is created by simply adding a file to the virtual directory
Can define custom handling of various events: Init Start End
Managing State Two ways:
Using the application Using the Session object
Application Data that is infrequently modified but read often
(global data) Session
Data specific to a user session or request
Agenda Overview of .NET Data Access using ADO.NET ASP.NET
Web Forms Web Services Web Applications
Development Tools
Visual Studio .NET All-in-One Integrated Development
Environment Write Code, Debug, Execute Access Databases, Remote servers Rich, Detailed Help System.
Resources ASP.NET Quickstart Tutorials
http://rack87.cs.duke.edu/quickstart/aspplus/ .NET Howto-s
http://rack87.cs.duke.edu/quickstart/howto/ ASP.NET official community web site
http://www.asp.net/ Microsoft official .NET web site
http://www.microsoft.com/net/ C# Resources
http://www.csharp-station.com/ MSDN
http://msdn.microsoft.com/library/en-us/dnanchor/html/netdevanchor.asp?frame=true