Types of .NET Applications


The development tools of the .NET Framework enable you to create different types of applications using .NET compliant languages. The types of applications that you can create in the .NET Framework are:

  • Windows applications: Run only under Windows environment. These applications consume the services provided by the Windows operating system. You can use these applications to create the user interface to simplify end user interaction.

  • ASP.NET Web applications: Run on a distributed environment, such as the Web. These applications use HTTP as the communication protocol and deliver information to the end users in an HTML format. ASP.NET Web applications can range from simple Web sites that consist of HTML pages to advanced enterprise applications that run on local and remote networks. These enterprise applications also provide components for exchanging data using XML.

  • ASP.NET Web services: Are small pieces of code that are modular, self-contained, and reusable. Web services allow exchange of data between different end users on the Web, regardless of the language, platform, or component model they use. Web services use a standard set of five Web protocols: XML, HTML, Simple Object Access Protocol (SOAP), Web Service Description Language (WSDL), and Universal Description, Discovery and Integration (UDDI). You use XML to structure the data, HTTP to transport the data, and SOAP to define the rules of communication between Web services. WSDL allows you to describe the Web services and UDDI helps publish the available Web services.

  • Windows services: Are long-running executable applications that run on the system as a background process. These applications do not interfere with the working of the other processes that run on the same computer. Windows services execute within separate Windows sessions created specifically for each Windows service. These services do not have a graphic user interface and are ideal for running on the server. You can program them to automatically run when the computer starts. You can also pause their execution and restart the service, if need be. Windows services were earlier called NT services.

  • Console applications: Are software programs that run on the console or the input/output terminal of the end user’s computer. A console application responds to end user actions on the keyboard and generates a response on the screen. These applications run in a text-only window and in a character-based mode.

  • Mobile applications: Can run on multiple mobile devices, such as Pocket PCs, mobile phones, or personal digital assistants. These applications provide ubiquitous access to data from mobile devices. For example, an application may return the local time depending upon the current location of the mobile device. The .NET Framework automatically makes changes to these applications to enable them to run on multiple browsers, depending on the mobile device.

  • Class libraries: Are components that you create once and reuse a number of times in multiple applications. Class libraries allow you to define several classes, along with their methods and interfaces, in one file. These libraries compile to .dll files and facilitate rapid development of new applications because of reusability of code. To access the functionality of the classes in a class library from your application, you need to include a reference to that library in your program.

All types of .NET applications use one or more .NET compliant languages for their design and development. The .NET Framework includes various technologies, such as ASP.NET, VB.NET, VC++.NET, and ADO.NET. You use ASP.NET to build Web applications and services, VB.NET and VC++.NET to create Windows applications, and ADO.NET for flexible access to databases.

Overview of ASP.NET

ASP.NET helps develop server-side Web applications and Web services that are robust, scalable, interoperable, and efficient. ASP.NET uses several features of the .NET Framework, such as compiled code, server side controls, data-bound controls, and a collection of other objects that are accessible by all CLS-compliant languages, such as VB.NET, C#, or J#.

ASP.NET eliminates the use of scripts and simplifies the process of designing and developing Web applications. In contrast, earlier server-based Web application frameworks, such as ASP, use scripting languages to access server-based resources and components. These scripts are interpreted and not compiled. As a result, these scripts execute at a slower rate as compared to the compiled applications of ASP.NET. Unlike secure Web applications that are built using ASP.NET, ASP scripts provide no integration with security settings. In addition, you can use only VBScript or JavaScript to write code for ASP pages. ASP.NET pages execute within the CLR. As a result, you can use any CLS-compliant language to write the code for these pages.

The extension for an ASP.NET page is .aspx. ASP.NET pages are not interpreted; they are compiled to .NET assemblies. The entire ASP.NET application, which might include several pages and custom controls, compiles to one executable assembly at the time of compilation.

Role of CLR in ASP.NET

An ASP.NET application runs within the CLR, and has access to every object and service the CLR provides. The features the CLR provides to an ASP.NET application are:

  • Cross language integration

  • Garbage collection

  • Structured error handling

