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

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

by Mahesh Chand, Mike Gold
A Programmer's Guide to ADO.NET in C#

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

by Mahesh Chand, Mike Gold

Paperback(Softcover reprint of the original 1st ed.)

$54.99 
  • SHIP THIS ITEM
    Qualifies for Free Shipping
  • PICK UP IN STORE
    Check Availability at Nearby Stores

Related collections and offers


Overview

A Programmer's Guide to ADO.NET in C# begins by taking readers through a fast-paced overview of C# and then delves into ADO.NET. Why should C# programmers use it instead of the existing technologies? What new functionality does it offer? The chapters that follow go through the details on each of the major Data Providers of the .NET platform (OleDb, SQL Server, and ODBC) that enable you to read and write data to the targeted database. These chapters also serve as a good reference for looking up detailed methods and properties for these data provider classes. Authors Chand and Gold also show C# programmers how to work with XML classes and how to integrate XML into the ADO.NET architecture.

The book provides programmers with handy ideas about taking advantage of the VS.NET IDE and how you can tie your data to the myriad of powerful controls including the multi-faceted Data Grid. Finally, it goes through creating a guest book application for the Web so you can see how all the pieces fit together.


Product Details

ISBN-13: 9781893115392
Publisher: Apress
Publication date: 04/25/2002
Series: Expert's Voice
Edition description: Softcover reprint of the original 1st ed.
Pages: 718
Product dimensions: 7.52(w) x 9.25(h) x 0.06(d)

About the Author

Mahesh Chand is presently engaged with Kruse. Inc. as a software developer. He has been working with Microsoft database technologies including ODBC, DAO, ADO, and OLE-DB for over 5 years. He has a M.S. degree in Computer Science and a B.S. in Mathematics. He is also an MCP in VC++ 6.0. Mahesh is also the founder of Mindcracker (http://www.mindcracker.com) and C# Corner (http://www.c-sharpcorner.com), a premier online resource for C# and .NET developers. In addition to his day job, Mahesh writes and program for C# Corner on C#, VB .NET, ASP .NET and other .NET technologies and help site visitors.

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....

Table of Contents

1: Introduction to C#.- 2: Introduction to Windows Forms.- 3: Overview of ADO.NET.- 4: Data Components in Visual Studio .NET.- 5: ADO.NET Data Providers and Disconnected Classes.- 6: Working with XML.- 7: Developing Web Applications Using ADO.NET.- 8: Using Web Services with ADO.NET.- 9: Handling ADO.NET Events.- 10: Different Flavors of ADO.NET.- 11: Working with the ODBC .NET Data Provider.- Appendix A: Relational Databases: Some Basic Concepts.- Understanding Normalization.- Introducing Sets, Cursors, and ADO.NET.- Using Locking.- References and Resources.- Appendix B: Commonly Used SQL Statements.- Understanding SQL References.- Understanding Views.- Using SQL Server’s SELECT...FOR XML Clause.- References and Resources.
From the B&N Reads Blog

Customer Reviews