A Programmer's Guide to ADO.NET in C#

A Programmer's Guide to ADO.NET in C#

3.7 4
by Mahesh Chand, Mike Gold
     
 

This is the book on ADO.NET! ADO.NET is the latest database technology from Microsoft and is the most powerful way to manipulate a database to date. A Programmer's Guide to ADO.NET in C# begins by taking readers through an overview of C# and then delves into ADO.NET. Mahesh Chand provides details on how to use each of .NET's major data providers, including OLE DB, SQL… See more details below

Overview

This is the book on ADO.NET! ADO.NET is the latest database technology from Microsoft and is the most powerful way to manipulate a database to date. A Programmer's Guide to ADO.NET in C# begins by taking readers through an overview of C# and then delves into ADO.NET. Mahesh Chand provides details on how to use each of .NET's major data providers, including OLE DB, SQL Server, and the release version of ODBC. This book also serves as a great reference for the methods and properties associated with these data providers' classes.

In addition, Chand shows C# programmers how to work with XML classes, integrate XML into the ADO.NET architecture, and use the power of XML to transfer, read, and store data. A Programmer's Guide to ADO.NET in C# provides developers with handy ideas for taking advantage of the Visual Studio .NET IDE and for tying data to myriad, powerful Windows Forms and Web Forms, including the multifaceted DataGrid control. Chand also discusses how you can use ADO.NET to develop Web applications and create Web services. Easy-to-follow, visually rich examples illustrate how to create and execute stored procedures, work with triggers and views, create and update tables, and perform event handling in ADO.NET. Chand also guides you through the development of a Web-based guest book.

About the Author:

Mahesh Chand is a software developer with Kruse Inc., a document-management software company, and is also an MCP in Visual C++ 6.0. He's the founder of both Mindcracker and C# Corner, a premier online resource for C# and .NET developers. Chand has a master's degree in computer science and a bachelor's degree in mathematics

Read More

Product Details

ISBN-13:
9781893115392
Publisher:
Apress
Publication date:
04/18/2002
Edition description:
2002
Pages:
718
Product dimensions:
7.52(w) x 9.25(h) x 0.06(d)

Read an Excerpt

Chapter 1: Introduction to C#

This chapter will introduce you to C#. You'll learn how to write and compile C# programs, C# syntaxes, data types, control flow, classes and their members, interfaces, arrays, and exception handling. I'll begin with an overview of the language.

Understanding the C# Language

Microsoft developed C#, a new programming language based on the C and C++ languages. Microsoft describes C# in this way: "C# is a simple, modern, object-oriented, and typesafe programming language derived from C and C++. C# (pronounced C sharp) is firmly planted in the C and C++ family tree of languages and will immediately be familiar to C and C++ programmers. C# aims to combine the high productivity of Visual Basic and the raw power of C++."

Anders Hejlsberg, the principal architect of C#, is known for his work with Borland on Turbo Pascal and Delphi (based on object-oriented Pascal). After leaving Borland, Hejlsberg worked at Microsoft on Visual J++.

Some aspects of C# will be familiar to those who have programmed in C, C++ , or Java. C# incorporates the Smalltalk concept, which means everything is an object. In other words, all types in C# are objects. C# properties are similar to Visual Basic properties. The Rapid Application Development (RAD) goal in C# is assisted by C#'s use of concepts and keywords, such as class, struct, statement, operator, and enum. The language also utilizes the concepts contained in the Component Object Model (COM) architecture.

Unlike Visual Basic or Delphi, events are data types in C# and can belong to an object. Members of a class object can have variables, methods, properties, and events. Attributes are another nice feature of the language.

Note: C# is a case-sensitive language.

C# and Open Source: The Mono Project

C# and Common Language Infrastructure (CLI) is under consideration at the European Computer Manufacturers Association (ECMA). You'll probably see C# running on Unix and Linux operating systems. It's no wonder you see many C# compilers emerging from different development tool companies.

Ximian, the Boston-based company that's well-known for its open-source product, GNOME, is working on a Linux-based, .NET open-source project called the Mono Project. The Mono Project incorporates key .NET-compliant components, including a C# compiler, a Common Language Runtime (CLR), a Just-In-Time (JIT) compiler, and a set of class libraries that will let developers create .NET applications that run on Windows, Linux, or Unix platforms. You'll find more information on the Mono Project at http://www.ximian.com/mono/ or at the ECMA Web site at http://www.ecma.ch./.

How and Why C# Came to Be

It was a dream of developers to have a language as powerful and as fast as C++, yet as easy to program as Microsoft's Visual Basic and Borland's Delphi. Microsoft planned its .NET Framework and C# language for years.

Prior to .NET, the most popular programming languages for Web and Windows development were Visual Basic, Java, Visual C++, and Delphi. Each of these languages has its pros and cons. Visual Basic and Delphi are easy to use and simple to program; however, they're not truly object-oriented, and they lack the flexibility to develop complex programs. Java is good for Web development, but it still lacks in its object-oriented aspects and in its capability to develop complex Windows applications. Java's platform independence, however, is a plus. Visual C++ is a great tool to develop Windows- and COM-based applications, but it's not as easy to use as Visual Basic or Delphi.