For example, suppose, you want to access a database to retrieve information about the employees in a company. If an error occurs, you can handle it in VBScript, as shown in Listing 1-3:

Listing 1-3: Error handling using VBScript

start example
 <%  On Error GOTO errorhandler Set conn=Server.CreateObject("ADODB.Connection") Set rs=Server.CreateObject("ADODB.Recordset") conn.Open "Provider=SQLOLEDB;UID=sa;PWD=sa;Initial Catalog=CRM" rs.Open "SELECT * FROM Employees, 3, 3" errorhandler: lblError.Caption="Unable to retrieve employee information" %>  
end example

The above listing shows how to use the errorhandler statement in VBScript to trap an error and generate an error message.

Listing 1-4 shows a piece of code in ASP.NET that is equivalent to the VBScript code of Listing 1-3:

Listing 1-4: Error handling in ASP.NET

start example
 Public Sub someMethod() Dim conn as new SqlConnection("Server=localhost; UID=sa; PWD=sa; Initial Catalog=CRM") Try conn.Open Catch ex as Exception lblError.Text="Unable to connect to the database" Exit Sub End Try Try Dim cmd as new SqlCommand("SELECT * FROM Employees",conn) Dim da as new SqlDataAdapter(cmd) Catch ex as Exception lblError.Text="Unable to retrieve employees information" End Try End Sub 
end example

The above listing shows how ASP.NET handles errors efficiently using the structured try-catch blocks.

Features of ASP.NET

ASP.NET provides various features, such as compiled code, multi-language support, support for multiple browsers and devices, security features, and dynamic update of applications. These features simplify the task of developing applications for the Web.

Compiled Code

When a client requests an ASP.NET page for the first time, which is a file with .aspx extension or a Web service with .asmx extension, the CLR compiles the code in that file into the MSIL code and later into the native code. The .NET runtime puts that file in the Global Assembly Cache (GAC) and maintains this cached copy until you restart your Web server or computer. If a client requests that page or service again, the CLR retrieves it from the cache and sends it to the client. The CLR recompiles a page or service only if you modify the code in that page or Web service. Compiled code enhances the performance of your Web application.

Multi-language Support

ASP.NET allows you to use any CLS-compliant language, such as VB.NET, C#, or J#, to develop your Web applications. This is because all these languages eventually compile to the same MSIL code that executes within the .NET run-time environment.

Support for Multiple Devices and Browsers

An ASP.NET page can run on multiple devices, such as desktop computers and mobile devices, and multiple browsers, such as Internet Explorer, Netscape, Opera, and America On-Line (AOL). This is because ASP.NET dynamically determines the target browser’s capabilities and makes appropriate adjustments to the Web page to display it in HTML format on the browser. ASP.NET also provides a set of Mobile controls that automatically generate the output of your application in the language appropriate to the target mobile device. Mobile controls automatically generate the output in Wireless Markup Language (WML), HTML, or XML, as required by the requesting device.

Control-Driven Applications

