Microsoft Visual C++ .NET Professional Projects - Premier Press
.pdf
IMPLEMENTING ADO.NET IN A MANAGED C++ APP. Chapter 14 501
{
error->SetError(amount,”Invalid amount”); return false;
}
else
error->SetError(amount,””);
try
{
Convert::ToDouble(amount->Text);
Convert::ToInt32(refacno->Text);
}
catch(...)
{
MessageBox::Show(“Please specify the amount and referral account number as integers.”);
return false;
}
return true;
}
Build and execute the application. Try adding and modifying records.
Summary
In this chapter, you learned how to create a Managed C++ application that uses ADO.NET to fetch, add, and update the data stored in a database. You have also seen how the error handling for a set of controls can be done using the ErrorProvider class. While the lack of a GUI tool for creating forms is a big drawback, a little bit of adroit coding can largely overcome that problem.
This page intentionally left blank
PART V
Professional
Project – 4
This page intentionally left blank
Project 4
Creating a Managed Extensions Class Library and Using It from within an ASP.NET Application
Project 4 Overview
One of the important technologies supported by Visual Studio .NET is
ASP.NET. ASP.NET is a technology that helps you to rapidly develop Web sites using the programming language of your choice. Visual C++ .NET supports the creation of Web services completely, but does not support the creation of ASP.NET applications. Currently, you can create ASP.NET applications using C# and Visual Basic .NET. The technology does not currently support C++. However, in this chapter, you will explore how existing code based in C++ can be used to power ASP.NET applications.
The technologies that I’ll use to build the Web services application are the following:
Managed Extensions for C++
Class library
ASP.NET
This project explores creating an ASP.NET application using C#. The business logic of this application is created using C++.
The Web is one of the most powerful tools of communication in the world today. Microsoft made creating powerful Web applications simple by introducing ASP.NET — a powerful scripting language that Web developers can use
to create dynamic and structured Web applications in a short span of time.
The rationale behind this part of the book (Part V) is mainly to throw light on how to access a Managed C++ Class Library from within an ASP.NET application. Prior to coding the project, in which you will be creating a class library and accessing it from within an ASP page, you need to understand the basic concepts of ASP.NET.
This chapter introduces you to those basic concepts of ASP.NET. In addition, you will learn about the ideal platform requirements for ASP.NET and Web Forms.
The Evolution of ASP.NET
As computers have evolved, so too have the variety of software programs designed to run on computers. With each new release of a software program, the vendors fix existing bugs as well as introduce new features that make developing applications using the software simpler. ASP.NET is no exception. Since its launch in 1996, ASP has experienced several changes and has emerged as ASP.NET, which undoubtedly is one of the most powerful server-side scripting languages on the market today.
Since ASP was launched in 1996, two more versions, ASP.NET 2.0 and ASP.NET 3.0, have been released. Though several new features were added with each new release of ASP, the basic CLR methodology remained the same. The methodology offered various benefits, including the following:
Ease of configuration
Ease of deployment
Automatic memory management
Multiple language support
A secure mechanism for user authentication
INTRODUCTION TO ASP.NET |
Chapter 15 |
509 |
|
|
|
|
|
Though ASP.NET is based on the .NET Framework methodology, it offers you all the benefits in the preceding list and many more. The following are the other benefits that make ASP.NET one of the most powerful server-side scripting languages today and the preferred choice of most Web developers:
Built-in support for other programming languages. In previous versions, ASP supported only scripting languages such as VBScript and JScript, which had certain drawbacks. First, these languages were not compiled, meaning it was possible to detect errors only at run time, which resulted in adverse effects on the performance of the applications. Secondly, these languages did not support predefined data types, thus resulting in developers having to cast existing objects to expected data types. This led to the objects being validated only at run time. Although ASP.NET continues to support VBScript and JScript, it now also supports more powerful languages, such as Visual C# and Visual Basic.
Built-in support for cross-language development. ASP.NET now provides functionality that enables objects created in one language to be used in another language. For example, objects created in Visual Basic
.NET can be extended in Visual C#.
Secure mechanism for user authentication. ASP.NET offers a secure mechanism for user authentication that automatically redirects unauthorized users to the Login page. In addition, ASP.NET offers an efficient cookie management system. It assigns each user a different account and role and accordingly grants the user access and modification rights. This ensures that only authorized users have rights to access and modify the code on the Web server.
Clear demarcation between content and application logic. One of the biggest drawbacks in the previous versions of ASP was that developers designing the user interface and the programming logic could not work simultaneously, because the HTML and ASP code were integrated. This integration of HTML and ASP also posed a greater problem when the pages needed to be updated frequently.
In ASP.NET, Microsoft has eliminated this limitation. ASP.NET now has a clear demarcation between the content and the application logic. The developer creating the application logic and the developer designing the application can now work simultaneously. All programming logic at the back end is separated from the logic used to create the