Microsoft wanted to develop an integrated tool with all the positive features of these languages and more. C# is the result. C# is as easy to use and as productive as Visual Basic and Delphi. Because it's derived from C and C++, it doesn't leave the C++ programmer at the beginning of the learning curve. C# also has the power and flexibility of C++. Because of its platform-independent nature (companies are still working on supporting C# on other operating systems such as Unix and Linux), you can deploy C# applications onto any .NET-supported platform. C# also provides Web development similar to Java with the help of ASP.NET.

Characteristics and Features of C#

As explained, C# was developed as a language that would combine the best features of previously existing Web and Windows programming languages. I'll discuss some of the primary characteristics of C# in the following sections.

Modern and Object Oriented
A modern language is one that provides latest features and tools for developing scalable, reliable, and robust industry-standard applications. C# is a modern language. The current trend in programming is Web development, and C# is the best language for developing Web applications and components for the Microsoft .NET platform.

As mentioned, C# is an object-oriented language. It supports all the basic object-oriented language features: encapsulation, polymorphism, and inheritance. Unlike C++, C# doesn't support multiple inheritance; however, there are always workarounds if you really need this capability. A few articles are available on C# Corner (http://www.c-sharpcorner.com/Language/MultipleInheritanceCB.asp) for more information on such workarounds.

Simple and Flexible
C# is as simple to use as Visual Basic, in that everything in C# is represented as an object. All data types and components in C# are objects. C++ programmers are sometimes confused when choosing different access operators to process objects. With C#, you use a dot (.) operator to access the object members.

Programmers use C# to develop both managed and unmanaged code. Managed code is code managed through the CLR module. It handles garbage collection, typesafety, and platform-independent behavior. Unmanaged code, on the other hand, is code run outside the CLR, such as an ActiveX control. C# provides the flexibility of using native Win 32 application programming interface (API) and unmanaged code through COM+. C# enables you to declare unsafe classes and members having pointers, COM interfaces, structures, and native APIs. Although the class and its members are not typesafe, they still can be executed from managed code using COM+. Using the N/Direct feature of C# and COM+, you can use the C language API. With the help of the COM+ run-time and the COM+ Common Language Specification (CLS), you can access the COM and COM+ API. Using the Sysimport attribute, you can even access native Windows API (DLLs) in C#. See the "Attributes" section of this chapter for more about attributes.

Typesafety
C# is a typesafe language. All variables and classes (including primitive types, such as integer, Boolean, and float) in C# are a type, and all types are derived from the object type. The object type provides basic functionality, such as string conversion, and information about a type. (See "The Object Class" section of this chapter for more about the object type). C# doesn't support unsafe type assignments. In other words, assigning a float variable directly to a Boolean variable is not permitted. If you assign a float type to a Boolean type, the compiler generates an error.

C# has two kinds of types: value types and reference types. All value types are initialized with a value of zero, and all reference types are automatically initialized with a null value (local variables need to be initialized explicitly or the compiler throws a warning). The "Types in C#" section of this chapter will discuss types in more detail.

Note: Some books and documentation also use the word type to mean a class such as MSDN. 

Automatic Memory Management and Garbage Collection
Automatic memory management and garbage collection are two important features of C#. With C#, you don't need to allocate memory or release it. The garbage collection feature ensures that unused references are deleted and cleaned up in memory. You use the new operator to create a type object, but you never need to call a delete operator to destroy the object. If the garbage collector finds any unreferenced object hanging around in memory, it removes it for you. Although you can't call delete directly on an object, you have ways to get the garbage collector to destroy objects.

Versioning Control and Scalable
If you're a Microsoft Windows developer, you should be familiar with the expression DLL hell, which refers to having multiple versions of the same Dynamic Link Library (DLL) and not having backward and forward compatibility. For example, you can't run programs written in Microsoft Foundation Class (MFC) version 4.0 on systems with MFC version 3.0 or earlier. This is one of the biggest challenges for a developer, especially if you're developing MFC applications.

The C# model is based on namespaces. All interfaces and classes must be bundled under a namespace. A namespace has classes as its members. You can access all the members or just a single member of a namespace. Two separate namespaces can have the same class as their member.

C# also supports binary compatibility with a base class. Adding a new method to a base class won't cause any problems in your existing application.

.NET assemblies contain metadata called manifest. A manifest stores information about an assembly such as its version, locale, and signature. There is no concept of registry entries for handling compatibility. In .NET, you simply put your assembly into one global folder if you want to make it sharable; otherwise, you put it in a private folder for private use only.

Language and Cross-Platform Interoperability
C#, as with all Microsoft .NET-supported languages, shares a common .NET run-time library. The language compiler generates intermediate code, which a .NET-supported compiler can read with the help of the CLR. Therefore, you can use a C# assembly in VB .NET without any problem, and vice versa.

With the full support of COM+ and .NET Framework services, C# has the ability to run on cross-platform systems. The Web-based applications created from .NET use an Extensible Model Language (XML) model, which can run on multiple platforms....

Read More

Customer Reviews

Average Review:

Write a Review

and post it to your social network

     

Most Helpful Customer Reviews

See all customer reviews >