ASP.NET provides a set of server-based controls to control and customize your applications. With ASP.NET, you can add a control to the page and support the control with a few lines of code that executes when the end user interacts with the control. You can access these controls in your program using events, properties, and methods. There are three types of ASP.NET controls:

  • Server-aware HTML controls: Are a set of HTML controls that are common to both ASP.NET and other server-based technologies. ASP.NET lets you convert these standard HTML controls to server controls by adding a few attributes. For example, the following code shows how to run an ASP.NET page with a standard HTML text box on the server, by adding the runat attribute with its value set to server:

     <input type="text"  runat="server"/> 
  • adding the server-aware HTML control to your Web form, you can work with the control in your program by referring to its id. For example, the following lines of code show how to set the value property of the text control, whose id is mytext, when an ASP.NET page loads:

     Public Sub Page_Load(Byval sender as Object, Byval e as EventArgs)     mytext.value="Welcome to my web application" End Sub 

  • ASP.NET built-in controls: Are similar to HTML controls, except that built-in controls share a common set of attributes. Each control that ASP.NET provides extends the functionality from the System.Web.UI.WebControls.WebControl class. As a result, the ASP.NET built-in controls have a consistent interface. This makes it easy for you to use these controls in your program. For example, the following lines of code show how a text box and a check box in ASP.NET share common attributes, such as id and Text:

     <asp:TextBox  Text="Welcome to my Web application" runat="server" /> <asp:CheckBox  Text="Unchecked" runat="server" /> 

  • controls share similar properties, you can work with different controls in a consistent manner, as shown in the following lines of code:

     MyText.Text="Welcome to my home page" MyCheckBox.Text="Checked" 
  • Data-bound controls: Provide the ability to bind data to the controls. You can access a data source and retrieve the data in a DataReader or a DataSet object. You can then bind the retrieved data to a specific control, such as ASP:DataGrid control, which automatically displays the retrieved data in an easy-to-comprehend tabular form, without explicitly coding for the DataGrid control. In addition, you can define the font-styles, background colors, header styles, and other features of the DataGrid control to make the data grid attractive and user friendly.

Configuration and Security Model

ASP.NET provides a built-in functionality that simplifies the task of authentication, authorization, and impersonation. Each ASP.NET page or Web service contains a Web.config file within the virtual root directory of the application. This file is written in XML and defines the configuration and security settings for the application. For example, the following XML tags in a Web.config file configure the security settings to deny anonymous requests to the application:

 <authentication mode="Windows" /> <authorization> <deny users="?" /> </authorization> 

The ? character in the above code represents anonymous requests to the application.

Instead of making changes to the Internet Information Server (IIS) security settings and Windows user accounts, you can simply change the security settings in the Web.config file by editing it using any text editor.

Faster Web Application Development

Visual Studio .NET Integrated Development Environment (IDE) allows you to create Web applications with the same ease with which you create Windows-based applications in Visual Basic. In ASP.NET, you can visually design the Web forms by simply dragging the controls from the toolbox to the desired places on the form. The IDE also contains features, such as code completion and color-coding, which simplify the process of developing the application. Visual Studio.NET provides integrated support for debugging and deploying ASP.NET Web applications. This helps quickly develop bug-free code.

Dynamic Update of Applications

ASP.NET allows you to dynamically update the components compiled in .NET by overwriting the existing DLL with its updated version, without restarting the Web server. The running application automatically detects the change and starts using the new code. In contrast, for other server-side technologies, you need to restart the Web server each time you want to deploy an updated component.

The ASP.NET Application Architecture

An ASP.NET application runs in a process under the IIS, which delivers the content from a particular virtual directory to the requesting Web browser. An ASP.NET application is just a virtual directory in IIS. The entire source code of your ASP.NET application, including the constituent class files, compiles into an assembly and is placed in the /bin directory of your application. The .aspx pages in the application too compile at runtime and the CLR caches the compiled pages in order to serve subsequent page requests. These pages are cached until the application changes in some way or the Web server restarts.

Figure 1-3 shows the architecture of an ASP.NET application:

click to expand: this figure shows the elements in an asp.net application.
Figure 1-3: An ASP.NET Application

The basic components that constitute an ASP.NET application are:

  • Global.asax file: Is the core component of every ASP.NET Web application where you can create global methods, events, and variables. You can define application and session specific methods in this file. For example, if you want to open a connection with the database when the application starts, and you want all the clients to share the same connection, you can open the connection in the Application_Start() method in this file.

  • Web.config: Controls various aspects of the ASP.NET application, such as security settings, debug settings, or session state management. Web.config is an XML file and is applicable at the folder level in an application. This means that it stores configuration information for all the files that reside in the same folder as the Web.config file itself.

  • Web forms: Are the Web pages that constitute a Web application. These pages are equivalent to Windows forms in Windows applications. Each Web form has a user interface and a code-behind file that separates the presentation logic from the business logic. For example, a login page in your Web application will be a combination of the Login.aspx Web form and the Login.aspx.vb file that stores the code behind the various controls in the form.

  • Controls: Enable you to create user interfaces to allow clients to interact with your Web applications. There are two types of controls, server and customized. While ASP.NET provides server controls, you can also create customized controls. A customized control has a .ascx extension. For example, suppose, you want a set of hyperlinks to appear on each page of your application. Instead of adding them separately on each page, you can create a customized control that contains all hyperlinks along with the appropriate functionality and use this control on each page in the application.

  • Web services: Are XML based and allow applications to communicate and share data over the Internet on disparate operating systems and programming languages. Web services use SOAP to exchange XML messages with client applications. ASP.NET makes it easy for you to call XML Web services from your application.

  • .NET Components: Enable .NET applications to reuse existing components. These components are mainly a part of the business and data tiers of large enterprise applications, but they can also be third party components that provide specific functions for databases, or implement security. These components exist in the form of .NET assemblies. Your applications can access the functionalities of these components by adding a reference to them in the program.

Note

To learn more about ASP.NET, see the Introducing ASP.NET ReferencePoint.

Overview of VB.NET

Visual Basic.NET helps create Windows and Web applications. VB.NET is the next version of VB 6.0. The compiler for VB.NET, vbc.exe, ships with the Microsoft .NET Framework SDK. VB.NET is an improved, stable, and fully object-oriented language, as compared to VB. As a result, you can use VB.NET and the features of the Visual Studio.NET IDE to easily develop large enterprise applications. Though VB supports abstraction and encapsulation, it is not fully object-oriented because it does not support inheritance and polymorphism.

Working with Classes

In VB.NET, the Class and End Class pair creates a class. Listing 1-5 shows how to define a class, its member variables, and methods in VB.NET:

Listing 1-5: Class Definition in VB.NET

start example
 Public Class MyClass Dim myInteger as Integer=15 Dim myString as String="Hello World" Public Function myMethod() as String Return myString End Function End Class 
end example

The above listing defines the MyClass class that contains two member variables, myInteger and myString, and a myMethod() function. In VB.NET, you can initialize the variable at the time of declaration, which was not possible in VB 6.0. In addition, in VB.NET, you can use the Return keyword to return a value from a function, which too was not possible in VB 6.0. To use the functionality of MyClass, you need to create an object of MyClass, as shown in the following code:

 Dim objMyClass as new MyClass 

This declaration creates an instance of the MyClass class. After instantiating the class, you can use the class object, objMyClass, to invoke the myMethod() function.

Working with Properties

In VB.NET, the Property-End Property pair creates a property. The Get method of a property retrieves the property value and the Set method sets the property value. Listing 1-6 shows how to define and use a property in a class in VB.NET:

Listing 1-6: Property Definition in VB.NET

start example
 Public Class MyClass Dim myString as String="Hello World" 'Adding Display property to the class Public Property Display() As String Get Return myString End Get Set(ByVal Value As String) myString = Value End Set End Property End Class Public Class TestClass Sub main() Dim objMyClass As new MyClass MsgBox objMyClass.Display    objMyClass.Display="Hello Rest of the World"    MsgBox objMyClass.Display    End Sub End Class 
end example

In the above listing, the MyClass class defines a property, Display, along with its methods that return and set the value of the variable, myString. The TestClass class defines the main() function that creates an object of MyClass and retrieves the default value of the Display property of MyClass. The method then sets the value of the Display property to "Hello Rest of the World" and displays the updated value to the end user.

Inheritance in VB.NET

You use inheritance to acquire the features of a class and extend those features to create a specialized class. Listing 1-7 shows how to implement inheritance in VB.NET:

Listing 1-7: Subclassing in VB.NET

start example
 Public Class A Public Function methodA() as String Return "Method of Class A" End Function End Class Public Class B inherits A Public Function methodB() as String Return "Method of Class B" End Function End Class Public Class TestClass Public Sub main() Dim objB as new B Console.WriteLine(objB.methodA()) Console.WriteLine(objB.methodB()) End Sub    End Class 
end example

In the above listing, class B inherits class A to extend the functionality that class A provides. You need to use the inherits keyword to implement inheritance.

Working with Variables

In VB.NET, you can declare multiple variables of the same type in one declaration. This feature was not available in VB 6.0. For example, you can declare two integer variables in one declaration, as shown in the following code:

 Dim sampleInteger1, sampleInteger2 As Integer 

In addition, you can initialize variables at the time of their declaration in VB.NET. This feature was also not available in VB 6.0. For example, you can declare a string variable and initialize it in one step, as shown in the following code:

 Dim myName As String = "Ed Smith" 

Working with Objects

All components of VB.NET language are objects. The built-in data types, such as Integer or String, are also objects. You create an object using the new keyword. For example, you can create a string variable in two ways, as shown in the following code snippets:

 Dim myString as String Dim myString as String=new String() 

VB.NET eliminates the use of the Set keyword to assign objects to variables. In VB 6.0, you need to use the Set keyword to assign an object to a variable, as shown in the following code:

 Set myObject=new MyObject 

The code to perform the same task in VB.NET is:

 myObject=new MyObject() 

Overview of VC++.NET

VC++.NET provides an environment to develop different types of applications, such as Windows applications, Web applications, XML Web services, and mobile applications, using C++. VC++.NET includes components, such as Active Template Library (ATL), Microsoft Foundation Class (MFC) libraries, and advanced language extensions, which simplify the task of developing applications in VC++. In addition, VC++.NET is integrated with the Visual Studio.NET IDE that has its own built-in features to facilitate application development. VC++.NET is an object-oriented language that is supported by an optimized compiler. This helps create robust components and applications.

Features of VC++.NET

VC++.NET provides several new features and enhancements, which help traditional C++ programmers create applications that target the .NET platform. These features include modifications to the preprocessor, compiler, linker, libraries, and development environment. The enhancements include:

  • Managed extensions for C++: Are additions to the syntax and keywords of C++. These extensions allow you to create C++ applications that execute in the .NET runtime and use all the services of the CLR, such as memory management and exception handling. Managed extensions enable integration of managed and unmanaged code within the same application. This saves the investment made in developing the existing C++ code.

  • Platform invoke capabilities: Help invoke unmanaged Application Programming Interfaces (APIs) that are provided by the Win32 DLLs, from managed applications by simply including the header file in your application and linking the application with the import library.

  • Web services creation facility: Helps create Web services using C++. VC++.NET includes an ATL Server, which is a set of unmanaged C++ classes. You use these classes to create Web applications, Web services, and other applications for the server.

Note

To learn more about managed extensions, see the Introduction to Managed Extensions ReferencePoint.

Project Types in VC++.NET

Visual Studio.NET includes four broad project categories that provide the templates to create different VC++.NET applications:

  • ATL

  • MFC

  • Win32

  • .NET

Active Template Library Project

ATL provides a set of template-based C++ classes that allow you to create Component Object Model (COM) objects. The ATL project type provides two templates to create COM components:

  • ATL project: Creates a project that provides facilities to include COM objects in your application. You can add objects, controls, and COM+ objects to an ATL project.

  • ATL server Web service: Provides classes that allow you to create Web services using C++. The classes that support the creation of XML Web services are collectively termed as ATL server.

Microsoft Foundation Classes Project

MFC classes provide tools to create ActiveX controls, database applications, and Windows desktop applications. The MFC project type provides the following templates to create applications that use the MFC classes:

  • MFC ActiveX control: Generates an MFC control class that serves as an ActiveX control. You can also specify the properties of the control that generates a property page class.

  • MFC application: Provides a Windows executable .exe application that can have Multiple Document Interface (MDI) and database support. The MFC application includes C++ source (.cpp) files, resource (.rc) files, header (.h) files, and a project (.vcproj) file.

  • MFC DLL: Creates an MFC DLL application that implements the basic features of a DLL. This application includes C++ source (.cpp) files, resource (.rc) files, and a project (.vcproj) file.

Win32 Project

Win32 applications use Win32 APIs to provide the operating system functionality.

You can use the Win32 project type to create Win32 applications, such as a console application, a Windows application, a DLL, or a static library.

.NET Project

Managed extensions for C++ in .NET extend the C++ language to allow you to use C++ in the .NET Framework and target the CLR for code execution. The .NET project type allows you to create various applications, such as console applications, ASP.NET Web service, Class library, Windows Forms applications, and Windows control library, using managed C++ extensions.

Overview of ADO.NET

ADO.NET helps connect a .NET application to multiple sources of data, such as a database, a text file, an XML file, or a spreadsheet. ADO.NET includes a set of classes under the System.Data namespace that provides data-access services.

Benefits of ADO.NET

Three key issues you need to examine when you design and develop your application are speed of data access, scalability, and data interoperability. To address all these issues, Microsoft developed ADO.NET, which is a subset of .NET Framework. The benefits of using ADO.NET are:

  • Leverages the existing knowledge of ADO. ADO.NET ensures smooth and efficient migration from ADO to ADO.NET. The basic constructs in the two languages remain the same. As a result, you do not have to spend time learning a completely new technology. ADO can also coexist with ADO.NET. This enables you to use both ADO.NET and ADO in your applications, using the COM interoperability services of .NET.

  • Enhances interoperability by supporting XML for data exchange. Because XML encodes data in a text format, any end user can access it from anywhere and on any platform. ADO.NET supports XML at a very basic level because the XML-based classes in .NET and the ADO.NET classes spring from the same architecture.

  • Makes applications scalable by providing disconnected data access. This means you can open a connection to the database in your application and use it until the data access request completes execution. After that, you can close the connection. In contrast, ADO provides connected data access, where the connection to the database remains active throughout the lifetime of the application. Disconnected data access improves application scalability because it allows the database to handle many more connections at a time.

  • Reduces development time by providing a more robust work environment. You can use ADO.NET to develop a more reliable and bug-free application, as compared to ADO. For example, ADO.NET provides typed DataSets, which include classes whose objects are type-safe. This prevents type incompatibilities at runtime. As a result, your code will be less prone to errors and faster to develop, as compared to that developed in ADO. ADO.NET also provides Transaction objects that make data transactions in your applications more reliable.

Architectural Components of ADO.NET

The architecture of ADO.NET facilitates interaction with the data sources by separating data access from data manipulation. The object model of ADO.NET consists of two prime components:

  • Connected data model: Includes the .NET Framework Data Provider, which contains components that connect to the database, directly execute commands against it, and read data from the database. The .NET Framework Data Provider includes four components: Connection, Command, DataReader, and DataAdapter.

  • Disconnected data model: Includes the DataSet that provides a local cache for disconnected data. This means that you can manipulate the retrieved data in the cached copy, without maintaining an active connection with the database. You establish a connection with the database only when you are ready to update the data to the database. Because DataSets are XML-based, they allow exchange of data between applications.

Figure 1-4 shows the components that make up the architecture of ADO.NET:

click to expand: this figure shows the .net data provider and dataset elements of the ado.net architecture.
Figure 1-4: Architecture of ADO.NET

The .NET Framework Data Provider

The components of the .NET Framework Data Provider help establish and maintain a connection with the database. These components also allow you to manipulate data in the database, such as update and delete data, and access the data in a rapid, forward-only, or read-only manner.

You can write the .NET Data Provider for any data source. The .NET Data Providers that are shipped along with the .NET Framework are:

  • The .NET Framework Data Provider for OLE DB: Works with any source of data other than Microsoft SQL Server 7.0 or later, such as Microsoft Access database or the Oracle database. To use this provider, your application needs to import the System.Data.OleDb namespace that contains all the classes for this provider.

  • The .NET Framework Data Provider for SQL Server: Works directly with Microsoft SQL Server 7.0 or later. To use the SQL Server .NET Data Provider, your application needs to import the System.Data.SqlClient namespace that contains all the classes for this provider.

The .NET Framework Data Provider includes four elements that provide various functionalities for efficient data access:

  • Connection object: Is an instance of a class that implements the IDbConnection interface and helps connect to the database.

  • Command object: Is an instance of a class that implements the IDbCommand interface and helps execute commands to the database across a connection. These commands allow you to retrieve and modify data, execute stored procedures on the database, and send or retrieve information about the different parameters in the database.

  • DataReader object: Is an instance of a class that implements the DataReader interface. DataReader provides a read-only, forward-only, and connected access to the ADO.NET data. You cannot directly create an instance of the DataReader object in your application. When you execute the ExecuteReader() method of the Command object, this method returns a DataReader object. The main advantage of using DataReader is that it does not buffer the data in the memory. As a result, DataReader reduces the overhead on the system’s performance. One of the drawbacks of using the DataReader is that it provides connected access to the data. This means that you need to have an active connection with the database throughout the lifetime of the DataReader object.

  • DataAdapter object: Is an instance of a class that derives from the DbDataAdapter class that implements the IDbDataAdapter interface. DataAdapter acts as the intermediary between the data source and the DataSet, by populating the DataSet with the data retrieved from the database. After you finish manipulating the data in the DataSet, you can use the DataAdapter to commit the changes to the database. The DataAdapter object provides a set of commands to the database, which include SelectCommand, InsertCommand, UpdateCommand, and DeleteCommand.

The DataSet Object

The DataSet object provides a local cache of disconnected data. This means that you do not work with live data on the server at any point of time. Whatever manipulations and updates you make to the data in the dataset are independent of the database. These changes are made to the local cached copy only and can be committed to the database at a later point of time. You can also fill data in the dataset regardless of the data source, such as a database or an XML file. This is because the native form of a dataset is XML. In addition, you can load files directly from XML documents to a dataset, without using a DataAdapter object. As a result, data from multiple and varied sources, such as Microsoft SQL server database or an Oracle database, can be collated in one DataSet object. A DataSet object cannot connect to the database or retrieve data from the database on its own. You need to use a DataAdapter object to fill the DataSet object with the fetched data.

You can use the DataSet object:

  • To navigate between multiple tables of results.

  • To add, edit, and delete rows of data in a disconnected cache.

  • To manipulate data retrieved from multiple sources. For example, you can use a DataSet object to integrate data from more than one database, from an XML file, and from a spreadsheet.

  • To exchange data between tiers by using an XML Web service because data in a DataSet can be exchanged remotely.

  • To reuse a set of rows for various tasks, such as sorting, searching, or filtering data. Application performance improves if these rows are cached locally.

  • To perform a large amount of processing for each row. If your application involves extensive processing of the data returned in a DataReader object, the database connection remains active for a longer period than required. This reduces performance of the system.

The DataSet object provides a relational view of the data in the database. The main components of a DataSet object are:

  • DataTableCollection: Includes one or more DataTable objects. Each DataTable object represents one table of the locally cached data. The DataTableCollection includes three collections:

    • DataRowCollection: Includes DataRow objects, each of which is a pointer to an actual row of data in the database.

    • DataColumnCollection: Includes DataColumn objects, each of which provides schema information about one column of data.

    • ConstraintCollection: Includes Constraint objects that allow you to define the constraints between the database entities, such as primary and foreign key constraints. These constraints help maintain the integrity of data in the tables.


  • DataRelationCollection: Contains objects that help define relationships between different DataTable objects. These relations facilitate navigation between parent and child rows of the retrieved data.

Note

To learn more about ADO.NET, see the Programming with ADO.NET Classes ReferenecePoint.




Migrating Unmanaged Applications to. NET
Migrating Unmanaged Applications to. NET
ISBN: N/A
EAN: N/A
Year: 2004
Pages: 31

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net