Professional Documents
Culture Documents
Table of Contents
Applied ADO.NETBuilding Data-Driven Solutions
Introduction
Chapter 1 - ADO.NET Basics
Chapter 2 - Data Components in Visual Studio .NET
Chapter 3 - ADO.NET in Disconnected Environments
Chapter 4 - ADO.NET in Connected Environments
Chapter 5 - Handling ADO.NET Events
Chapter 6 - Integrating XML with ADO.NET
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
Chapter 8 - Constraints and Data Relations
Chapter 9 - ADO.NET Exception Handling
Chapter 10 - Working with the ODBC .NET Data Provider
Chapter 11 - Stored Procedures and Views
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Chapter 13 - Developing a Custom Data Provider
Chapter 14 - Developing Database Web Applications using ASP.NET
Chapter 15 - Using ADO.NET in Xml Web Services
Chapter 16 - ASP.NET Server Controls and Data Binding
Chapter 17 - Building Real-World Web Applications
Chapter 18 - Object-Relational Mapping in .NET
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
Chapter 20 - COM Interoperability and ADO.NET
Chapter 21 - Messaging
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Appendix A - Relational Databases: Some Basic Concepts
Appendix B - Commonly Used SQL Statements
Appendix C - ADO.NET Frequently Asked Questions
Index
List of Figures
List of Tables
List of Listings
List of Sidebars
Applied ADO.NET: Building Data-Driven Solutions
Back Cover
by Mahesh Chand and David Talbot ISBN:1590590732
Applied ADO.NET: Building Data-Driven Solutions provides extensive coverage of ADO.NET technology including
Apress 2003 (928 pages)
ADO.NET internals, namespaces, classes, and interfaces. Where most books cover only SQL and OLE DB data
This text
providers, Mahesh Chand andprovides extensive
David Talbot covercoverage
SQL, OLEofDB,
ADO.NET technology
ODBC data providers and the latest additions to
including
ADO.NET: Oracle, MySQL, andADO.NET
XML .NETinternals, namespaces,
data providers. Chandclasses, and also cover internals of data binding and
and Talbot
interfaces,
they provide detailed coverage and takesWindows
on both a comprehensive
Forms and look
WebatForms
XML data binding and data-bound controls.
namespaces
Since XML plays a major and classes,
role in .NET and how
development, theto integrate
authors alsoboth with a comprehensive look at XML
provide
ADO.NET.
namespaces and classes, and how to integrate both with ADO.NET.
Applied ADO.NET: Building Data-Driven Solutions begins with the basics of ASP.NET and data-bound controls. It
then delves
Table into internals of data binding and shows how to use DataGrid, DataList, and other data-bound controls
of Contents
in real-world
Applied applications. Chand
ADO.NETBuilding and Talbot
Data-Driven also discuss the ASP.NET guest book, database XML Web services, and
Solutions
even an online bookstore site development and design process. Advanced developers will learn from the coverage
Introduction
of ADO.NET architecture, related design issues, and how ADO.NET data providers are designed. The authors also
show
Chapter
how1 to -create
ADO.NET
a Custom
BasicsData Provider. Event handling, server side programming, data relations and
constraints, Active Directory,
Chapter 2 - Data Components messaging,
in Visual exception
Studio .NETand error handling, and object relational model are other topics
covered in detail.
Chapter 3 - ADO.NET in Disconnected Environments
Chapter 4 - ADO.NET in Connected Environments About the Authors
Chapter 5 - Handling ADO.NET Events
Mahesh
ChapterChand is presentlyXML
6 - Integrating engaged as a software developer with Kruse. Inc. He has been working with Microsoft
with ADO.NET
database technologies including ODBC, DAO, ADO, and OLE-DB for over 5 years. He has a M.S. degree in Computer
Chapter a7 B.S.
Science, - Data Binding and and
in Mathematics, Windows Forms
is also Data-Bound
a Microsoft Controls
Certified Professional in VC++.In addition to his day job,
Mahesh
Chapterwrites
8 - Constraints
and programsandfor
Data
C#Relations
Corner on C#, VB .NET, ASP .NET and other .NET technologies and help site
visitors.
Chapter 9 - ADO.NET Exception Handling
Chapter 10 - Working with the ODBC .NET Data Provider
David Talbot's background is diverse, ranging from developing license plate recognition technology to television set
Chapter
boxes 11 - Stored
to scalable WebProcedures and
applications. Views
Currently, David works in the New Business Technologies group at FreeMarkets
applying
Chapter cutting edge .NET
12 - Oracle, SQLXML,technologies
and Otherto.NET
solveData
business problems. He has been working with .NET since the early
Providers
betas, developing a number of solutions for several start-ups and established companies while working on several
Chapter 13 - Developing a Custom Data Provider
.NET books and articles. Prior to the development of .NET, David worked primarily on Java, SCO UNIX, Linux, DB2,
Chapter
SQL 14 -and
Server, Developing
PERL. Database Web Applications using ASP.NET
Chapter 15 - Using ADO.NET in Xml Web Services
Chapter 16 - ASP.NET Server Controls and Data Binding
Chapter 17 - Building Real-World Web Applications
Chapter 18 - Object-Relational Mapping in .NET
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
Chapter 20 - COM Interoperability and ADO.NET
Chapter 21 - Messaging
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Appendix A - Relational Databases: Some Basic Concepts
Appendix B - Commonly Used SQL Statements
Appendix C - ADO.NET Frequently Asked Questions
Index
List of Figures
List of Tables
List of Listings
List of Sidebars
Applied ADO.NET-Building Data-Driven
Applied ADO.NET: Building Data-Driven Solutions
by Mahesh Chand and David Talbot ISBN:1590590732
Solutions
Apress
MAHESH CHAND AND 2003 (928 pages)
DAVID TALBOT This text provides extensive coverage of ADO.NET technology
including ADO.NET internals, namespaces, classes, and
interfaces, and takes a comprehensive look at XML
namespaces and classes, and how to integrate both with
ADO.NET.
Outside the United States, fax +49 6221 345229, email <orders@springer.de>, or visit
http://www.springer.de.
For information on translations, please contact Apress directly at 2560 9th Street, Suite 219, Berkeley, CA
94710. Phone 510-549-5930, fax: 510-549-5939, email <info@apress.com>, or visit
http://www.apress.com.
The information in this book is distributed on an "as is" basis, without warranty. Although every precaution
has been taken in the preparation of this work, neither the author nor Apress shall have any liability to any
person or entity with respect to any loss or damage caused or alleged to be caused directly or indirectly by
Applied ADO.NET: Building Data-Driven Solutions
the information contained in this work.
by Mahesh Chand and David Talbot ISBN:1590590732
The source codeApress
for thisbook is available
2003 (928 pages) to readers at http://www.apress.com in the Downloads
section. This text provides extensive coverage of ADO.NET technology
including ADO.NET internals, namespaces, classes, and
To uncles Banshiinterfaces, and takes
Lal and Rajbir Singha comprehensive look at XML
Malik for their support and guidance.
namespaces and classes, and how to integrate both with
-Mahesh Chand ADO.NET.
David Talbot has worked in a variety of technologies including television set top boxes, license plate
recognition, and scalable Web applications. He has written a number of articles concerning .NET
technologies and has worked in various capacities on three books. He is currently working as a
development manager in the New Business Technologies group at FreeMarkets in Pittsburgh,
Pennsylvania. Applied ADO.NET: Building Data-Driven Solutions
by Mahesh Chand and David Talbot ISBN:1590590732
Apress
About the Technical Reviewer
2003 (928 pages)
This text provides extensive coverage of ADO.NET technology
including ADO.NET internals, namespaces, classes, and
interfaces, and takes a comprehensive look at XML
namespaces and classes, and how to integrate both with
ADO.NET.
Table of Contents
Applied ADO.NETBuilding Data-Driven Solutions
Introduction
Chapter 1 - ADO.NET Basics
Chapter 2 - Data Components in Visual Studio .NET
Chapter 3 - ADO.NET in Disconnected Environments
Chapter 4 - ADO.NET in Connected Environments
Chapter 5 - Handling ADO.NET Events
Chapter 6 - Integrating XML with ADO.NET
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
Chapter 8 - Constraints and Data Relations
Philip Pursglove
Chapter 9 - ADO.NETis aException
developer with the Willis Group, based in Ipswich, United Kingdom. He has worked
Handling
with every
Chapter 10 -version
Workingofwith
Visual
theBasic
ODBCfrom
.NET3.0 onward.
Data Philip was one of the first developers in the UK to gain
Provider
the Microsoft
Chapter Certified
11 - Stored Application
Procedures Developer certification; he also holds the Microsoft Certified Solution
and Views
Developer certification in addition to a degree in business information systems. Philip writes for Pinnacle
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Publishing'sHardcore Visual Basic and SQL Server Professional magazines, and he speaks at user
Chapter 13 - Developing a Custom Data Provider
group events in the UK. He maintains a Web site at www.philippursglove.com and can be reached
Chapter 14 - Developing Database Web Applications using ASP.NET
at <phil@philippursglove.com>.
Chapter 15 - Using ADO.NET in Xml Web Services
Chapter 16 - ASP.NET Server Controls and Data Binding
Acknowledgments
Chapter 17 - Building Real-World Web Applications
First, I would
Chapter like to thank Karen
18 - Object-Relational Watterson
Mapping in .NETat Apress. I couldn't even think about finishing this book without
her timely
Chapter 19 -expert
Mappedcomments and motivation.
Objects: Performance Second, asand
Considerations always,
Data project
Bindingmanager Tracy Brown Collins did
a great job of managing the entire project so we could finish it within the time constraints. Without a
Chapter 20 - COM Interoperability and ADO.NET
technical reviewer, a book could never be published. Philip Pursglove did a good job of improving the
Chapter 21 - Messaging
technical aspect of the book. Thanks also to Kim Wimpsett, the copy editor, and Kari Brooks, the
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
production manager, for their hard work and for giving the book a professional look.
Appendix A - Relational Databases: Some Basic Concepts
Appendix
-MaheshBChand
- Commonly Used SQL Statements
Appendix C - ADO.NET Frequently Asked Questions
I would like to thank Andy Harris for convincing me to write my first book.
Index
List of Figures
-David Talbot
List of Tables
List of Listings
List of Sidebars
Introduction
Applied ADO.NET: Building Data-Driven Solutions
by Mahesh Chand and David Talbot ISBN:1590590732
Apress 2003developers
This book is for experienced (928 pages) who want to write desktop or Web-based database applications in
This text provides
.NET. This book assumes you have extensive coverage
some prior of ADO.NET
programming technology
knowledge of an object-oriented
including ADO.NET internals, namespaces, classes, and
programming language such as C++, Java, or Visual Basic; some basic concepts of database
interfaces, and takes a comprehensive look at XML
programming; and some experience
namespaces with and
and classes, previous versions
how to of both
integrate Visual Studio (VS). This book also assumes
with
you know the basic concepts of .NET and how to install it.
ADO.NET.
Table of Contents
Applied ADO.NETBuilding Data-Driven Solutions
Introduction
Chapter 1 - ADO.NET Basics
Chapter 2 - Data Components in Visual Studio .NET
Chapter 3 - ADO.NET in Disconnected Environments
Chapter 4 - ADO.NET in Connected Environments
Chapter 5 - Handling ADO.NET Events
Chapter 6 - Integrating XML with ADO.NET
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
Chapter 8 - Constraints and Data Relations
Chapter 9 - ADO.NET Exception Handling
Chapter 10 - Working with the ODBC .NET Data Provider
Chapter 11 - Stored Procedures and Views
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Chapter 13 - Developing a Custom Data Provider
Chapter 14 - Developing Database Web Applications using ASP.NET
Chapter 15 - Using ADO.NET in Xml Web Services
Chapter 16 - ASP.NET Server Controls and Data Binding
Chapter 17 - Building Real-World Web Applications
Chapter 18 - Object-Relational Mapping in .NET
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
Chapter 20 - COM Interoperability and ADO.NET
Chapter 21 - Messaging
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Appendix A - Relational Databases: Some Basic Concepts
Appendix B - Commonly Used SQL Statements
Appendix C - ADO.NET Frequently Asked Questions
Index
List of Figures
List of Tables
List of Listings
List of Sidebars
Applied ADO.NET: Building Data-Driven Solutions
Chapter 6: by
"Integrating XML
Mahesh Chand and David with
Talbot ADO.NET"
ISBN:1590590732
Apress 2003 (928 pages)
This chapter begins
Thiswith
textthe introduction
provides of the
extensive classes
coverage of provided
ADO.NET by the .NET Framework Library to work
technology
with Extensible Markup Language
including ADO.NET(XML) documents.
internals, Thisclasses,
namespaces, chapteranddiscusses how to read from and write to
XML documents interfaces, and takes
using the .NET a comprehensive
Framework look at After
Library classes. XML that it discusses how to navigate
namespaces and classes, and how to integrate both with
through XML documents. The chapter also discusses XML transformations. In addition, this chapter covers
ADO.NET.
the relationship between ADO.NET and XML and shows how to mix them up and use rich ADO.NET
database components to display and manipulate XML data. Finally, this chapter covers the
XPathNavigator
Table of Contents class, which navigates XML documents.
Applied ADO.NETBuilding Data-Driven Solutions
Introduction
Chapter 1 - ADO.NET Basics
Chapter 2 - Data Components in Visual Studio .NET
Chapter 3 - ADO.NET in Disconnected Environments
Chapter 4 - ADO.NET in Connected Environments
Chapter 5 - Handling ADO.NET Events
Chapter 6 - Integrating XML with ADO.NET
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
Chapter 8 - Constraints and Data Relations
Chapter 9 - ADO.NET Exception Handling
Chapter 10 - Working with the ODBC .NET Data Provider
Chapter 11 - Stored Procedures and Views
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Chapter 13 - Developing a Custom Data Provider
Chapter 14 - Developing Database Web Applications using ASP.NET
Chapter 15 - Using ADO.NET in Xml Web Services
Chapter 16 - ASP.NET Server Controls and Data Binding
Chapter 17 - Building Real-World Web Applications
Chapter 18 - Object-Relational Mapping in .NET
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
Chapter 20 - COM Interoperability and ADO.NET
Chapter 21 - Messaging
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Appendix A - Relational Databases: Some Basic Concepts
Appendix B - Commonly Used SQL Statements
Appendix C - ADO.NET Frequently Asked Questions
Index
List of Figures
List of Tables
List of Listings
List of Sidebars
Applied ADO.NET: Building Data-Driven Solutions
Chapter 7: by
"Data
MaheshBinding
Chand and DavidandTalbot
Windows Forms Data-Bound
ISBN:1590590732
Apress 2003 (928 pages)
Controls" This text provides extensive coverage of ADO.NET technology
including ADO.NET internals, namespaces, classes, and
Data-bound controls are not only ease to use, but they also provide many built-in features that
interfaces, and takes a comprehensive look at XML
programmers willnamespaces
find useful. and
Thisclasses,
chapteranddiscusses the basics
how to integrate of data
both with binding and data-bound controls,
as well as how toADO.NET.
develop interactive Graphical User Interface (GUI) database applications using these
controls in minimal time and with minimal effort. This chapter covers how to use Windows controls such as
theTextBox,Button,Label,CheckBox,ComboBox,ListBox, and DataGrid controls in the data-
Table of Contents
binding process and how to write your custom data-bound applications to navigate through the records of
Applied
a data ADO.NETBuilding Data-Driven
source. In this chapter, Solutions
you'll learn some data-binding techniques that are hard to find in other
Introduction
ADO.NET books.
Chapter 1 - ADO.NET Basics
Chapter 2 - Data Components in Visual Studio .NET
Chapter 3 - ADO.NET in Disconnected Environments
Chapter 4 - ADO.NET in Connected Environments
Chapter 5 - Handling ADO.NET Events
Chapter 6 - Integrating XML with ADO.NET
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
Chapter 8 - Constraints and Data Relations
Chapter 9 - ADO.NET Exception Handling
Chapter 10 - Working with the ODBC .NET Data Provider
Chapter 11 - Stored Procedures and Views
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Chapter 13 - Developing a Custom Data Provider
Chapter 14 - Developing Database Web Applications using ASP.NET
Chapter 15 - Using ADO.NET in Xml Web Services
Chapter 16 - ASP.NET Server Controls and Data Binding
Chapter 17 - Building Real-World Web Applications
Chapter 18 - Object-Relational Mapping in .NET
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
Chapter 20 - COM Interoperability and ADO.NET
Chapter 21 - Messaging
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Appendix A - Relational Databases: Some Basic Concepts
Appendix B - Commonly Used SQL Statements
Appendix C - ADO.NET Frequently Asked Questions
Index
List of Figures
List of Tables
List of Listings
List of Sidebars
Applied ADO.NET: Building Data-Driven Solutions
Chapter 8: by
"Constraints
Mahesh Chand andand
David Data
Talbot Relations"
ISBN:1590590732
Apress 2003 (928 pages)
This chapter discusses constraints
This text and data coverage
provides extensive relations of
in ADO.NET
detail. First, this chapter starts with a discussion of
technology
constraints and how ADO.NET
including constraint
ADO.NET objects
internals, maintainclasses,
namespaces, data integrity.
and The second part of this chapter
interfaces, and takes a comprehensive look at XML
discusses data relations.
namespaces and classes, and how to integrate both with
ADO.NET.
Table of Contents
Applied ADO.NETBuilding Data-Driven Solutions
Introduction
Chapter 1 - ADO.NET Basics
Chapter 2 - Data Components in Visual Studio .NET
Chapter 3 - ADO.NET in Disconnected Environments
Chapter 4 - ADO.NET in Connected Environments
Chapter 5 - Handling ADO.NET Events
Chapter 6 - Integrating XML with ADO.NET
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
Chapter 8 - Constraints and Data Relations
Chapter 9 - ADO.NET Exception Handling
Chapter 10 - Working with the ODBC .NET Data Provider
Chapter 11 - Stored Procedures and Views
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Chapter 13 - Developing a Custom Data Provider
Chapter 14 - Developing Database Web Applications using ASP.NET
Chapter 15 - Using ADO.NET in Xml Web Services
Chapter 16 - ASP.NET Server Controls and Data Binding
Chapter 17 - Building Real-World Web Applications
Chapter 18 - Object-Relational Mapping in .NET
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
Chapter 20 - COM Interoperability and ADO.NET
Chapter 21 - Messaging
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Appendix A - Relational Databases: Some Basic Concepts
Appendix B - Commonly Used SQL Statements
Appendix C - ADO.NET Frequently Asked Questions
Index
List of Figures
List of Tables
List of Listings
List of Sidebars
Applied ADO.NET: Building Data-Driven Solutions
Chapter 9: by
"ADO.NET
Mahesh Chand Exception
and David Talbot Handling"
ISBN:1590590732
Apress 2003 (928 pages)
Exception and errorThishandling is oneextensive
text provides of the most important
coverage parts oftechnology
of ADO.NET writing reliable and error-prone
applications. If you come from
including a C++
ADO.NET background,
internals, you're probably
namespaces, familiar with different exceptional
classes, and
handling methodsinterfaces, and takes
such as C++ a comprehensive
exceptional look at XMLexceptional handling, and Microsoft
handling, structured
namespaces and classes, and how to integrate both with
Foundation Classes (MFC) exceptions. If you come from a Visual Basic background, you're probably
ADO.NET.
familiar with the On Error statement. Besides the exception handling in previous versions of VC++ and
Visual Basic, .NET implements exceptions in a different way, and all .NET-supported languages (C# and
VB .NET)
Table share the same mechanism. Now Visual Basic developers can enjoy the same rich exception
of Contents
handling
Applied C++ developersData-Driven
ADO.NETBuilding have enjoyed. Discussing .NET exception handling is beyond the scope of this
Solutions
book; this chapter concentrates on ADO.NET exception handling classes.
Introduction
Chapter 1 - ADO.NET Basics
Chapter 2 - Data Components in Visual Studio .NET
Chapter 3 - ADO.NET in Disconnected Environments
Chapter 4 - ADO.NET in Connected Environments
Chapter 5 - Handling ADO.NET Events
Chapter 6 - Integrating XML with ADO.NET
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
Chapter 8 - Constraints and Data Relations
Chapter 9 - ADO.NET Exception Handling
Chapter 10 - Working with the ODBC .NET Data Provider
Chapter 11 - Stored Procedures and Views
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Chapter 13 - Developing a Custom Data Provider
Chapter 14 - Developing Database Web Applications using ASP.NET
Chapter 15 - Using ADO.NET in Xml Web Services
Chapter 16 - ASP.NET Server Controls and Data Binding
Chapter 17 - Building Real-World Web Applications
Chapter 18 - Object-Relational Mapping in .NET
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
Chapter 20 - COM Interoperability and ADO.NET
Chapter 21 - Messaging
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Appendix A - Relational Databases: Some Basic Concepts
Appendix B - Commonly Used SQL Statements
Appendix C - ADO.NET Frequently Asked Questions
Index
List of Figures
List of Tables
List of Listings
List of Sidebars
Applied ADO.NET: Building Data-Driven Solutions
Chapter 10:by"Working with
Mahesh Chand and the
David ODBC .NET
Talbot Data Provider"
ISBN:1590590732
Apress 2003 (928 pages)
This chapter discusses theprovides
This text ODBC extensive
.NET datacoverage
providerofand how totechnology
ADO.NET work with various data sources such as
Access, MySQL, including
Excel, and text using
ADO.NET the ODBC
internals, data provider.
namespaces, classes, and
interfaces, and takes a comprehensive look at XML
namespaces and classes, and how to integrate both with
ADO.NET.
Table of Contents
Applied ADO.NETBuilding Data-Driven Solutions
Introduction
Chapter 1 - ADO.NET Basics
Chapter 2 - Data Components in Visual Studio .NET
Chapter 3 - ADO.NET in Disconnected Environments
Chapter 4 - ADO.NET in Connected Environments
Chapter 5 - Handling ADO.NET Events
Chapter 6 - Integrating XML with ADO.NET
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
Chapter 8 - Constraints and Data Relations
Chapter 9 - ADO.NET Exception Handling
Chapter 10 - Working with the ODBC .NET Data Provider
Chapter 11 - Stored Procedures and Views
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Chapter 13 - Developing a Custom Data Provider
Chapter 14 - Developing Database Web Applications using ASP.NET
Chapter 15 - Using ADO.NET in Xml Web Services
Chapter 16 - ASP.NET Server Controls and Data Binding
Chapter 17 - Building Real-World Web Applications
Chapter 18 - Object-Relational Mapping in .NET
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
Chapter 20 - COM Interoperability and ADO.NET
Chapter 21 - Messaging
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Appendix A - Relational Databases: Some Basic Concepts
Appendix B - Commonly Used SQL Statements
Appendix C - ADO.NET Frequently Asked Questions
Index
List of Figures
List of Tables
List of Listings
List of Sidebars
Applied ADO.NET: Building Data-Driven Solutions
Chapter 11:by"Stored Procedures
Mahesh Chand and David Talbot and Views"
ISBN:1590590732
Apress 2003 (928 pages)
Stored procedures and
This views
text are another
provides extensiveimportant
coverageaspect of database
of ADO.NET programming. This chapter
technology
discusses how you can take
including advantage
ADO.NET of VSnamespaces,
internals, .NET tools to work with
classes, and these objects.
interfaces, and takes a comprehensive look at XML
namespaces and classes, and how to integrate both with
ADO.NET.
Table of Contents
Applied ADO.NETBuilding Data-Driven Solutions
Introduction
Chapter 1 - ADO.NET Basics
Chapter 2 - Data Components in Visual Studio .NET
Chapter 3 - ADO.NET in Disconnected Environments
Chapter 4 - ADO.NET in Connected Environments
Chapter 5 - Handling ADO.NET Events
Chapter 6 - Integrating XML with ADO.NET
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
Chapter 8 - Constraints and Data Relations
Chapter 9 - ADO.NET Exception Handling
Chapter 10 - Working with the ODBC .NET Data Provider
Chapter 11 - Stored Procedures and Views
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Chapter 13 - Developing a Custom Data Provider
Chapter 14 - Developing Database Web Applications using ASP.NET
Chapter 15 - Using ADO.NET in Xml Web Services
Chapter 16 - ASP.NET Server Controls and Data Binding
Chapter 17 - Building Real-World Web Applications
Chapter 18 - Object-Relational Mapping in .NET
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
Chapter 20 - COM Interoperability and ADO.NET
Chapter 21 - Messaging
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Appendix A - Relational Databases: Some Basic Concepts
Appendix B - Commonly Used SQL Statements
Appendix C - ADO.NET Frequently Asked Questions
Index
List of Figures
List of Tables
List of Listings
List of Sidebars
Applied ADO.NET: Building Data-Driven Solutions
Chapter 12:by"Oracle, SQLXML,
Mahesh Chand and OtherISBN:1590590732
and David Talbot .NET Data Providers"
Apress 2003 (928 pages)
In this chapter, you'll
This see
text some more
provides data providersspecifically,
extensive Oracle and SQLXML. In previous
coverage of ADO.NET technology
chapters, you learned howADO.NET
including to work with other namespaces,
internals, data providers, so working
classes, and with the rest of them is just a
piece of cake. Allinterfaces, and takes
data providers a comprehensive
implement look at
a similar class XML
hierarchy model with only a few changes. This
namespaces and classes, and how to integrate both with
chapter concentrates how to work with Oracle databases and how to access SQL Server using SQLXML.
ADO.NET.
Table of Contents
Applied ADO.NETBuilding Data-Driven Solutions
Introduction
Chapter 1 - ADO.NET Basics
Chapter 2 - Data Components in Visual Studio .NET
Chapter 3 - ADO.NET in Disconnected Environments
Chapter 4 - ADO.NET in Connected Environments
Chapter 5 - Handling ADO.NET Events
Chapter 6 - Integrating XML with ADO.NET
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
Chapter 8 - Constraints and Data Relations
Chapter 9 - ADO.NET Exception Handling
Chapter 10 - Working with the ODBC .NET Data Provider
Chapter 11 - Stored Procedures and Views
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Chapter 13 - Developing a Custom Data Provider
Chapter 14 - Developing Database Web Applications using ASP.NET
Chapter 15 - Using ADO.NET in Xml Web Services
Chapter 16 - ASP.NET Server Controls and Data Binding
Chapter 17 - Building Real-World Web Applications
Chapter 18 - Object-Relational Mapping in .NET
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
Chapter 20 - COM Interoperability and ADO.NET
Chapter 21 - Messaging
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Appendix A - Relational Databases: Some Basic Concepts
Appendix B - Commonly Used SQL Statements
Appendix C - ADO.NET Frequently Asked Questions
Index
List of Figures
List of Tables
List of Listings
List of Sidebars
Applied ADO.NET: Building Data-Driven Solutions
Chapter 13:by"Developing a Custom
Mahesh Chand and David Talbot Data ISBN:1590590732
Provider"
Apress 2003 (928 pages)
ADO.NET is an extensible architecture
This text provides that allows
extensive anyone,
coverage not just
of ADO.NET Microsoft, to create data providers for
technology
virtually any type including
of data source.
ADO.NET This chapternamespaces,
internals, covers how classes,
to createand
a data provider for pipe-delimited data
interfaces,
files, which is a common fileand takesespecially
format, a comprehensive
for Unixlook at XMLThis data provider plugs in to the
systems.
namespaces and classes, and how to integrate both with
ADO.NET architecture and provides all of the things you would expect from a data provider, including the
ADO.NET.
ability to fill a DataSet and bind it to any GUI object.
Table of Contents
Applied ADO.NETBuilding Data-Driven Solutions
Introduction
Chapter 1 - ADO.NET Basics
Chapter 2 - Data Components in Visual Studio .NET
Chapter 3 - ADO.NET in Disconnected Environments
Chapter 4 - ADO.NET in Connected Environments
Chapter 5 - Handling ADO.NET Events
Chapter 6 - Integrating XML with ADO.NET
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
Chapter 8 - Constraints and Data Relations
Chapter 9 - ADO.NET Exception Handling
Chapter 10 - Working with the ODBC .NET Data Provider
Chapter 11 - Stored Procedures and Views
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Chapter 13 - Developing a Custom Data Provider
Chapter 14 - Developing Database Web Applications using ASP.NET
Chapter 15 - Using ADO.NET in Xml Web Services
Chapter 16 - ASP.NET Server Controls and Data Binding
Chapter 17 - Building Real-World Web Applications
Chapter 18 - Object-Relational Mapping in .NET
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
Chapter 20 - COM Interoperability and ADO.NET
Chapter 21 - Messaging
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Appendix A - Relational Databases: Some Basic Concepts
Appendix B - Commonly Used SQL Statements
Appendix C - ADO.NET Frequently Asked Questions
Index
List of Figures
List of Tables
List of Listings
List of Sidebars
Applied ADO.NET: Building Data-Driven Solutions
Chapter 14:by"Developing Database
Mahesh Chand and David Talbot Applications Using ASP.NET"
ISBN:1590590732
Apress 2003 (928 pages)
As the programming This world moves extensive
text provides toward thecoverage
Internet of
these days,technology
ADO.NET it's becoming important for developers
to be able to create Web applications
including and Web
ADO.NET internals, services. The
namespaces, Microsoft
classes, and .NET Framework enables you to
develop, maintain, interfaces,
and deploy andreliable
takes a and
comprehensive look at XML
high-performance Web applications and Web services. This
namespaces and classes, and how to integrate both with
chapter starts with an overview of ASP.NET and how to install it, and it then shows how to develop a
ADO.NET.
simple Web application using VS .NET. Finally, it discusses Web Forms controls and how to use them.
The Web Form's DataGrid control is a useful control to develop Web-based database applications. You
can of
Table bind a DataSet to the DataGrid control as you did for the Windows Form's DataGrid control. This
Contents
chapter discusses how toData-Driven
Applied ADO.NETBuilding fill data to aSolutions
DataGrid and how to develop powerful Web-based database
applications
Introduction using the DataGrid control. It also discusses how to enable paging in a DataGrid control.
Finally,1it shows
Chapter you how
- ADO.NET to develop an ASP.NET guest book for your Web site using ASP.NET.
Basics
Chapter 2 - Data Components in Visual Studio .NET
Chapter 3 - ADO.NET in Disconnected Environments
Chapter 4 - ADO.NET in Connected Environments
Chapter 5 - Handling ADO.NET Events
Chapter 6 - Integrating XML with ADO.NET
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
Chapter 8 - Constraints and Data Relations
Chapter 9 - ADO.NET Exception Handling
Chapter 10 - Working with the ODBC .NET Data Provider
Chapter 11 - Stored Procedures and Views
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Chapter 13 - Developing a Custom Data Provider
Chapter 14 - Developing Database Web Applications using ASP.NET
Chapter 15 - Using ADO.NET in Xml Web Services
Chapter 16 - ASP.NET Server Controls and Data Binding
Chapter 17 - Building Real-World Web Applications
Chapter 18 - Object-Relational Mapping in .NET
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
Chapter 20 - COM Interoperability and ADO.NET
Chapter 21 - Messaging
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Appendix A - Relational Databases: Some Basic Concepts
Appendix B - Commonly Used SQL Statements
Appendix C - ADO.NET Frequently Asked Questions
Index
List of Figures
List of Tables
List of Listings
List of Sidebars
Applied ADO.NET: Building Data-Driven Solutions
Chapter 15:by"Using ADO.NET
Mahesh Chand in XML Web
and David Talbot Services"
ISBN:1590590732
Apress 2003 (928 pages)
Web services provide a way
This text to run extensive
provides a service coverage
on the Web and access
of ADO.NET its methods using standard protocols,
technology
including Simple including
Object Access
ADO.NET Protocol (SOAP),
internals, XML, Web
namespaces, Service
classes, and Description Language (WSDL), and
Hypertext Transfer interfaces,
Protocoland takes Technically,
(HTTP). a comprehensive look
a Web at XMLis nothing more than an application that
service
namespaces and classes, and how to integrate both with
exposes its interface over the Web to a client who wants to access the service's abilities. The uses of a
ADO.NET.
Web service include validating credit cards, searching for data in a database, inserting an order into a
shopping cart, and updating a guest list. The sky is the limit on what you can have your Web service do. In
the past,
Table JavaBeans, Component Object Model (COM) components, and other, nonstandard service
of Contents
components
Applied handled these
ADO.NETBuilding services, Solutions
Data-Driven which required specialized formats or extra, specialized components
to exchange data with the client. But Web services under .NET run by invoking methods in the service
Introduction
directly1through
Chapter HTTPBasics
- ADO.NET or SOAP, so someone wanting to run your Web service from their computer can
simply send an HTTP call
Chapter 2 - Data Components to your service,
in Visual passing
Studio .NET the parameters in a standard Uniform Resource
Locator (URL). This chapter shows you
Chapter 3 - ADO.NET in Disconnected Environments
how to use ADO.NET in XML Web services.
Chapter 4 - ADO.NET in Connected Environments
Chapter 5 - Handling ADO.NET Events
Chapter 6 - Integrating XML with ADO.NET
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
Chapter 8 - Constraints and Data Relations
Chapter 9 - ADO.NET Exception Handling
Chapter 10 - Working with the ODBC .NET Data Provider
Chapter 11 - Stored Procedures and Views
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Chapter 13 - Developing a Custom Data Provider
Chapter 14 - Developing Database Web Applications using ASP.NET
Chapter 15 - Using ADO.NET in Xml Web Services
Chapter 16 - ASP.NET Server Controls and Data Binding
Chapter 17 - Building Real-World Web Applications
Chapter 18 - Object-Relational Mapping in .NET
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
Chapter 20 - COM Interoperability and ADO.NET
Chapter 21 - Messaging
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Appendix A - Relational Databases: Some Basic Concepts
Appendix B - Commonly Used SQL Statements
Appendix C - ADO.NET Frequently Asked Questions
Index
List of Figures
List of Tables
List of Listings
List of Sidebars
Applied ADO.NET: Building Data-Driven Solutions
Chapter 16:by"ASP.NET Server
Mahesh Chand and Controls and
David Talbot Data Binding"
ISBN:1590590732
Apress 2003 (928 pages)
Chapter 14 discussed some
This text of theextensive
provides basics of coverage
data binding in Web Forms
of ADO.NET and ASP.NET data-bound
technology
controls. You alsoincluding
saw how to use data-bound
ADO.NET controls in classes,
internals, namespaces, Web applications.
and Chapter 15 discussed how to
interfaces,
develop data-driven and takes
Web services anda how
comprehensive lookfunctionality
to access the at XML implemented in a Web service from
namespaces and classes, and how to integrate both with
Web Forms applications. This chapter extends the information in Chapter 14 and concentrates on the
ADO.NET.
more practical aspect of data binding and Web Forms data-bound controls.
Table of Contents
Applied ADO.NETBuilding Data-Driven Solutions
Introduction
Chapter 1 - ADO.NET Basics
Chapter 2 - Data Components in Visual Studio .NET
Chapter 3 - ADO.NET in Disconnected Environments
Chapter 4 - ADO.NET in Connected Environments
Chapter 5 - Handling ADO.NET Events
Chapter 6 - Integrating XML with ADO.NET
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
Chapter 8 - Constraints and Data Relations
Chapter 9 - ADO.NET Exception Handling
Chapter 10 - Working with the ODBC .NET Data Provider
Chapter 11 - Stored Procedures and Views
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Chapter 13 - Developing a Custom Data Provider
Chapter 14 - Developing Database Web Applications using ASP.NET
Chapter 15 - Using ADO.NET in Xml Web Services
Chapter 16 - ASP.NET Server Controls and Data Binding
Chapter 17 - Building Real-World Web Applications
Chapter 18 - Object-Relational Mapping in .NET
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
Chapter 20 - COM Interoperability and ADO.NET
Chapter 21 - Messaging
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Appendix A - Relational Databases: Some Basic Concepts
Appendix B - Commonly Used SQL Statements
Appendix C - ADO.NET Frequently Asked Questions
Index
List of Figures
List of Tables
List of Listings
List of Sidebars
Applied ADO.NET: Building Data-Driven Solutions
Chapter 17:by"Building
Mahesh Chand Real-World
and David Talbot Web Applications"
ISBN:1590590732
Apress 2003 (928 pages)
Chapter 14 discussed the provides
This text basics ofextensive
ASP.NET and how
coverage ofto write data-driven
ADO.NET technologyWeb applications using
ASP.NET and ADO.NET. Chapter 16
including ADO.NET discussed
internals, data binding
namespaces, in ASP.NET
classes, and and ASP.NET server controls
interfaces,
and how to use these andtotakes
controls a comprehensive
develop look at
data-bound Web XML
applications. This chapter uses the functionality
namespaces and classes, and how to integrate both with
discussed in those chapters. You'll see how you can write a real-world online job board where candidates
ADO.NET.
can post their resumes, recruiters can post their jobs, recruiters can browse the available resumes, and
job hunters can browse and apply for the available jobs online.
Table of Contents
Applied ADO.NETBuilding Data-Driven Solutions
Introduction
Chapter 1 - ADO.NET Basics
Chapter 2 - Data Components in Visual Studio .NET
Chapter 3 - ADO.NET in Disconnected Environments
Chapter 4 - ADO.NET in Connected Environments
Chapter 5 - Handling ADO.NET Events
Chapter 6 - Integrating XML with ADO.NET
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
Chapter 8 - Constraints and Data Relations
Chapter 9 - ADO.NET Exception Handling
Chapter 10 - Working with the ODBC .NET Data Provider
Chapter 11 - Stored Procedures and Views
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Chapter 13 - Developing a Custom Data Provider
Chapter 14 - Developing Database Web Applications using ASP.NET
Chapter 15 - Using ADO.NET in Xml Web Services
Chapter 16 - ASP.NET Server Controls and Data Binding
Chapter 17 - Building Real-World Web Applications
Chapter 18 - Object-Relational Mapping in .NET
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
Chapter 20 - COM Interoperability and ADO.NET
Chapter 21 - Messaging
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Appendix A - Relational Databases: Some Basic Concepts
Appendix B - Commonly Used SQL Statements
Appendix C - ADO.NET Frequently Asked Questions
Index
List of Figures
List of Tables
List of Listings
List of Sidebars
Applied ADO.NET: Building Data-Driven Solutions
Chapter 18:by"Object-Relational Mapping ISBN:1590590732
Mahesh Chand and David Talbot in .NET"
Apress 2003 (928 pages)
Object-relational This
mapping is a commonly
text provides desired
extensive software
coverage architecture
of ADO.NET element on any platform because
technology
of the encapsulation and modeling
including ADO.NET of data behavior
internals, from aclasses,
namespaces, relational
anddatabase into an object. Although
you can use XMLinterfaces, and takes a(XSD)
Schema Document comprehensive look at
files to create XML from data, these objects are not easily
objects
namespaces and classes, and how to integrate both with
extensible in regard to modeling data behavior. The technique discussed in this chapter extends the
ADO.NET.
concept provided by Duwamish7 (a demo application from Microsoft) to create custom-built mapped
objects.
Table of Contents
Applied ADO.NETBuilding Data-Driven Solutions
Introduction
Chapter 1 - ADO.NET Basics
Chapter 2 - Data Components in Visual Studio .NET
Chapter 3 - ADO.NET in Disconnected Environments
Chapter 4 - ADO.NET in Connected Environments
Chapter 5 - Handling ADO.NET Events
Chapter 6 - Integrating XML with ADO.NET
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
Chapter 8 - Constraints and Data Relations
Chapter 9 - ADO.NET Exception Handling
Chapter 10 - Working with the ODBC .NET Data Provider
Chapter 11 - Stored Procedures and Views
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Chapter 13 - Developing a Custom Data Provider
Chapter 14 - Developing Database Web Applications using ASP.NET
Chapter 15 - Using ADO.NET in Xml Web Services
Chapter 16 - ASP.NET Server Controls and Data Binding
Chapter 17 - Building Real-World Web Applications
Chapter 18 - Object-Relational Mapping in .NET
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
Chapter 20 - COM Interoperability and ADO.NET
Chapter 21 - Messaging
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Appendix A - Relational Databases: Some Basic Concepts
Appendix B - Commonly Used SQL Statements
Appendix C - ADO.NET Frequently Asked Questions
Index
List of Figures
List of Tables
List of Listings
List of Sidebars
Applied ADO.NET: Building Data-Driven Solutions
Chapter 19:by"Mapped
Mahesh ChandObjects: Performance
and David Talbot Considerations and
ISBN:1590590732
Apress 2003 (928 pages)
Data Binding"
This text provides extensive coverage of ADO.NET technology
including ADO.NET internals, namespaces, classes, and
Building on the object-relational concepts discussed in Chapter 18, this chapter deals with the common
interfaces, and takes a comprehensive look at XML
problems encountered in a mapped
namespaces system,
and classes, andincluding performance
how to integrate considerations and how to use data
both with
binding. Data binding is the preferred way to work with data in .NET, but you'll need to alter your code
ADO.NET.
slightly when using mapped objects. In addition, performance is always a consideration in creating a
scalable system, but often many of the things that improve performance can lead to an unmaintainable
Table of Contents
system design. In the performance part of the chapter, it discusses common performance problems such
Applied ADO.NETBuilding
as managing Data-Driven
large tree structures Solutions
and balancing the ease of use that lazy loading can provide vs.
Introduction
reducing round trips to the database.
Chapter 1 - ADO.NET Basics
Chapter 2 - Data Components in Visual Studio .NET
Chapter 3 - ADO.NET in Disconnected Environments
Chapter 4 - ADO.NET in Connected Environments
Chapter 5 - Handling ADO.NET Events
Chapter 6 - Integrating XML with ADO.NET
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
Chapter 8 - Constraints and Data Relations
Chapter 9 - ADO.NET Exception Handling
Chapter 10 - Working with the ODBC .NET Data Provider
Chapter 11 - Stored Procedures and Views
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Chapter 13 - Developing a Custom Data Provider
Chapter 14 - Developing Database Web Applications using ASP.NET
Chapter 15 - Using ADO.NET in Xml Web Services
Chapter 16 - ASP.NET Server Controls and Data Binding
Chapter 17 - Building Real-World Web Applications
Chapter 18 - Object-Relational Mapping in .NET
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
Chapter 20 - COM Interoperability and ADO.NET
Chapter 21 - Messaging
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Appendix A - Relational Databases: Some Basic Concepts
Appendix B - Commonly Used SQL Statements
Appendix C - ADO.NET Frequently Asked Questions
Index
List of Figures
List of Tables
List of Listings
List of Sidebars
Applied ADO.NET: Building Data-Driven Solutions
Chapter 20:by"COM Interoperability
Mahesh Chand and David Talbot with ADO.NET"
ISBN:1590590732
Apress 2003 (928 pages)
COM has been around forprovides
This text many years and iscoverage
extensive used byofmany Windows
ADO.NET applications. Eventually .NET
technology
platform will replace COM,ADO.NET
including but until internals,
then you namespaces,
may need to classes,
developand
COM components from .NET and
access them frominterfaces,
unmanaged and code,
takes aorcomprehensive
you may wantlook at XML
to use COM components in .NET applications.
namespaces and classes, and how to integrate both with
COM interoperability (also referred to as COM Interop) enables you to use existing COM components in
ADO.NET.
.NET applications or use .NET components in unmanaged code. This chapter shows you how to use ADO
and other COM-based data access technologies through COM Interop in your .NET applications.
Table of Contents
Applied ADO.NETBuilding Data-Driven Solutions
Introduction
Chapter 1 - ADO.NET Basics
Chapter 2 - Data Components in Visual Studio .NET
Chapter 3 - ADO.NET in Disconnected Environments
Chapter 4 - ADO.NET in Connected Environments
Chapter 5 - Handling ADO.NET Events
Chapter 6 - Integrating XML with ADO.NET
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
Chapter 8 - Constraints and Data Relations
Chapter 9 - ADO.NET Exception Handling
Chapter 10 - Working with the ODBC .NET Data Provider
Chapter 11 - Stored Procedures and Views
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Chapter 13 - Developing a Custom Data Provider
Chapter 14 - Developing Database Web Applications using ASP.NET
Chapter 15 - Using ADO.NET in Xml Web Services
Chapter 16 - ASP.NET Server Controls and Data Binding
Chapter 17 - Building Real-World Web Applications
Chapter 18 - Object-Relational Mapping in .NET
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
Chapter 20 - COM Interoperability and ADO.NET
Chapter 21 - Messaging
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Appendix A - Relational Databases: Some Basic Concepts
Appendix B - Commonly Used SQL Statements
Appendix C - ADO.NET Frequently Asked Questions
Index
List of Figures
List of Tables
List of Listings
List of Sidebars
Applied ADO.NET: Building Data-Driven Solutions
Chapter 21:by"Messaging"
Mahesh Chand and David Talbot ISBN:1590590732
Apress 2003 (928 pages)
A messaging service
This is one
text of the most
provides effective
extensive and popular
coverage mediums
of ADO.NET to communicate between two
technology
machines. It doesn't matterADO.NET
including if you'reinternals,
a high-tech developer,classes,
namespaces, a stockbroker,
and a high-school student, or a
businessperson. interfaces, and takes
In some means, youaprobably
comprehensive look at XML
use messaging services. Some of the common messaging
namespaces and classes, and how to integrate both with
services are electronic mail (email), instant messenger services, text messaging via phones, or messaging
ADO.NET.
used in complex distributed applications. This chapter covers messaging and its related functionality
defined in the .NET Framework Class Library, as well as how to use it in your applications.
Table of Contents
Applied ADO.NETBuilding Data-Driven Solutions
Introduction
Chapter 1 - ADO.NET Basics
Chapter 2 - Data Components in Visual Studio .NET
Chapter 3 - ADO.NET in Disconnected Environments
Chapter 4 - ADO.NET in Connected Environments
Chapter 5 - Handling ADO.NET Events
Chapter 6 - Integrating XML with ADO.NET
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
Chapter 8 - Constraints and Data Relations
Chapter 9 - ADO.NET Exception Handling
Chapter 10 - Working with the ODBC .NET Data Provider
Chapter 11 - Stored Procedures and Views
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Chapter 13 - Developing a Custom Data Provider
Chapter 14 - Developing Database Web Applications using ASP.NET
Chapter 15 - Using ADO.NET in Xml Web Services
Chapter 16 - ASP.NET Server Controls and Data Binding
Chapter 17 - Building Real-World Web Applications
Chapter 18 - Object-Relational Mapping in .NET
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
Chapter 20 - COM Interoperability and ADO.NET
Chapter 21 - Messaging
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Appendix A - Relational Databases: Some Basic Concepts
Appendix B - Commonly Used SQL Statements
Appendix C - ADO.NET Frequently Asked Questions
Index
List of Figures
List of Tables
List of Listings
List of Sidebars
Applied ADO.NET: Building Data-Driven Solutions
Chapter 22:by"SQL Server
Mahesh Chand andTalbot
and David ADO.NET: ISBN:1590590732
Notes on Performance"
Apress 2003 (928 pages)
Database performance has
This text alwaysextensive
provides been something
coverageofofaADO.NET
black arttechnology
consisting largely of obscure tricks.
Although there's no single ADO.NET
including trick that internals,
will makenamespaces,
your application scale,
classes, andthere are several tricks that can help
interfaces,
you identify and address and takes aproblems.
performance comprehensive look at XML
This chapter covers those tricks. It also discusses some
namespaces and classes, and how to integrate both with
best practices to make sure you get most out of your code.
ADO.NET.
Table of Contents
Applied ADO.NETBuilding Data-Driven Solutions
Introduction
Chapter 1 - ADO.NET Basics
Chapter 2 - Data Components in Visual Studio .NET
Chapter 3 - ADO.NET in Disconnected Environments
Chapter 4 - ADO.NET in Connected Environments
Chapter 5 - Handling ADO.NET Events
Chapter 6 - Integrating XML with ADO.NET
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
Chapter 8 - Constraints and Data Relations
Chapter 9 - ADO.NET Exception Handling
Chapter 10 - Working with the ODBC .NET Data Provider
Chapter 11 - Stored Procedures and Views
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Chapter 13 - Developing a Custom Data Provider
Chapter 14 - Developing Database Web Applications using ASP.NET
Chapter 15 - Using ADO.NET in Xml Web Services
Chapter 16 - ASP.NET Server Controls and Data Binding
Chapter 17 - Building Real-World Web Applications
Chapter 18 - Object-Relational Mapping in .NET
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
Chapter 20 - COM Interoperability and ADO.NET
Chapter 21 - Messaging
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Appendix A - Relational Databases: Some Basic Concepts
Appendix B - Commonly Used SQL Statements
Appendix C - ADO.NET Frequently Asked Questions
Index
List of Figures
List of Tables
List of Listings
List of Sidebars
Applied ADO.NET: Building Data-Driven Solutions
Appendix A:
by "Relational
Mahesh Chand andDatabases:Some
David Talbot Basic Concepts"
ISBN:1590590732
Apress 2003 (928 pages)
Appendix A covers some
This text of the basics
provides of databases,
extensive coverage such as locking,
of ADO.NET cursors, and normalization.
technology
including ADO.NET internals, namespaces, classes, and
interfaces, and takes a comprehensive look at XML
namespaces and classes, and how to integrate both with
ADO.NET.
Table of Contents
Applied ADO.NETBuilding Data-Driven Solutions
Introduction
Chapter 1 - ADO.NET Basics
Chapter 2 - Data Components in Visual Studio .NET
Chapter 3 - ADO.NET in Disconnected Environments
Chapter 4 - ADO.NET in Connected Environments
Chapter 5 - Handling ADO.NET Events
Chapter 6 - Integrating XML with ADO.NET
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
Chapter 8 - Constraints and Data Relations
Chapter 9 - ADO.NET Exception Handling
Chapter 10 - Working with the ODBC .NET Data Provider
Chapter 11 - Stored Procedures and Views
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Chapter 13 - Developing a Custom Data Provider
Chapter 14 - Developing Database Web Applications using ASP.NET
Chapter 15 - Using ADO.NET in Xml Web Services
Chapter 16 - ASP.NET Server Controls and Data Binding
Chapter 17 - Building Real-World Web Applications
Chapter 18 - Object-Relational Mapping in .NET
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
Chapter 20 - COM Interoperability and ADO.NET
Chapter 21 - Messaging
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Appendix A - Relational Databases: Some Basic Concepts
Appendix B - Commonly Used SQL Statements
Appendix C - ADO.NET Frequently Asked Questions
Index
List of Figures
List of Tables
List of Listings
List of Sidebars
Applied ADO.NET: Building Data-Driven Solutions
Appendix B: "Commonly
by Mahesh Used
Chand and David SQL Statements"
Talbot ISBN:1590590732
Apress 2003 (928 pages)
SQL is a vital partThis
of database programming.
text provides Appendix
extensive coverage of B is a quick
ADO.NET reference to SQL statements and
technology
shows you how toincluding
write various SQLinternals,
ADO.NET statements.
namespaces, classes, and
interfaces, and takes a comprehensive look at XML
namespaces and classes, and how to integrate both with
ADO.NET.
Table of Contents
Applied ADO.NETBuilding Data-Driven Solutions
Introduction
Chapter 1 - ADO.NET Basics
Chapter 2 - Data Components in Visual Studio .NET
Chapter 3 - ADO.NET in Disconnected Environments
Chapter 4 - ADO.NET in Connected Environments
Chapter 5 - Handling ADO.NET Events
Chapter 6 - Integrating XML with ADO.NET
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
Chapter 8 - Constraints and Data Relations
Chapter 9 - ADO.NET Exception Handling
Chapter 10 - Working with the ODBC .NET Data Provider
Chapter 11 - Stored Procedures and Views
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Chapter 13 - Developing a Custom Data Provider
Chapter 14 - Developing Database Web Applications using ASP.NET
Chapter 15 - Using ADO.NET in Xml Web Services
Chapter 16 - ASP.NET Server Controls and Data Binding
Chapter 17 - Building Real-World Web Applications
Chapter 18 - Object-Relational Mapping in .NET
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
Chapter 20 - COM Interoperability and ADO.NET
Chapter 21 - Messaging
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Appendix A - Relational Databases: Some Basic Concepts
Appendix B - Commonly Used SQL Statements
Appendix C - ADO.NET Frequently Asked Questions
Index
List of Figures
List of Tables
List of Listings
List of Sidebars
Applied ADO.NET: Building Data-Driven Solutions
Appendix C: "ADO.NET
by Mahesh Frequently
Chand and David Talbot Asked Questions"
ISBN:1590590732
Apress 2003 (928 pages)
This appendix answers some
This text of theextensive
provides commonly asked of
coverage questions
ADO.NETrelated to ADO.NET. Most of these
technology
questions were originally
includingasked on the
ADO.NET discussion
internals, forums at
namespaces, C# Corner
classes, and (www.c-sharpcorner.com) or
interfaces, and takes a comprehensive look at XML
other newsgroups.
namespaces and classes, and how to integrate both with
ADO.NET.
Table of Contents
Applied ADO.NETBuilding Data-Driven Solutions
Introduction
Chapter 1 - ADO.NET Basics
Chapter 2 - Data Components in Visual Studio .NET
Chapter 3 - ADO.NET in Disconnected Environments
Chapter 4 - ADO.NET in Connected Environments
Chapter 5 - Handling ADO.NET Events
Chapter 6 - Integrating XML with ADO.NET
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
Chapter 8 - Constraints and Data Relations
Chapter 9 - ADO.NET Exception Handling
Chapter 10 - Working with the ODBC .NET Data Provider
Chapter 11 - Stored Procedures and Views
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Chapter 13 - Developing a Custom Data Provider
Chapter 14 - Developing Database Web Applications using ASP.NET
Chapter 15 - Using ADO.NET in Xml Web Services
Chapter 16 - ASP.NET Server Controls and Data Binding
Chapter 17 - Building Real-World Web Applications
Chapter 18 - Object-Relational Mapping in .NET
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
Chapter 20 - COM Interoperability and ADO.NET
Chapter 21 - Messaging
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Appendix A - Relational Databases: Some Basic Concepts
Appendix B - Commonly Used SQL Statements
Appendix C - ADO.NET Frequently Asked Questions
Index
List of Figures
List of Tables
List of Listings
List of Sidebars
Chapter Applied
1: ADO.NET Basics
ADO.NET: Building Data-Driven Solutions
by Mahesh Chand and David Talbot ISBN:1590590732
Apress 2003 (928 pages)
Highlights This text provides extensive coverage of ADO.NET technology
including ADO.NET internals, namespaces, classes, and
Activex data objects for the and
interfaces, .NETtakes
Framework (ADO.NET)
a comprehensive lookisatthe latest database access technology from
XML
Microsoft. ADO.NET namespaces
addressesandissues
classes, and
with how to integrate
previous databaseboth withtechnologies and provides the
access
ADO.NET.
foundation for future scalability. Although ADO.NET stands for Active Data Objects .NET, it's perhaps
misnamed because unlike ActiveX Data Objects (ADO), ADO.NET isn't an ActiveX/Component Object
Model
Table of (COM) technology. As the business world is moving onto the Internet, one of the main goals of
Contents
ADO.NET is allow developers
Applied ADO.NETBuilding to writeSolutions
Data-Driven high-performance, reliable, and scalable database applications over
the Internet.
Introduction
ADO.NET uses .NET Common Language Runtime (CLR) services to manage the library, and
it utilizes Extensible Markup Language (XML) to cache the data and exchange data among applications
Chapter 1 - ADO.NET Basics
over the Internet as well as intranets.
Chapter 2 - Data Components in Visual Studio .NET
Chapter 3 in- this
Our goal ADO.NET in Disconnected
chapter Environments
is simply to provide you with a high-level overview of ADO.NET. In it, we provide
Chapter 4 -ofADO.NET
the basics ADO.NET,in Connected Environments
describe its advantages over current data access technologies, and briefly
Chapter 5 ADO.NET
introduce - Handling ADO.NET Events
classes and namespaces as well as show how to use them to write simple database
applications
Chapter using Microsoft
6 - Integrating Visual
XML with Studio .NET (VS .NET). VS .NET provides tremendous support for
ADO.NET
writing 7database
Chapter applications
- Data Binding in no time,
and Windows using
Forms its wizardsControls
Data-Bound and utilities. (Chapter 2 covers VS .NET and
ADO.NET
Chapter 8 -support.) In this
Constraints and chapter, we also briefly describe the ADO.NET components and how they fit in
Data Relations
the model
Chapter 9 -and work together.
ADO.NET ExceptionChapters
Handling 3 and 4 discuss these components in more detail. Specifically, in
Chapter
Chapter 103,- we coverwith
Working the ADO.NET object
the ODBC .NET model
Data in disconnected environments, and in Chapter 4, we
Provider
cover ADO.NET
Chapter in Procedures
11 - Stored connected and
environments.
Views
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Note The .NET Base Class Library is also called the .NET Runtime Library or the .NET Framework
Chapter 13 Class
- Developing
Library.a Custom Data Provider
Chapter 14 - Developing Database Web Applications using ASP.NET
Chapter 15 - Using ADO.NET in Xml Web Services
Chapter 16 - ASP.NET Server Controls and Data Binding
Chapter 17 - Building Real-World Web Applications
Chapter 18 - Object-Relational Mapping in .NET
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
Chapter 20 - COM Interoperability and ADO.NET
Chapter 21 - Messaging
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Appendix A - Relational Databases: Some Basic Concepts
Appendix B - Commonly Used SQL Statements
Appendix C - ADO.NET Frequently Asked Questions
Index
List of Figures
List of Tables
List of Listings
List of Sidebars
Overview ofApplied
Microsoft Data
ADO.NET: Access
Building Technologies
Data-Driven Solutions
by Mahesh Chand and David Talbot ISBN:1590590732
To understand the importance
Apress of ADO.NET,
2003 (928 pages) it's useful to take a quick look at existing Microsoft database
access technologies before ADO.NET.
This text provides extensive coverage of ADO.NET technology
including ADO.NET internals, namespaces, classes, and
Since the first release of Open
interfaces, andDatabase Connectivity (ODBC)
takes a comprehensive to access databases for Windows
look at XML
namespaces
applications, Microsoft and introducing
has been classes, andand
howimproving
to integrate
waysboth
towith
make database programmers' lives
ADO.NET.
easier. In this series of database technologies, it introduced many new technologies and improved existing
technologies. Each of these technologies has its own pros and cons. Some of the technologies are
specific to a particular kind of data source, and some of them are common to all kinds of data sources.
Table of Contents
Together these technologies are called Microsoft Data Access Technologies or Microsoft Data Access
Applied ADO.NETBuilding Data-Driven Solutions
Components (MDAC). These technologies include the following:
Introduction
Chapter 1 - ADO.NET Basics
ODBC
Chapter 2 - Data Components in Visual Studio .NET
Data
Chapter 3 Access Objects
- ADO.NET (DAO)
in Disconnected Environments
Chapter 4 - ADO.NET in Connected Environments
Microsoft Foundation Classes (MFC) ODBC and DAO classes
Chapter 5 - Handling ADO.NET Events
Chapter 6 - Integrating
Remote XML(RDO)
Data Objects with ADO.NET
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
Object
Chapter 8 - Linking and and
Constraints Embedding Database (OLE DB)
Data Relations
Chapter 9 - ADO.NET Exception Handling
ADO
Chapter 10 - Working with the ODBC .NET Data Provider
Chapter 11 - Stored Procedures and Views
ODBC
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Chapter 13 - Developing a Custom Data Provider
ODBC was the first formal database access technology introduced by Microsoft. ODBC provides a low-
Chapter 14 - Developing Database Web Applications using ASP.NET
level C/C++ Application Programming Interface (API) to retrieve data from relational databases such as
Chapter 15 - Using
SQL Server, ADO.NET
Access, in Xml
or Oracle byWeb
usingServices
ODBC drivers and ODBC Administration. With the help of ODBC
Chapter 16 - ASP.NET Server Controls and Datayou
drivers and the ODBC Administration utility, Binding
can connect to any ODBC-compliant data source using
Chapter 17 - Building Real-World Web Applications
the ODBC API. However, ODBC is relational in nature, so it's difficult to use ODBC to communicate with
Chapter 18 - Object-Relational
nonrelational Mapping
data sources such in .NET
as object databases, network directory services, email stores, and so on.
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
Figure 20
Chapter 1-1-shows ODBC connectivity
COM Interoperability to a database through an ODBC driver and ODBC Administration,
and ADO.NET
also called
Chapter 21 - the ODBC driver manager.
Messaging
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Appendix A - Relational Databases: Some Basic Concepts
Appendix B - Commonly Used SQL Statements
Appendix C - ADO.NET Frequently Asked Questions
Index
List of Figures
List of Tables
List of Listings
List of Sidebars
Using ODBC functions isn't a fun way of programming for high-level programmers. ODBC is a hierarchical
model, which means you have to create environment and database objects before creating a recordset
object with which you can start accessing the data. Other problems with ODBC are multiple connections
and multiple data sources. An ODBC connection doesn't allow you to connect to two data sources using
the same connection. You need to use two separate connection objects to do so. Being non-object-
oriented in nature and having poor memory management are other drawbacks of ODBC.
DAO is easier to use than the ODBC API, but it doesn't provide the degree of low-level control and
flexibility afforded by the ODBC API. Therefore, you could classify DAO as a high-level database interface.
To access non-Access databases, DAO uses ODBC internally, which adds one more layer of API to
access ODBC data sources. This degrades the performance of DAO while accessing ODBC data
sources.
MFC ODBCApplied
and DAO Classes
ADO.NET: Building Data-Driven Solutions
by Mahesh Chand and David Talbot ISBN:1590590732
MFC is a set of C++ classes that provides DAO and ODBC classes to access databases that use DAO
Apress 2003 (928 pages)
and ODBC. These classes provide a high-level programming model for Visual C++ developers working
This text provides extensive coverage of ADO.NET technology
with DAO and ODBC. These classes are a nice wrapper around DAO and ODBC APIs. A drawback of
including ADO.NET internals, namespaces, classes, and
these classes is that they aren't
interfaces, flexible
and takes enough. Also, they
a comprehensive look are slow in performance because of too many
at XML
layers. namespaces and classes, and how to integrate both with
ADO.NET.
RDO
Table of Contents
RDO isADO.NETBuilding
Applied an object interface for ODBC Solutions
Data-Driven that provides an OLE layer on the top of the ODBC API. The main
advantage of RDO is that it gives developers an object interface for ODBC developers, but the
Introduction
disadvantage is that it's slow in performance because of too many layers. It also suffers the ODBC
Chapter 1 - ADO.NET Basics
limitation of not being well suited for nonrelational data sources.
Chapter 2 - Data Components in Visual Studio .NET
Chapter 3 - ADO.NET in Disconnected Environments
OLE DB
Chapter 4
- ADO.NET in Connected Environments
Chapter 5 - Handling ADO.NET Events
OLE DB was designed to access all kinds of data including relational, nonrelational, text data, graphical
Chapter 6 - Integrating XML with ADO.NET
data, and directory services. OLE DB components consist of data providers, which expose their data; data
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
consumers, which use data; and service components, which process and transport data (for example,
Chapter 8 - Constraints and Data Relations
query processors and cursor engines). OLE DB is a low-level programming model and provides the most
Chapter 9 and
flexibility - ADO.NET Exception
control over data.Handling
Figure 1-3 shows the OLE DB model.
Chapter 10 - Working with the ODBC .NET Data Provider
Chapter 11 - Stored Procedures and Views
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Chapter 13 - Developing a Custom Data Provider
Chapter 14 - Developing Database Web Applications using ASP.NET
Chapter 15 - Using ADO.NET in Xml Web Services
Chapter 16 - ASP.NET Server Controls and Data Binding
Chapter 17 - Building Real-World Web Applications
Chapter 18 - Object-Relational Mapping in .NET
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
Chapter 20 - 1-3:
Figure COM OLE
Interoperability
DB model and ADO.NET
Chapter 21 - Messaging
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
As you can see from Figure 1-3, a client application accesses a database through an OLE DB provider
Appendix A - Relational Databases: Some Basic Concepts
and consumers. You must have an OLE DB provider installed to use OLE DB in your application; database
Appendix B - Commonly Used SQL Statements
venders provide this.
Appendix C - ADO.NET Frequently Asked Questions
Index
ADO
List of Figures
List of Tables
ActiveX Data Objects (ADO) is a set of ActiveX components that provide object-based programmatic
List of Listings
access to OLE DB. ADO is a COM wrapper around OLE DB libraries. ADO is much simpler to use than
List of Sidebars
OLE DB; you can classify it as a high-level database interface.
In comparison to other data access technologies, ADO provides many benefits. ADO is easy to program
and, with a few exceptions, is faster than ODBC and DAO. ADO also provides more flexibility and control
over data. You don't have to go through a hierarchy of objects to access data as you do in DAO or ODBC.
ADO (OLE DB) is a set of COM interfaces. This means ADO provides a binary standard to access any kind
of data source. You can use ADO with any language that supports COM, such as Visual Basic (VB) or
C++. ADO also supports XML data access with the help of Microsoft XML (MSXML).
ADO.NET
ADO.NET is an evolution of ADO. The ADO.NET and XML .NET APIs construct a uniform model to work
Applied ADO.NET: Building Data-Driven Solutions
with XML data from any type of data store. The ADO.NET API is managed code, which means you get all
the advantages ofby.NET,
Mahesh Chand and
including David Talbot
automatic memory management ISBN:1590590732
and garbage collection. Unlike DAO
Apress 2003 (928 pages)
or ODBC, though, you don't have to install new libraries to make an ADO.NET program work if you are
This text
already running .NET provides extensive
applications coverage
on a machine. We of ADO.NET
discuss technology
ADO.NET in more detail in the following
including ADO.NET internals, namespaces, classes, and
section.
interfaces, and takes a comprehensive look at XML
[1]Karen Watterson, "ODBC," and
namespaces Microsoft SQL
classes, andServer
how toConnection, July
integrate both 1992.
with
ADO.NET.
Table of Contents
Applied ADO.NETBuilding Data-Driven Solutions
Introduction
Chapter 1 - ADO.NET Basics
Chapter 2 - Data Components in Visual Studio .NET
Chapter 3 - ADO.NET in Disconnected Environments
Chapter 4 - ADO.NET in Connected Environments
Chapter 5 - Handling ADO.NET Events
Chapter 6 - Integrating XML with ADO.NET
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
Chapter 8 - Constraints and Data Relations
Chapter 9 - ADO.NET Exception Handling
Chapter 10 - Working with the ODBC .NET Data Provider
Chapter 11 - Stored Procedures and Views
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Chapter 13 - Developing a Custom Data Provider
Chapter 14 - Developing Database Web Applications using ASP.NET
Chapter 15 - Using ADO.NET in Xml Web Services
Chapter 16 - ASP.NET Server Controls and Data Binding
Chapter 17 - Building Real-World Web Applications
Chapter 18 - Object-Relational Mapping in .NET
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
Chapter 20 - COM Interoperability and ADO.NET
Chapter 21 - Messaging
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Appendix A - Relational Databases: Some Basic Concepts
Appendix B - Commonly Used SQL Statements
Appendix C - ADO.NET Frequently Asked Questions
Index
List of Figures
List of Tables
List of Listings
List of Sidebars
What Is ADO.NET?
Applied ADO.NET: Building Data-Driven Solutions
by Mahesh Chand and David Talbot ISBN:1590590732
ADO.NET is a new database
Apress 2003 access technology created by Microsoft; its .NET Framework can access any
(928 pages)
kind of data source. It's a collection of object-oriented
This text provides extensive classes
coverage of ADO.NETthattechnology
provides a rich set of data components
to create high-performance, reliable, and scalable database applications
including ADO.NET internals, namespaces, classes, and for client-server applications as
well as distributedinterfaces, and takes
environments over athecomprehensive look at XML
Internet and intranets.
namespaces and classes, and how to integrate both with
ADO.NET.
In the ADO.NET modelunlike ADO (in connected state) and previous data access
technologiesapplications are connected to the data sources only when they are reading or updating the
data. After that, the connection closes. This is important because in client-server or distributed
Table of Contents
applications, having connection resources open all the time is one of the most resource-consuming parts.
Applied ADO.NETBuilding Data-Driven Solutions
You don't have to connect to a data source all the time; the only time you need to connect to a data source
Introduction
is when you are reading and writing final changes to a data source.
Chapter 1 - ADO.NET Basics
Chapter
The old2 approach
- Data Components in Visual Studio
of having connections open.NET
all the time is problematic when considering the number of
Chapter
clients 3that- access
ADO.NETtheinsame
Disconnected Environments
data source simultaneously. In larger systems, Microsoft Transaction Server
(MTS)/COM+
Chapter was often
4 - ADO.NET used to pool
in Connected ADO connections to address some of this resource consumption;
Environments
however,
Chapter 5 ADO.NET
- Handling provides
ADO.NET aEvents
more optimal paradigm for large systems without needing to utilize
MTS/COM+
Chapter enterprise XML
6 - Integrating servicesunless,
with ADO.NET of course, you need to take advantage of such advanced
techniques
Chapter 7 - as a three-phase
Data commit. Forms Data-Bound Controls
Binding and Windows
Chapter 8 - Constraints and Data Relations
ADO.NET uses Structured Query Language (SQL) queries and stored procedures to read, write, update,
Chapter 9
and delete- data
ADO.NET Exception Handling
from a data source. You use SQL queries through the ADO.NET Command object, which
Chapter
returns dataWorking
10 - withof
in the form the ODBC .NET Data
DataReader Provider objects. After that connection is closed with the data
or DataSet
Chapter 11 - Stored Procedures and Views
source, you use DataSet objects to work with the data and connect to the data source again when you
Chapter
need to12 - Oracle,
update the SQLXML, and Other .NET Data Providers
data source.
Chapter 13 - Developing a Custom Data Provider
Note
Chapter 14 SQL queries Database
- Developing are also called SQL statements.
Web Applications See Appendix B for some SQL query examples.
using ASP.NET
Chapter 15 See Chapter
- Using 11 for
ADO.NET in more details
Xml Web on stored procedures.
Services
Chapter 16 - ASP.NET Server Controls and Data Binding
ADataSet is a collection of DataTable objects and the relationships among them. It works as a
Chapter 17 - Building Real-World Web Applications
container that stores returned data from a database in cached form. You can fill a DataSet with the data
Chapter 18 - Object-Relational Mapping in .NET
retrieved from multiple tables of a database. Once you have a DataSet (which is disconnected data, stored
Chapter
on your19 - Mapped
local Objects:
machine), Performance
you treat Considerations
the DataSet as your and
dataData Binding
source and work with it. You call the Update
Chapter
method20to-make
COM Interoperability
DataSet changes and ADO.NET
final to the actual database. You can even read and update a
Chapter
DataSet 21 -from
Messaging
different data sources.
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
You access
Appendix a data source
A - Relational and fillSome
Databases: a DataSet via data providers. The .NET Framework provides three
Basic Concepts
differentBtypes
Appendix of data providers
- Commonly Used SQL that ship with the version 1.0 of Visual Studio .NET: Sql, OleDb, and Odbc.
Statements
MicrosoftC and
Appendix third parties
- ADO.NET have Asked
Frequently also developed
Questions data providers for the Oracle database. Some companies
also have developed data providers for MySql and other databases. You use a DataAdapter object of a
Index
data provider and call its Fill method to fill a DataSet.
List of Figures
List
XML of plays
Tablesa major role in ADO.NET. The ADO.NET model utilizes XML to store the data in cache and
List of Listings
transfer the data among applications. DataSets use XML schemas to store and transfer data among
List of SidebarsYou can even use this XML file from other applications without interacting with the actual
applications.
DataSet. Because XML is an industry standard, data can be used among all kinds of applications and
components; because of its text-based nature, data can be transferred via many protocols, such as
Hypertext Transfer Protocol (HTTP). We discuss XML and ADO.NET integration and how you can take
advantage of XML support in ADO.NET applications in Chapter 6.
Why ADO.NET Was
Applied Designed
ADO.NET: Building Data-Driven Solutions
by Mahesh Chand and David Talbot ISBN:1590590732
As mentioned, each previous
Apress 2003 data access technology has its own pros and cons. Some of them were
(928 pages)
designed specifically for a particular type of data
This text provides extensive source,
coverage some of technology
of ADO.NET them aren't easy to program for
developers, and some
including ADO.NET internals, namespaces, classes, and For example, the ODBC API is a set
of them don't have good enough performance.
interfaces,
of C functions. It has and takes a comprehensive
no object-oriented look at XMLapplications using ODBC is a time-
support. So, developing
consuming process namespaces and classes,
for developers. andproblem
Another how to integrate
with ODBC bothiswith
its relational nature. The ODBC API is
ADO.NET.
limited to relational databases, and it's difficult to use ODBC with nonrelational data sources such as
network directories, email stores, ISAM data, object data, and so on.
Table of Contents
DAO is an object model but was specifically designed to work with the Microsoft Jet database engine. The
Applied ADO.NETBuilding Data-Driven Solutions
MFC ODBC and DAO classes are one more wrapper for ODBC and DAO APIs. Because of this extra
Introduction
wrapper, these classes aren't up to the mark performance-wise and still have some of the same limitations
Chapter 1 - ADO.NET Basics
as ODBC and DAO.
Chapter 2 - Data Components in Visual Studio .NET
Chapter
OLE-DB 3 is- aADO.NET
solution in Disconnected
that works with Environments
any kind of data source using OLE-DB providers and consumers;
however,
Chapter 4 writing OLE-DB
- ADO.NET applications
in Connected is time consuming, and it's hard for developers to program them.
Environments
Moreover,
Chapter 5 -OLE-DB
HandlingisADO.NET
a flat model.
EventsThat means you could directly connect to a table without going through
hierarchical
Chapter objects of connections
6 - Integrating and databases. Because of the lower-level programming model of the
XML with ADO.NET
OLE API,
Chapter 7 the OLE-DB
- Data API
Binding isn't
and easy toForms
Windows program for non-OLE
Data-Bound programmers.
Controls
Chapter 8 - Constraints and Data Relations
To overcome this problem, Microsoft introduced ADO. ADO is a high-level programming model, and it was
Chapter 9 - ADO.NET Exception Handling
the best data access technology at that point. It's a nice COM wrapper for the OLE-DB API, and it suits
Chapter 10 - Working with the ODBC .NET Data Provider
most developers. The first major drawback of ADO is that it's a COM-based model. Writing COM-based
Chapter 11 - Stored
applications Procedures
and using them isand Views one of the most difficult models of programming and a pain for
probably
Chapter 12 - Oracle, SQLXML, and Other
non-COM developers. The second drawback .NET Data Providers
is the limited support for XML. You can read XML documents
Chapter
through13ADO,
- Developing a Custom
but documents Data
have to Provider
have a certain format, which negates many of the benefits of XML.
Chapter 14 - Developing Database Web Applications using ASP.NET
Keeping
Chapter 15all these ADO.NET
- Using problemsininXml
mind,
WebMicrosoft
Serviceswrote a set of new object-oriented classes: ADO.NET.
ADO.NET
Chapter 16 -inherits
ASP.NET itsServer
programming
Controls model from
and Data its predecessor ADO, so ADO programmers will see
Binding
something
Chapter 17 -common between these
Building Real-World two APIs. As such, it will also take less time to jump from ADO to
Web Applications
ADO.NET. ADO.NET classes are based on the ADO model and have some objects in common, such as
Chapter 18 - Object-Relational Mapping in .NET
Connection and Command. However, DataSets replace recordsets in ADO.NET. These classes are
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
easy to use and have solutions for all the problems mentioned.
Chapter 20 - COM Interoperability and ADO.NET
Chapter
In brief,21 - Messaging
ADO.NET was designed to meet today's programming needs, including disconnected data, tight
Chapter
integration-with
22 SQL XML,
Server anda ADO.NET:
and Notes on
common model to Performance
work with all kinds of data sources. Welcome to the
Appendix
ADO.NET A -world.
Relational Databases: Some Basic Concepts
Appendix B - Commonly Used SQL Statements
Appendix C - ADO.NET Frequently Asked Questions
Index
List of Figures
List of Tables
List of Listings
List of Sidebars
AdvantagesApplied
of ADO.NET
ADO.NET: Building Data-Driven Solutions
by Mahesh Chand and David Talbot ISBN:1590590732
ADO.NET offers Apress
severaladvantages over previous Microsoft data access technologies, including ADO.
2003 (928 pages)
The following sections outline these advantages.
This text provides extensive coverage of ADO.NET technology
including ADO.NET internals, namespaces, classes, and
interfaces, and takes a comprehensive look at XML
Single Object-Oriented API
namespaces and classes, and how to integrate both with
ADO.NET.
As discussed earlier, with the many available data access methods, sometimes developers are confused
about which technology to use. For example, to work with Microsoft Access databases, you can use
Table of Contents
ODBC, DAO, OLE-DB, ADO, DAO, or ODBC MFC classes.
Applied ADO.NETBuilding Data-Driven Solutions
Which one would you choose? It all depends on your requirements. Another problem with these
Introduction
technologies
Chapter is installing
1 - ADO.NET the right version. For example, ODBC and ADO have different versions of DLLs,
Basics
and some -ofData
Chapter 2
these versions aren't backward or forward compatible. So, if a user is running some
Components in Visual Studio .NET
programs that require ODBC 3.0 and your application uses ODBC 3.5, then the user will have to install
Chapter 3 - ADO.NET in Disconnected Environments
ODBC 3.5 to run your application. However, the users' programs that are based on ODBC 3.0 may not
Chapter 4 - ADO.NET in Connected Environments
work properly after installing ODBC 3.5. Having multiple DLL versions is a well-known problem, termed
Chapter 5 - Handling ADO.NET Events
DLL hell.
Chapter 6 - Integrating XML with ADO.NET
Chapter
ADO.NET7 -provides
Data Binding and object-oriented
a single Windows Forms set Data-Bound Controls
of classes. Different data providers work with different data
sources,
Chapter 8 but the programming
- Constraints and Datamodel for all these data providers work in the same way. So, if you know
Relations
how to 9work
Chapter with one Exception
- ADO.NET data provider, you can easily work with others. It's just a matter of changing class
Handling
names10
Chapter and- Working
connection
withstrings.
the ODBC .NET Data Provider
Chapter 11 - Stored Procedures and Views
Note You can use more than one data provider to access a single data source. For example, you can
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
use Odbc or OleDb data providers to access Microsoft Access databases.
Chapter 13 - Developing a Custom Data Provider
Chapter 14 - Developing
The ADO.NET classesDatabase
are easy Web Applications
to use and easy using ASP.NET because of their object-oriented nature.
to understand
Chapter 15 - Using ADO.NET in Xml Web Services
Chapter 16 - ASP.NET Server Controls and Data Binding
Managed Code
Chapter 17 - Building Real-World Web Applications
Chapter 18 - Object-Relational
The ADO.NET Mapping in
classes are managed .NET They have all the advantages of the .NET CLR, such as
classes.
Chapter 19 independency
language - Mapped Objects:
andPerformance Considerations
automatic resource and DataAll
management. Binding
.NET languages access the same API.
So, if you
Chapter 20 know
- COMhow to use theseand
Interoperability classes in C#, you will have no problem using them in VB .NET. Another
ADO.NET
big advantage
Chapter is you don't have to worry about memory allocation and freeing it. The CLR takes care of it
21 - Messaging
for you.22 - SQL Server and ADO.NET: Notes on Performance
Chapter
Appendix A - Relational Databases: Some Basic Concepts
XML Support
Appendix B - Commonly Used SQL Statements
Appendix C - ADO.NET Frequently Asked Questions
Today, XML is an industry standard and the most widely used method of sharing data among applications
Index
over
List of the Internet. As mentioned earlier, in ADO.NET data is cached and transferred in XML format. All
Figures
components
List of Tables and applications can share this data, and data can be transferred via different protocols such
as of
List HTTP. We explain this topic in more detail in Chapters 6 and 7.
Listings
List of Sidebars
Visual Data Components
VS .NET offers ADO.NET components and data-bound controls to work in visual form. That means you
can use these components as you use any Windows controls. You drag and drop these components on
Windows and Web Forms, set their properties, and write events. This helps programmers to write less
code and develop applications in no time. VS .NET also offers the Data Form Wizard, which helps you
create full-fledged database applications without writing a single line of code. Using these components,
you can directly bind these components with data-bound controls by setting these control's properties at
design-time.Chapter 4 explains this in detail.
Table of Contents
Applied ADO.NETBuilding Data-Driven Solutions
Introduction
Chapter 1 - ADO.NET Basics
Chapter 2 - Data Components in Visual Studio .NET
Chapter 3 - ADO.NET in Disconnected Environments
Chapter 4 - ADO.NET in Connected Environments
Chapter 5 - Handling ADO.NET Events
Chapter 6 - Integrating XML with ADO.NET
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
Chapter 8 - Constraints and Data Relations
Chapter 9 - ADO.NET Exception Handling
Chapter 10 - Working with the ODBC .NET Data Provider
Chapter 11 - Stored Procedures and Views
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Chapter 13 - Developing a Custom Data Provider
Chapter 14 - Developing Database Web Applications using ASP.NET
Chapter 15 - Using ADO.NET in Xml Web Services
Chapter 16 - ASP.NET Server Controls and Data Binding
Chapter 17 - Building Real-World Web Applications
Chapter 18 - Object-Relational Mapping in .NET
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
Chapter 20 - COM Interoperability and ADO.NET
Chapter 21 - Messaging
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Appendix A - Relational Databases: Some Basic Concepts
Appendix B - Commonly Used SQL Statements
Appendix C - ADO.NET Frequently Asked Questions
Index
List of Figures
List of Tables
List of Listings
List of Sidebars
ComparingApplied
ADO.NET and
ADO.NET: ADO
Building Data-Driven Solutions
by Mahesh Chand and David Talbot ISBN:1590590732
Prior to ADO.NET, ADOwas
Apress 2003 the
(928most
pages)popular and powerful Microsoft data access technology. So, how
does ADO.NET improve on ADO? To understand
This text provides extensive the of
coverage power of ADO.NET,
ADO.NET technologyit's not a bad idea to compare
ADO.NET with ADO.
including ADO.NET internals, namespaces, classes, and
interfaces, and takes a comprehensive look at XML
namespaces
The ADO.NET model and classes,
is inherited from its and how to integrate
predecessor both
ADO, but withare some key differences between
there
ADO.NET.
ADO and ADO.NET. The following sections describe these differences.
The ADO.NET model uses XML to store and transfer data among applications, which is not only an
industry standard but also provides fast access of data for desktop and distributed applications. ADO uses
COM marshaling to transfer data among applications, which is not only hard to program but also not as
efficient or reliable as XML because of its limitations, its data types and their conversions, and the nature of
COM. Using XML, it's easy to program XML files, and you can also transfer data through firewalls using
HTTP, which isn't possible using COM marshaling.
Overview ofApplied
ADO.NET Namespaces
ADO.NET: and
Building Data-Driven Classes
Solutions
by Mahesh Chand and David Talbot ISBN:1590590732
TheSystem.Data namespace
Apress and
2003 (928 its five supporting namespaces define the ADO.NET functionality. In
pages)
this section, we briefly describe these namespaces.
This text provides extensive coverageLater chaptertechnology
of ADO.NET describe these namespaces and
classes in more detail. These namespaces reside in the System.Data.dll
including ADO.NET internals, namespaces, classes, and assembly.
interfaces, and takes a comprehensive look at XML
namespaces
Note In the .NET and classes,
Framework, and how
each class to integrate
belongs both with A namespace is a logical group of
to a namespace.
ADO.NET.
related types and their definitions. To access a type defined in a namespace, you must reference
the namespace by using the Imports keyword or by referencing it directly. For example, the
System namespace defines all the system-related functionality. For example, the Console
Table of Contents
class of the System
Applied ADO.NETBuilding namespace
Data-Driven represents the system console. If you want to access the
Solutions
Console
Introduction class, you need to call System.Console or Imports System in your application.
Chapter 1 - ADO.NET Basics
The six general ADO.NET namespaces are System.Data,System.Data.Common,
Chapter 2 - Data Components
System.Data.OleDb, in Visual Studio .NET
System.Data.Odbc, System.Data.SqlClient, and
Chapter 3 - ADO.NET in Disconnected
System.Data.SqlTypes. BesidesEnvironments
these namespaces, each new data provider may have its own
Chapter 4 - ADO.NET
namespace. in Connected
For example, Environments
if you install the Oracle .NET data provider, the installation adds a new
Chapter 5 - Handling
namespace, ADO.NET Events
the Microsoft.Data.OracleClient namespace, which also belongs to ADO.NET.
Chapter 6 - Integrating XML with ADO.NET
TheSystem.Data
Chapter namespace
7 - Data Binding is the Forms
and Windows core namespace
Data-Bound of ADO.NET. It consists of the base classes for
Controls
the ADO.NET
Chapter architecture.
8 - Constraints All data
and Data providers use these classes. It defines classes that represent tables,
Relations
columns, rows,
Chapter 9
and DataSets. Some common classes from this namespace are DataView,
- ADO.NET Exception Handling
DataViewManager,DataSet,DataTable,DataRow,DataColumn, and DataRelation. To use
Chapter 10 - Working with the ODBC .NET Data Provider
these classes in your applications, you need to add a reference to the System.Data namespace.
Chapter 11 - Stored Procedures and Views
Chapter 12 All
Note - Oracle,
classesSQLXML, and Other
in the .NET Base .NET Data
Class Providers
Library are derived from the Object class and represent a
Chapter 13 type.
- Developing a Custom
Some authors Data
and Provider
documentation also use the word type for a .NET Framework class.
Chapter 14 - Developing Database Web Applications using ASP.NET
TheSystem.Data.Common
Chapter namespace
15 - Using ADO.NET in Xml defines common classes. These classes are base classes for
Web Services
concrete
Chapter 16data provider
- ASP.NET classes.
Server All data
Controls providers
and Data share these classes. DBConnection,DataAdapter,
Binding
DbDataAdaper,
Chapter DataColumnMapping,
17 - Building and DataTableMapping are some of the classes defined in
Real-World Web Applications
this namespace.
Chapter To use these
18 - Object-Relational classes
Mapping in in your application, you need to add a reference to the
.NET
System.Data.Common namespace in your application. Sql, OleDb, and Odbc.
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
Chapter 20 - COM Interoperability
TheSystem.Data.OleDb and ADO.NET
namespace defines classes to work with OLE-DB data sources using .NET
Chapter 21 - Messaging
OleDb data providers. To work with an OLE-DB data source, you must have an OleDb provider for that
Chapter 22 - SQL
data source. EachServer
dataand ADO.NET:
provider Notes on
component Performance
has a class corresponding to it. These classes start with
Appendix A - Relational Databases: Some Basic Concepts
OleDb, followed by the component. For example, the OleDbConnection class represents a
Appendix object. Some
B - Commonly
Connection of the
Used SQL common classes of this namespace are OleDbDataAdapter,
Statements
OleDbDataReader,
Appendix OleDbCommand,
C - ADO.NET Frequently OleDbCommandBuilder,OleDbError,OleDbParameter,
Asked Questions
OleDbPermission, and OleDbTransaction. To use these classes in your application, you need to
Index
addofaFigures
List reference to the System.Data.OleDb namespace in your application.
List of Tables
Similar to the System.Data.OleDb namespace, the System.Data.Odbc namespaces define Odbc
List of Listings
.NET data provider classes to work with the ODBC data sources. To work with ODBC data sources, you
List of Sidebars
need to install an ODBC driver for a database. The System.Data.Odbc namespace classes start with
Odbc, followed by the component. For example, the OdbcConnection class represents a Connection
object. Some of the common classes of this namespace are OdbcDataAdapter,OdbcDataReader,
OdbcCommand,OdbcCommandBuilder,OdbcError,OdbcParameter,OdbcPermission, and
OdbcTransaction. To use these classes in your application, you need to add a reference to the
System.Data.Odbc namespace in your application.
TheSystem.Data.SqlClient namespaces define Sql .NET data provider classes to work with SQL
Server 7.0 or later databases. Similar to Odbc and OleDb classes, the classes in this namespace start with
Sql, followed by the component. For example, common classes are SqlConnection,
SqlDataAdapter,SqlCommand,SqlDataReader, and SqlTransaction.
The last namespace, System.Data.SqlTypes, provides a group of classes representing the specific
Applied
types found in SQL ADO.NET:
Server. Some of Building Data-Driven
these classes Solutions
are SqlBinary, SqlMoney,SqlString,SqlInt32,
by Mahesh Chand and David
SqlDouble,SqlDateTime, and SqlNumeric. Talbot ISBN:1590590732
Apress 2003 (928 pages)
We discuss theseThis
namespaces, classes,
text provides andcoverage
extensive their members in more
of ADO.NET detail in Chapters 3 and 4.
technology
including ADO.NET internals, namespaces, classes, and
interfaces, and takes a comprehensive look at XML
namespaces and classes, and how to integrate both with
ADO.NET.
Table of Contents
Applied ADO.NETBuilding Data-Driven Solutions
Introduction
Chapter 1 - ADO.NET Basics
Chapter 2 - Data Components in Visual Studio .NET
Chapter 3 - ADO.NET in Disconnected Environments
Chapter 4 - ADO.NET in Connected Environments
Chapter 5 - Handling ADO.NET Events
Chapter 6 - Integrating XML with ADO.NET
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
Chapter 8 - Constraints and Data Relations
Chapter 9 - ADO.NET Exception Handling
Chapter 10 - Working with the ODBC .NET Data Provider
Chapter 11 - Stored Procedures and Views
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Chapter 13 - Developing a Custom Data Provider
Chapter 14 - Developing Database Web Applications using ASP.NET
Chapter 15 - Using ADO.NET in Xml Web Services
Chapter 16 - ASP.NET Server Controls and Data Binding
Chapter 17 - Building Real-World Web Applications
Chapter 18 - Object-Relational Mapping in .NET
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
Chapter 20 - COM Interoperability and ADO.NET
Chapter 21 - Messaging
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Appendix A - Relational Databases: Some Basic Concepts
Appendix B - Commonly Used SQL Statements
Appendix C - ADO.NET Frequently Asked Questions
Index
List of Figures
List of Tables
List of Listings
List of Sidebars
Understanding
AppliedADO.NET Components
ADO.NET: Building Data-Driven Solutions
by Mahesh Chand and David Talbot ISBN:1590590732
You can categorize ADO.NET
Apress components
2003 (928 pages) into three categories: disconnected, common or shared, and
the .NET data providers. The disconnected components build thetechnology
This text provides extensive coverage of ADO.NET basic ADO.NET architecture. You can
use these components (or classes) with or without data providers.
including ADO.NET internals, namespaces, classes, and For example, you can use a
DataTable object interfaces, and takes
with or without a comprehensive
data look or
providers. Shared at common
XML components are the base classes
for data providersnamespaces and classes,
and are shared and providers.
by all data how to integrate
The databothprovider
with components are specifically
ADO.NET.
designed to work with different kinds of data sources. For example, Odbc data providers work with ODBC
data sources, and OleDb data providers work with OLE-DB data sources.
Table of Contents
Figure 1-4 represents the ADO.NET components model and shows how the components work together.
Applied ADO.NETBuilding Data-Driven Solutions
Introduction
Chapter 1 - ADO.NET Basics
Chapter 2 - Data Components in Visual Studio .NET
Chapter 3 - ADO.NET in Disconnected Environments
Chapter 4 - ADO.NET in Connected Environments
Chapter 5 - Handling ADO.NET Events
Chapter 6 - Integrating XML with ADO.NET
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
Chapter 8 - 1-4:
Figure Constraints and Data components
The ADO.NET Relations model
Chapter 9 - ADO.NET Exception Handling
Adata provider
Chapter is a set
10 - Working ofthe
with components,
ODBC .NET such
Data as Connection,Command,DataAdapter, and
Provider
DataReader.
Chapter TheProcedures
11 - Stored Connection is the first component that talks to a data source. The Connection
and Views
object establishes a connection to a data source and is used in Command and DataAdapter objects as a
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
connection reference. A Command object executes a SQL query and stored procedures to read, add,
Chapter 13 - Developing a Custom Data Provider
update, and delete data in a data source via a DataAdapter. The DataAdapter is a bridge between a
Chapter 14 - Developing Database Web Applications using ASP.NET
DataSet and the connection. It uses Command objects to execute SQL queries and stored procedures.
Chapter 15 - Using ADO.NET in Xml Web Services
Chapter
All data16providers
- ASP.NET Server
share theControls
ADO.NET andcommon
Data Binding
components. These components represent the data.
Chapter 17 - Building Real-World Web Applications
Some of the common components are DataSet,DataView, and DataViewManager. The DataSet
uses XML
Chapter 18 -toObject-Relational
store and transfer data between
Mapping in .NET the applications and the data provider. A DataSet is a set of
DataTable
Chapter objects.
19 - Mapped A DataTable
Objects: represents
Performance a database
Considerations table.Binding
and Data The DataView and
DataViewManager
Chapter objects provide
20 - COM Interoperability single or multiple views of a DataSet. You can attach a DataView
and ADO.NET
or a DataViewManager
Chapter 21 - Messaging directly to data-bound controls such as a DataGrid or a DataList. Other
common
Chapter 22 components
- SQL Server are
andDataTable, DataRow,
ADO.NET: Notes DataColumn, and so on. Now let's break down the
on Performance
ADO.NET
Appendix A -model to see
Relational how it works.
Databases: Some Basic Concepts
Appendix B - Commonly Used SQL Statements
The Connection Object
Appendix C - ADO.NET Frequently Asked Questions
Index
The
List ofConnection
Figures object is the first component of ADO.NET that we should talk about. A connection sets
a link between a data source and ADO.NET. A Connection object sits between a data source and a
List of Tables
DataAdapter (via Command). You need to define a data provider and a data source when you create a
List of Listings
connection. With these two, you can also specify the user ID and password depending on the type of data
List of Sidebars
source.Figure 1-5 shows the relationship between a connection, a data source, and a DataAdapter.
Applied ADO.NET: Building Data-Driven Solutions
by Mahesh Chand and David Talbot ISBN:1590590732
Apress 2003 (928 pages)
This text provides extensive coverage of ADO.NET technology
including ADO.NET internals, namespaces, classes, and
interfaces, and takes a comprehensive look at XML
namespaces and classes, and how to integrate both with
ADO.NET.
Table of Contents
Figure
Applied 1-5: The relationship
ADO.NETBuilding between
Data-Driven Connection,DataAdpater, and a data source
Solutions
Introduction
You can
Chapter 1 also connectBasics
- ADO.NET a Connection object to a Command object to execute SQL queries, which you can
use to retrieve,
Chapter 2 - Dataadd, update, and
Components delete
in Visual data .NET
Studio in a data source. Figure 1-6 shows the relationship between
theCommand and Connection objects.
Chapter 3 - ADO.NET in Disconnected Environments
Chapter 4 - ADO.NET in Connected Environments
Chapter 5 - Handling ADO.NET Events
Chapter 6 - Integrating XML with ADO.NET
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
Figure 1-6: The relationship between the Command object and the Connection object
Chapter 8 - Constraints and Data Relations
Chapter 9 - ADO.NET Exception Handling
TheConnection
Chapter object
10 - Working alsoODBC
with the plays.NET
a useful
Data role in creating a transaction. Transactions are stored in
Provider
Transaction
Chapter objects,
11 - Stored and Transaction
Procedures and Views classes have all those nice features for dealing with
transactions
Chapter such as
12 - Oracle, commitand
SQLXML, andOther
rollback.
.NETFigure 1-7 shows the relationship between the Connection
Data Providers
object and
Chapter 13 - aDeveloping
transaction.
a Custom Data Provider
Chapter 14 - Developing Database Web Applications using ASP.NET
Chapter 15 - Using ADO.NET in Xml Web Services
Chapter 16 - ASP.NET Server Controls and Data Binding
Chapter 17 - Building Real-World Web Applications
Figure 1-7: Creating a transaction from a Connection object
Chapter 18 - Object-Relational Mapping in .NET
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
Each data provider has a Connection class. The OleDbConnection,SqlConnection, and
Chapter 20 - COM Interoperability
OdbcConnection and ADO.NET
classes represent the Connection object of the OleDb, Sql, and Odbc data
Chapter 21 - Messaging
providers, respectively.
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
NoteA ADO.NET
Appendix - Relationalconnections are discussed
Databases: Some in more detail in "The Connection: Connecting to a Data
Basic Concepts
Appendix B Source" section
- Commonly UsedofSQL
Chapter 4.
Statements
Appendix C - ADO.NET Frequently Asked Questions
The Command Object
Index
List of Figures
You
List of will usually use the Command object to execute SQL queries and stored procedures. You can execute
Tables
SQL
List of queries
Listings to return data in a DataSet or a DataReader object. To retrieve, add, update, and delete
data,
List you use SELECT,INSERT,UPDATE, and DELETE SQL queries. A DataAdapter generated using
of Sidebars
the VS .NET Integrated Development Environment (IDE) has these queries. Figure 1-8 shows the
relationship between a DataAdaper and a Command object.
Applied ADO.NET: Building Data-Driven Solutions
by Mahesh Chand and David Talbot ISBN:1590590732
Apress 2003 (928 pages)
This text provides extensive coverage of ADO.NET technology
including ADO.NET internals, namespaces, classes, and
interfaces, and takes a comprehensive look at XML
namespaces and classes, and how to integrate both with
ADO.NET.
Note The DataSet object is discussed in more detail in the "The DataSet: The Heart of ADO.NET"
section of Chapter 3 and the "The DataSet in Connected Environments" section of Chapter 4.
DataSets in DataViews
Another thing you can do with the contents of DataSets is sort and filter them using DataViews. You can
have multiple views of a single DataSet. A DataView is a view of your data created according to certain
criteria. Each DataView has a one-to-one mapping to a DataTable in a DataSet. For example, say
you have three tables in a DataSet: table1, table2, and table3. Using three different data tables and data
Applied this
views, you can represent ADO.NET:
DataSet Building Data-Driven
in three Solutions
different views. Using sort and filters, you can even sort
by Mahesh Chand and David Talbot
and filter the data based on some criteria. Figure 1-13 shows three ISBN:1590590732
different views of a DataSet in the
Apressdata
form of three different 2003 (928 pages)
views.
This text provides extensive coverage of ADO.NET technology
including ADO.NET internals, namespaces, classes, and
interfaces, and takes a comprehensive look at XML
namespaces and classes, and how to integrate both with
ADO.NET.
Table of Contents
Applied ADO.NETBuilding Data-Driven Solutions
Introduction
Chapter 1 - ADO.NET Basics
Chapter 2 - Data Components in Visual Studio .NET
Chapter 3 - ADO.NET in Disconnected Environments
Figure 1-13: The relationship between DataSet and DataView objects
Chapter 4 - ADO.NET in Connected Environments
Chapter 5 - Handling ADO.NET Events
ADataView
Chapter can directly
6 - Integrating XMLattach
with to data-bound controls such as a DataGrid,DataList, or a combo
ADO.NET
box. We
Chapter 7 cover this
- Data data binding
Binding in Chapter
and Windows Forms2Data-Bound
and Chapter 7 in more detail.
Controls
Chapter 8 - Constraints and Data Relations
OK, enough theory. Let's see how to write your first database application and get some hands-on
Chapter 9 - ADO.NET Exception Handling
experience with ADO.NET.
Chapter 10 - Working with the ODBC .NET Data Provider
Chapter 11 - Stored Procedures and Views
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Chapter 13 - Developing a Custom Data Provider
Chapter 14 - Developing Database Web Applications using ASP.NET
Chapter 15 - Using ADO.NET in Xml Web Services
Chapter 16 - ASP.NET Server Controls and Data Binding
Chapter 17 - Building Real-World Web Applications
Chapter 18 - Object-Relational Mapping in .NET
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
Chapter 20 - COM Interoperability and ADO.NET
Chapter 21 - Messaging
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Appendix A - Relational Databases: Some Basic Concepts
Appendix B - Commonly Used SQL Statements
Appendix C - ADO.NET Frequently Asked Questions
Index
List of Figures
List of Tables
List of Listings
List of Sidebars
Writing ADO.NET Applications
Applied ADO.NET: Building Data-Driven Solutions
by Mahesh Chand and David Talbot ISBN:1590590732
It's now time to write your
Apress first (928
2003 ADO.NET
pages) application. In the following sections, we discuss the necessary
steps required to This
writetext
a database application
provides extensive using ADO.NET.
coverage of ADO.NET technology
including ADO.NET internals, namespaces, classes, and
interfaces, and takes a comprehensive look at XML
Choosing a .NET Data Provider
namespaces and classes, and how to integrate both with
ADO.NET.
The first step of writing your first ADO.NET application is to decide what .NET data provider you'll use in
your application. As discussed previously, there are many data providers that work with multiple data
Table of Contents
sources. Some of the available data providers are OleDb, Sql, Odbc, and Oracle. You use the OleDb data
Applied ADO.NETBuilding
provider to access OLE-DB Data-Driven Solutions
data sources. The Sql data provider works with SQL Server 7.0 or later
databases. The Odbc data provider works with ODBC data sources, and the Oracle data provider works
Introduction
with Oracle
Chapter databases.
1 - ADO.NET You can also use more than one data provider to access the same database. For
Basics
example, you can use the
Chapter 2 - Data Components OleDb and Odbc
in Visual Studiodata
.NETproviders to work with Microsoft Access databases.
Chapter 3 - ADO.NET in Disconnected Environments
Note Some documentation and authors represent the Sql data provider as the SqlClient data provider.
Chapter 4 - ADO.NET in Connected Environments
This may be because the Sql data provider is defined in the SqlClient namespace.
Chapter 5 - Handling ADO.NET Events
Chapter
For this6example,
- Integrating
you'llXML
learnwith
howADO.NET
to build an application that uses OleDb data providers to access an
Chapter
Access 2000 database. In the "Using aForms
7 - Data Binding and Windows Data-Bound
DataSet to Read Controls
Data" section, you'll learn how to create an
Chapter 8 - that
application Constraints
uses Sqland Data
data Relations
providers to access a SQL Server 2000 database.
Chapter 9 - ADO.NET Exception Handling
Chapter 10 - Working with the ODBC .NET Data Provider
Adding Namespace References
Chapter 11 - Stored Procedures and Views
Chapter 12 - Oracle,
After you've chosenSQLXML, and
your data Other .NET
provider, you Data
needProviders
to add references to the assembly and include the
namespaces in your project. The System.Data.dll
Chapter 13 - Developing a Custom Data Provider assembly defines ADO.NET namespaces. You can
add references
Chapter to the project
14 - Developing using
Database Webthe Project using
Applications Add Reference
ASP.NET option. The .NET tab of the Add
Reference
Chapter 15 - dialog box lists all
Using ADO.NET the available
in Xml .NET assemblies (see Figure 1-14). Select the
Web Services
System.Data.dll
Chapter assembly.
16 - ASP.NET Server Controls and Data Binding
Chapter 17 - Building Real-World Web Applications
Chapter 18 - Object-Relational Mapping in .NET
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
Chapter 20 - COM Interoperability and ADO.NET
Chapter 21 - Messaging
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Appendix A - Relational Databases: Some Basic Concepts
Appendix B - Commonly Used SQL Statements
Appendix C - ADO.NET Frequently Asked Questions
Index
List of Figures
List of Tables
List of Listings
List of Sidebars
After selecting the System.Data.dll assembly, click the Select button and then the OK button. This
action adds the System.Data assembly and related namespace references to your project.
After adding a reference to the assembly, you need to include namespaces in your project by using the
Imports directive. The Imports directive imports a namespace definition in a project. The following
code shows how to import the System,System.Data,System.Data.Common, and
System.Data.OleDb namespaces:
Applied ADO.NET: Building Data-Driven Solutions
by Mahesh Chand and David Talbot ISBN:1590590732
Imports System
Apress 2003 (928 pages)
Imports System.Data
This text provides extensive coverage of ADO.NET technology
Imports System.Data.OleDb
including ADO.NET internals, namespaces, classes, and
Imports System.Data.Common
interfaces, and takes a comprehensive look at XML
namespaces and classes, and how to integrate both with
ADO.NET.
Note If you are using the Sql data provider, you need to include the System.Data.Sql namespace.
Table of Contents
If you are using the Odbc data provider, you need to include the System.Data.Odbc
Applied ADO.NETBuilding Data-Driven Solutions
namespace.
Introduction
Chapter 1 - ADO.NET Basics
Establishing
Chapter a Connection
2 - Data Components in Visual Studio .NET
Chapter 3 - ADO.NET in Disconnected Environments
Now, the next step is to create a Connection object. You create a Connection object using the data
Chapter 4 Connection
provider's - ADO.NET in Connected Environments
class. In the following code, the OleDbConnection class creates a connection
Chapter 5 - Handling ADO.NET Events
with an Access 2000 database. The OleDbConnection constructor takes one parameter of a string type.
Chapter 6 -isIntegrating
This string XML with ADO.NET and it has two parts. First, it has a provider, and second, it has
called connectionString,
Chapter 7 - Data Binding and As
the path of the data source. Windows Forms
you can see, Data-Bound Controls
the following code uses the Microsoft.Jet.OLEDB.4.0
Chapter 8 and
provider - Constraints and Data Relations
the northwind.mdb data source:
Chapter 9 - ADO.NET Exception Handling
Chapter 10 - Working with the ODBC
Dim connectionString .NET Data Provider
As String
Chapter
'Create11 -connection
Stored Procedures
andand Views
command objects
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
connectionString = "Provider=Microsoft.JET.OLEDB.4.0;" & _
Chapter
"data13source=C:\\Northwind.mdb"
- Developing a Custom Data Provider
Chapter 14 - Developing
Dim conn Database Web Applications
As OleDbConnection using ASP.NET
= New OleDbConnection(connectionString)
'Open15connection
Chapter - Using ADO.NET in Xml Web Services
conn.Open()
Chapter 16 - ASP.NET Server Controls and Data Binding
Chapter 17 - Building Real-World Web Applications
Chapter 18 - Object-Relational Mapping in .NET
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
Chapter 20 - COM Interoperability and ADO.NET
Note In this sample, the northwind.mdb database path is "C:\\northwind.mdb". You can use
Chapter 21 - Messaging
any database you want. You just need to change the path and name of the database and
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
change the table names you are using in the SQL statements to access the data.
Appendix A - Relational Databases: Some Basic Concepts
Appendix B - Commonly Used SQL Statements
Creating a Command or DataAdapter Object
Appendix C - ADO.NET Frequently Asked Questions
Index
Next, you need to create a DataAdapter or Command object. You create a Command object by using the
List of Figures
OleDbCommand class. (You'll see a DataAdapter object in the SQL Server example at the end of this
List of Tables
chapter; see the "Using a DataSet to Read Data" section.)
List of Listings
The
List ofOleDbCommand
Sidebars constructor takes two parameters. The first is a SQL query, and the second is the
Connection object. You can create a SELECT SQL query from the Customers table in the Northwind
database. The following code shows how to create a Command object:
Table of Contents
Applied ADO.NETBuilding Data-Driven Solutions
Introduction
Chapter 1 - ADO.NET Basics
Chapter 2 - Data Components in Visual Studio .NET
Chapter 3 - ADO.NET in Disconnected Environments
Chapter 4 - ADO.NET in Connected Environments
Chapter 5 - Handling ADO.NET Events
Figure 1-15: Displaying data on the console using DataReader
Chapter 6 - Integrating XML with ADO.NET
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
Chapter 8 - Constraints and Data Relations
Chapter 9 - ADO.NET Exception Handling
Chapter 10 - Working with the ODBC .NET Data Provider
Chapter 11 - Stored Procedures and Views
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Chapter 13 - Developing a Custom Data Provider
Chapter 14 - Developing Database Web Applications using ASP.NET
Chapter 15 - Using ADO.NET in Xml Web Services
Chapter 16 - ASP.NET Server Controls and Data Binding
Chapter 17 - Building Real-World Web Applications
Chapter 18 - Object-Relational Mapping in .NET
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
Chapter 20 - COM Interoperability and ADO.NET
Chapter 21 - Messaging
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Appendix A - Relational Databases: Some Basic Concepts
Appendix B - Commonly Used SQL Statements
Appendix C - ADO.NET Frequently Asked Questions
Index
List of Figures
List of Tables
List of Listings
List of Sidebars
Using a DataSet to ReadBuilding
Applied ADO.NET: Data Data-Driven Solutions
by Mahesh Chand and David Talbot ISBN:1590590732
You just saw an example of working
Apress 2003 with an Access 2000 database. For variety, you'll now see an example
(928 pages)
of using a SQL Server database. Instead of writing
This text provides extensive coveragea console-based application, this time you'll create a
of ADO.NET technology
Windows Forms application and use the VS .NET IDE.
including ADO.NET internals, namespaces, classes, and
interfaces, and takes a comprehensive look at XML
In this application,namespaces andSQL
you'll use the classes, andNorthwind
Server how to integrate bothYou'll
database. with read data from the Customers
ADO.NET.
table using the same CustomerId,ContactName, and ContactTitle columns you selected in Listing
1-1 and display data in a DataGrid control.
Table of Contents
Begin your first ADO.NET application by launching VS .NET and by creating a new project using File
Applied
New ADO.NETBuilding Data-Driven
Project. Choose Visual Solutionsand select the Windows Application template from the
Basic Projects
Introduction
available templates, name your project DataGridSamp, and click OK.
Chapter 1 - ADO.NET Basics
Clicking2 the
Chapter OK button
- Data creates
Components inaVisual
Windows
Studioapplication
.NET project. Now you read data from the SQL Server
Northwind database and display data in a DataGrid
Chapter 3 - ADO.NET in Disconnected Environments control. This example shows the Customers table
data in a DataGrid control.
Chapter 4 - ADO.NET in Connected Environments
Chapter 5 - Handling ADO.NET Events
Drag a DataGrid control from the Toolbox onto the form using Toolbox Window Forms and then resize
Chapter
it. Also 6drag
- Integrating
a Button XML withonto
control ADO.NET
the form and assign it a Text property of Fill. Now double-click the
Chapter
button to write a click event handler forForms
7 - Data Binding and Windows Data-Bound
the button. Controls
Fill data from a database to the DataGrid on the Fill
Chapter 8 - Constraints
button click and Data Relations
event handler.
Chapter 9 - ADO.NET Exception Handling
To access
Chapter 10 -SQL Server,
Working withyou
the use
ODBCthe.NET
Sql Data
.NETProvider
data provider, which is defined in the
11 - Stored Procedures namespace.
System.Data.SqlClient
Chapter and Views Before adding this namespace class, you need to import the
namespace
Chapter using the
12 - Oracle, Imports
SQLXML, statement.
and Other Add the
.NET Data following two lines in the beginning of your application:
Providers
Chapter 13 - Developing a Custom Data Provider
Imports
Chapter 14 -System.Data
Developing Database Web Applications using ASP.NET
Imports
Chapter 15 -System.Data.SqlClient
Using ADO.NET in Xml Web Services
Chapter 16 - ASP.NET Server Controls and Data Binding
Chapter 17 - Building Real-World Web Applications
You implement your ADO.NET routine inside this method. To retrieve data from the database, you first
Chapter 18 - Object-Relational Mapping in .NET
need to connect to the database using a Connection object. The DataAdapter is the bridge between
Chapter
the data19source
- Mapped
(sql)Objects:
and thePerformance Considerations
DataSet (memory). and Data Bindingis constructed with two elements in
The DataAdapter
Chapter 20 - COM Interoperability and ADO.NET
this example: a SQL SELECT command to tell the DataAdapter which data to extract into the DataSet
Chapter
and the21 - Messaging object to tell the DataAdapter how to connect to the data source. In this example,
Connection
Chapter
select the -CustomerId,
22 SQL Server and ADO.NET: Notes
ContactName, andonContactTitle
Performance column data from the Customers table.
Appendix A - Relational Databases: Some Basic Concepts
After creating a DataAdapter, the next step is to create and fill data from a DataAdapter to a DataSet,
which you
Appendix B -do by making
Commonly a call
Used SQLtoStatements
the Fill method of DataAdapter. The Fill method takes two
parameters:
Appendix a DataSet
C - ADO.NET and a database
Frequently table name.
Asked Questions
Index
Finally, you'll want to display the data from the Customers table in the DataGrid control. You do this by
List of Figures
simply binding the DataSet to the DataGrid through its DefaultViewManager (Chapters 2 and 4
List of Tables
discussDataViewManager in more detail) by using the DataGrid'sDataSource property. You just set
List of Listings
theDataSource property of the DataSet'sDefaultViewManager.
List of Sidebars
Listing 1-2 shows the button click event handler. As you can see, this code creates a connection using the
localhost server and the Northwind database, and you create a DataAdapter using the Customers table.
After that, create a DataSet object and call the DataAdapter'sFill method. After that, bind
DataSet.DefaultViewManager to the DataGrid using the DataSource property of the DataGrid.
Listing 1-2: Viewing Data from a SQL Server Database to a DataGrid Control
The second tab of this wizard, Connection, lets you pick your server and corresponding data source. The
drop-down list displays all the available servers. Our server is a SQL Server with the default name
localhost. After selecting a server, the Database drop-down list displays all the available databases on the
server. Select the Northwind database in this example. You can also pick what security mode you want to
use for your connection on this tab. You can use the user ID and password of a SQL Server or use the
Windows NT Integrated security option. By clicking the Test Connection button, you can make sure your
database connection is working. If you've provided an incorrect user ID or password, the test will throw an
error.
The third tab, Advanced, is for setting connection timeout and access permissions. You can give this
connection read, write, or other permissions using the Advanced tab. The last tab, All, shows you all
properties of the connection in a list, such as server name, connection timeout, data source, initial catalog
(database name),Applied ADO.NET: Building Data-Driven Solutions
security, and other network options. You can also edit this data from this tab by just
by Mahesh Chand and
double-clicking a particular property David
and Talbot
editing the value of it.ISBN:1590590732
Apress 2003 (928 pages)
After adding a data connection,
This you'll
text provides see that
extensive the wizard
coverage adds a node
of ADO.NET technology
including ADO.NET internals,
(Servername.DatabaseName.dbo) to thenamespaces, classes,root
Data Connections andnode. If you expand this node, you
interfaces,
can see the database and
objects takes
such asatables,
comprehensive look at
views, stored XML
procedures, and functions.
namespaces and classes, and how to integrate both with
ADO.NET.
Managing and Viewing Data
Table of Contents
As mentioned earlier, the Server Explorer not only lets you add server and database connections, but it
Applied ADO.NETBuilding
also lets you manage andData-Driven
view data. Solutions
You can add, update, and delete data from a database. Of course,
Introduction
you must have read and write permissions on the server to read and write data. The Server Explorer also
Chapter 1 options
provides - ADO.NET Basics new databases and objects, including tables, views, stored procedures, and
for creating
Chapter 2 - can
so on. You Datado
Components in Visual
this from both Studio (Data
root nodes .NET Connections or Servers).
Chapter 3 - ADO.NET in Disconnected Environments
The Server
Chapter Explorer shows
4 - ADO.NET database
in Connected objects in a tree structure. Each database is a tree node of the
Environments
server. As -you
Chapter 5
expand the Northwind database node, for example, you can see its children listed as tables,
Handling ADO.NET Events
stored procedures, and views.
Chapter 6 - Integrating XML with ADO.NET
Chapter 7 - Data
If you expand thisBinding and Windows
connection Forms Data-Bound
by double-clicking it, you'll Controls
notice it shows tables, views, and stored
Chapter 8 - Constraints
procedures. and Data
You can further Relations
expand these items to see them in more detail.
Chapter 9 - ADO.NET Exception Handling
Note
Chapter 10 We discuss
- Working stored
with procedures
the ODBC and Provider
.NET Data views in more detail in Chapter 11.
Chapter 11 - Stored Procedures and Views
Besides showing a list of database objects such as tables, views, stored procedures, and functions, the
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Server Explorer also lets you retrieve, add, edit, and delete data from a data source. You can always
Chapter 13 - Developing a Custom Data Provider
double-click to view the data of a table. Alternatively, right-clicking a database object (such as a table)
Chapter 14you
provides - Developing Database
menu options basedWeb
on Applications using
the selection. ForASP.NET
example, you can right-click and then select the
Chapter 15 - Using ADO.NET in Xml Web Services
Retrieve Data from Table menu option to retrieve data from that table.
Chapter 16 - ASP.NET Server Controls and Data Binding
Now, if 17
Chapter you- Building
retrieve data from the
Real-World WebEmployees table by double-clicking or using the Retrieve Data from
Applications
Table option,
Chapter data will be displayed
18 - Object-Relational Mappingininan editable grid. You can edit this data at any time-again, assuming
.NET
you have
Chapter 19 the correctObjects:
- Mapped permissions. For example,
Performance to delete
Considerations a row
and DataorBinding
a collection of rows, select the rows and
hit Delete
Chapter 20 or right-click
- COM the selected
Interoperability and rows and then hit the Delete option. The right-click option of the grid
ADO.NET
also provides you options to move to the grid's first, next, previous, and last records.
Chapter 21 - Messaging
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Appendix A - Relational Databases: Some Basic Concepts
Appendix B - Commonly Used SQL Statements
Appendix C - ADO.NET Frequently Asked Questions
Index
List of Figures
List of Tables
List of Listings
List of Sidebars
Using Visual Data
Applied Components
ADO.NET: Building Data-Driven Solutions
by Mahesh Chand and David Talbot ISBN:1590590732
At this time, ADO.NET
Apresshas three
2003 (928base
pages)data providers and multiple add-on data providers to work with
various kinds of data sources, including SQLcoverage
This text provides extensive Server, OLEDB datatechnology
of ADO.NET sources, and ODBC data sources. What
do we mean by base including ADO.NET internals, namespaces, classes, and only three data providers; now, based
data providers? Well, initially Microsoft released
interfaces, and
on additional requirements, takes aand
Microsoft comprehensive
third parties look at XML new data providers to the library. For
are adding
example, Microsoft,namespaces andCore
Oracle, and classes,
Laband how to Development
Software integrate both provide
with three different data providers for
ADO.NET.
the Oracle database. (We discuss these new data providers in later chapters.) The main class hierarchy
model of these data providers remains the same, so programmers will have no problem switching between
dataof
Table providers.
ContentsSome of these data providers are OleDb, Sql, Odbc, and Oracle. In this chapter, we
concentrate on the OleDbData-Driven
Applied ADO.NETBuilding and Sql data providers. Later chapters discuss the ODBC, Oracle, and other data
Solutions
providers.
Introduction
Chapter 1 - ADO.NET Basics
Tip You can even write your own custom data provider. ADO.NET provides a set of interfaces, which
Chapter 2 - Data Components in Visual Studio .NET
you must implement to write your own data provider. Chapter 13 of this book covers writing custom
Chapter 3data
- ADO.NET in Disconnected Environments
providers.
Chapter 4 - ADO.NET in Connected Environments
You can
Chapter 5 use the dataADO.NET
- Handling providerEvents
components at design-time in VS .NET. The data provider components are
available
Chapter 6 at design-timeXML
- Integrating via with
the Toolbox.
ADO.NETThe Toolbox's Data tab shows you the available data controls in
VS .NET.
Chapter 7 Some
- Data of the components
Binding you
and Windows mayData-Bound
Forms see are DataSet,
ControlsDataView, SqlConnection,
SqlCommand,
Chapter SqlDataAdapter,
8 - Constraints OleDbConnection,OleDbCommand,OleDbDataAdapter,
and Data Relations
OdbcCommand,
Chapter 9
OdbcCommandBuilder,OdbcConnection, and OdbcDataAdapter. These
- ADO.NET Exception Handling
components are available only when you're in a design view.
Chapter 10 - Working with the ODBC .NET Data Provider
Chapter
Tip11 - Stored
You Procedures
can open Toolboxand
by Views
using the View Toolbox menu item.
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
As mentioned
Chapter briefly inaChapter
13 - Developing Custom 1, theProvider
Data .NET Framework Library contains many ADO.NET data providers,
including
Chapter 14 OleDb, Sql, and
- Developing Odbc.Web
Database The Applications
OleDb datausing
provider wraps up the native OLE-DB COM Application
ASP.NET
Programming
Chapter Interface
15 - Using (API)
ADO.NET for working
in Xml with OLE-DB data sources. To access an OLE-DB data source,
Web Services
you need
Chapter 16 to install anServer
- ASP.NET OLE-DB data and
Controls provider
Data for that database. Sql data providers work with SQL Server 7
Binding
or later17
Chapter databases.
- BuildingOdbc data providers
Real-World wrap up the ODBC API to work with ODBC data sources (with the
Web Applications
help of the ODBC Administration and ODBC drivers). Chapter 4 discusses these data providers in more
Chapter 18 - Object-Relational Mapping in .NET
detail. Microsoft and other vendors might introduce more data providers, which you can add to the library
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
later.
Chapter 20 - COM Interoperability and ADO.NET
Chapter 21 - Messaging
In the .NET Framework, each of these data providers has its own namespaces. For instance, the
Chapter 22 - SQL Server and
System.Data.OleDb ADO.NET:consists
namespace Notes onofPerformance
classes belonging to the OleDb data providers. All of these
namespace
Appendix classes start
A - Relational with OleDb.
Databases: Some The
BasicMicrosoft.Data.ODBC
Concepts and System.Data.SqlClient
namespaces
Appendix consist ofUsed
B - Commonly classes
SQL belonging
Statementsto the Odbc and Sql data providers, respectively. Similar to
OleDb, classes
Appendix in Odbc
C - ADO.NET start with
Frequently Odbc,
Asked and classes in SqlClient start with Sql.
Questions
Index
In VS .NET, some of these classes (or objects) are available from the Toolbox; you can drag them onto a
List of Figures
form like any other Windows control in the Toolbox. These controls are called data components.
List of Tables
List
VSof.NET
Listings
also provides a set of data-bound controls. The DataGrid,ListBox, and DataList are good
List of Sidebars
examples of some of these data-bound controls. It's fairly easy to work with these controls. You just set a
few properties, and they're ready to display your data. For example, setting a DataGrid control's
DataSource property displays data from a DataSet object. We use these data-bound controls in the
examples throughout this book. In the next section, we discuss how you can add these components to your
Windows Forms applications and set their properties and methods at design-time with the help of the .NET
wizards.
Each data provider has a Connection class, and if you're using the VS .NET IDE, you can see these class
objects as components in the Data tab of the Toolbox. For example, the SqlConnection,
OdbcConnection, Applied ADO.NET: Building Data-Driven
and OleDbConnection class objectsSolutions
represent a connection for the Sql, Odbc, and
by Mahesh Chand and
OleDb data providers, respectively: David Talbot ISBN:1590590732
Apress 2003 (928 pages)
SqlConnection creates
This text andextensive
provides managescoverage
SQL Server database
of ADO.NET connections.
technology
including ADO.NET internals, namespaces, classes, and
creates
interfaces,
OdbcConnection and manages
and takes connections
a comprehensive look attoXML
ODBC data sources.
namespaces and classes, and how to integrate both with
ADO.NET.creates and manages connections to OLE-DB data sources.
OleDbConnection
In the VS .NET IDE, you can create a Connection in many ways. You can use the IDE to add a
Table of Contents
Connection object to a project, create it programmatically, or use DataAdapters that automatically
Applied
create ADO.NETBuilding Data-Driven
a Connection object for you.Solutions
In this chapter, we concentrate on adding a connection through the
Introduction
VS .NET IDE.
Chapter 1 - ADO.NET Basics
Chapter 2 - Data Components in Visual StudioIDE
.NETvs. Manual Coding
Chapter 3 - ADO.NET in Disconnected Environments
In some
Chapter 4
cases, you may not know if you should use the IDE or write code manually. Actually, creating a
- ADO.NET in Connected Environments
connection and other objects such as a Command manually is usually much better. Those types of
Chapter 5 - Handling ADO.NET Events
objects only require a few lines of code, and creating them manually allows you to know where the
Chapter 6 - Integrating XML with ADO.NET
code is and what it means. If you use the VS .NET IDE, it adds a connection and other data
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
components but sometimes also writes lots of code that is difficult to understand. For example, adding
Chapter 8 - Constraints
aDataAdapter and aData
adds Relations
great deal of code that you may not need. If you want to modify it, you'll almost
Chapter 9 - ADO.NET Exception Handling
certainly get lost if you don't have a lot of experience.
Chapter 10 - Working with the ODBC .NET Data Provider
Now,
Chapter 11 your nextProcedures
- Stored question probably is, "Why do I need to use the IDE at all?" Well, the IDE may help you
and Views
if you
Chapter 12 don't know
- Oracle, how to and
SQLXML, create connection
Other .NET Datastrings and other objects because it writes code for you.
Providers
Basically,
Chapter the IDE isa useful
13 - Developing Customfor part-time
Data ADO.NET developers-those who write non-database-related
Provider
code
Chapter 14 but occasionally
- Developing use ADO.NET.
Database It's alsousing
Web Applications useful for beginners, who want to have their application
ASP.NET
ready
Chapter 15 -and running
Using in nointime.
ADO.NET But after
Xml Web completing this book, I bet you'll hate using IDE.
Services
Chapter 16 - ASP.NET Server Controls and Data Binding
Chapter 17 - Building Real-World Web Applications
Chapter 18 - Object-Relational
The easiest Mapping to
way to add a connection in .NET
a project in VS .NET is to drag a connection component
Chapter 19 - Mapped OleDbConnection,
(SqlConnection, Objects: Performance Considerations and Data from
or OdbcConnection) Binding
the Toolbox's Data tab to a form.
Chapter 20 -you
After that, COM Interoperability
can and ADO.NET
set the connection's properties using the Properties window. For this demonstration, drop
aSqlConnection
Chapter from the Toolbox onto the form. You can set the SqlConnection properties from the
21 - Messaging
Properties
Chapter 22 -window by right-clicking
SQL Server and ADO.NET: theNotes
SqlConnection and selecting the Properties menu item.
on Performance
Appendix A - Relational Databases: Some Basic Concepts
Note that the default connection name is the class name with a unique name appended to it. Because this
Appendix B - Commonly Used SQL Statements
is the first connection, the name is sqlConnection1.
Appendix C - ADO.NET Frequently Asked Questions
Index
As you can see in the Properties window, a connection's properties include Database,
List of Figures
ConnectionTimeout, DataSource,PacketSize,WorkstationId,Name, and
List of Tables
ConnectionString.
List of Listings
List ofNote The connection properties depend on the data provider. Some properties may not be available for
Sidebars
some data providers. For example, the WorkstationId property is available in Sql data
providers but not in OleDb or ODBC data providers.
For this example, we use the database server name MCB instead of localhost. The SQLConnection string
for server MCB looks like following:
Applied ADO.NET: Building Data-Driven Solutions
data source=MCB;initial catalog=Northwind;integrated security=SSPI;" & _
by Mahesh Chand and David Talbot ISBN:1590590732
"persist security info=False;workstation id=MCB;packet size=4096
Apress 2003 (928 pages)
This text provides extensive coverage of ADO.NET technology
including ADO.NET internals, namespaces, classes, and
interfaces, and takes a comprehensive look at XML
Note In Chapter 4, we discuss
namespaces a connection
and classes, and howand
to its properties
integrate bothinwith
more detail and show how to set them
programmatically.
ADO.NET. You can also use a user ID and password in a connection string.
In this first project, you'll learn how to create SQL DataAdapters, read data from a SQL Server data
source, and display the data from a DataAdapter to a DataGrid control. After completing these steps,
Applied ADO.NET: Building Data-Driven Solutions
you'll see how easy it is to develop database applications using the Data Adapter Configuration Wizard.
by Mahesh Chand and David Talbot ISBN:1590590732
Apress
Step 1: Selecting a Project
2003Template
(928 pages)
This text provides extensive coverage of ADO.NET technology
To create a new Windows application
including ADO.NET using VS
internals, .NET, select
namespaces, File and
classes, New Project Visual Basic Projects
Windows Application.
interfaces, andselect
Next, takes an
a comprehensive look at XML
appropriate directory and type your project name.
namespaces and classes, and how to integrate both with
Step 2: Adding aADO.NET.
DataGrid Control to the Form
Now add a DataGrid control to the form. You do this by just dragging a DataGrid control from the
Table of Contents
Toolbox's Windows Forms category to the form and resizing it.
Applied ADO.NETBuilding Data-Driven Solutions
Step 3: Adding a DataAdapter Component
Introduction
Chapter 1 - ADO.NET Basics
Next, drag a SqlDataAdapter control from the Toolbox's Data category to the form. As you drop the
Chapter 2 - Data Components in Visual Studio .NET
SqlDataAdapter the Data Adapter Configuration Wizard pops up. The following sections walk you
Chapter 3 - ADO.NET in Disconnected Environments
through this wizard.
Chapter 4 - ADO.NET in Connected Environments
Chapter
Welcome5 -Page
Handling ADO.NET Events
Chapter 6 - Integrating XML with ADO.NET
The first
Chapter 7 page of Binding
- Data this wizard
and is just a welcome
Windows screen. Click
Forms Data-Bound the Next button to move to the next screen.
Controls
Chapter 8 - Constraints and Data Relations
Choose Your Data Connection Page
Chapter 9 - ADO.NET Exception Handling
Chapter 10 - Working
The second page of with the ODBC
the wizard lets.NET
you Data Provider
create a new connection or pick from a list of available connections
on your11
Chapter machine.
- StoredAll availableand
Procedures connections
Views are listed in the drop-down list. If you don't have any
connections
Chapter listed inSQLXML,
12 - Oracle, the list, and
you Other
can click
.NETthe New
Data Connection button, which launches the Data Link
Providers
Properties
Chapter 13 -Wizard (discussed
Developing previously
a Custom in the "Adding a New Connection" section).
Data Provider
Chapter 14 - Developing Database Web Applications using ASP.NET
Choose a Query Type
Chapter 15 - Using ADO.NET in Xml Web Services
Chapter 16page
The next - ASP.NET
of theServer
wizardControls and Data
is for selecting a Binding
SQL query type. If you see this page, three options are
Chapter 17 - Building Real-World Web
available for the SQL Server connection:Applications
Chapter 18 - Object-Relational Mapping in .NET
The
Chapter 19Use SQL Statement
- Mapped option allows
Objects: Performance you to createand
Considerations a new
DataSQL query.
Binding
Chapter 20 - COM Interoperability and ADO.NET
The Create New Stored Procedure option allows you to create a new stored procedure.
Chapter 21 - Messaging
Chapter
The22Use
- SQL ServerStored
Existing and ADO.NET: Notes
Procedure on Performance
option allows you to select a stored procedure from the existing
stored
Appendix A - procedures.
Relational Databases: Some Basic Concepts
Appendix B - Commonly Used SQL Statements
Note The last two options aren't available for databases that don't support stored procedures.
Appendix C - ADO.NET Frequently Asked Questions
Index
Generate the SQL Statement
List of Figures
The
List of next page of the Data Adapter Configuration Wizard lets you build a SQL statement or a stored
Tables
procedure.
List of ListingsYou can type a SQL statement directly into the text box, or you can click the Query Builder
button
List to use the Query Builder to build your SQL statement.
of Sidebars
Query Builder
The Query Builder option lets you pick tables from your data source. First, select the Employees table to
read in the Employee data. You actually have the option of selecting as many as tables you want, but for
now select only one table and click the Add button. After clicking the Add button, the Query Builder provides
you with an option to select columns of the table. You can check *(All Columns) to select all the columns of
a table, or you can check only the columns you want to participate in the SQL statement.
If you've ever used the New Query Wizard in Microsoft Access, you'll find that the Query Builder is similar to
it. In Access, you can create queries by dragging tables and their columns to the grid (or checking the
columns), and the Query Builder builds a SQL query for your action.
In this sample, select EmployeeID,FirstName, and LastName from the Employees table to build your
SQL statements. Applied
The SQLADO.NET:
statementBuilding Data-Driven Solutions
after selecting these three columns looks like this:
by Mahesh Chand and David Talbot ISBN:1590590732
Apress 2003 (928 pages)
SELECT EmployeeID, LastName, FirstName FROM Employees
This text provides extensive coverage of ADO.NET technology
including ADO.NET internals, namespaces, classes, and
interfaces, and takes a comprehensive look at XML
You can even type this SQL statement
namespaces directly
and classes, intotothe
and how text box.both with
integrate
ADO.NET.
Note You can even write your own SQL statement if you don't want to use the Query Builder. For
performance reasons, if you only want few columns, then use column names instead of using
Table of Contents
SELECT * statements.
Applied ADO.NETBuilding Data-Driven Solutions
One more button is available on this page: Advanced Options. By clicking the Advanced Options button, you
Introduction
launch 1the- Advanced
Chapter SQL Generation Options page. On this page, there are three options: Generate Insert,
ADO.NET Basics
Update,
Chapter 2 and Delete
- Data Statements;
Components Use Optimistic
in Visual Concurrency; and Refresh the DataSet. By default all three
Studio .NET
options are checked. If you don't want to generate INSERT,UPDATE, or DELETE SQL statements, you
Chapter 3 - ADO.NET in Disconnected Environments
should uncheck the first check box.
Chapter 4 - ADO.NET in Connected Environments
Chapter 5 - ADO.NET
By default, Handling ADO.NET Events concurrency. If you don't want your program to implement optimistic
uses optimistic
Chapter 6 - Integrating XML with
concurrency, you should uncheck ADO.NET
the second check box.
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
View Wizard
Chapter Results and Data Relations
8 - Constraints
Chapter 9 - ADO.NET Exception Handling
The View Wizard Results page shows you the action being taken by the wizard. If everything went well, the
Chapter 10 - Working with the ODBC .NET Data Provider
wizard generates a message saying, "The data adapter was configured successfully." For this example,
Chapter 11 - section
the Details Stored Procedures
shows thatand
the Views
wizard has generated SQL SELECT,INSERT,UPDATE, and DELETE
Chapter 12 - Oracle, SQLXML,
statements and mappings. and Other .NET Data Providers
Chapter 13 - Developing a Custom Data Provider
Now you
Chapter 14can click the Finish
- Developing button
Database WebtoApplications
complete the process.
using ASP.NET
Chapter 15 - Using ADO.NET in Xml Web Services
Currently, if you examine the design surface at the bottom of the Form window, you'll see two components:
Chapter 16 - ASP.NET Server Controls and Data Binding
sqlConnection1 and sqlDataAdapter1. The wizard sets the properties of these components for you.
Chapter 17 - Building Real-World Web Applications
Now you can use the DataAdapter to populate your DataSets. Don't forget to resize the DataGrid you
Chapter 18 - Object-Relational Mapping in .NET
added to the project.
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
Chapter
Step 4:20 - COM and
Setting Interoperability
Reviewingand ADO.NET Properties
DataAdapter
Chapter 21 - Messaging
Now that you have a DataAdapter on your form, let's look at the SqlDataAdapter component
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
properties. You can see its properties by right-clicking the adapter and selecting the Properties menu item.
Appendix A - Relational Databases: Some Basic Concepts
The wizard also shows the available command properties, including InsertCommand,DeleteCommand,
Appendix B - Commonly Used SQL Statements
SelectCommand, and UpdateCommand.
Appendix C - ADO.NET Frequently Asked Questions
Index
You can set DataAdapter properties by clicking these properties. . A DataAdapter has four
List of Figures properties-SelectCommand, DeleteCommand, InsertCommand, and UpdateCommand-
SqlCommand
thatofall
List execute SQL commands on the data source. For example, if you look at the SelectCommand
Tables
property,
List you'll see the SQL SELECT statement.
of Listings
List of Sidebars
Note Chapter 4 covers SelectCommand,InsertCommand,UpdateCommand, and DeleteCommand
in more detail.
From the Properties window, you can also set CommandText,CommandType,Connection, and other
properties. If you double-click CommandText, it pops up the Query Builder where you can rebuild your
query.
A: Sometimes, you won't want to display your actual table names and their columns as
Table of Contents defined in a database. For instance, say you have a MyTable table with two fields, a0 and
a1. The Data-Driven
Applied ADO.NETBuilding table storesSolutions
a customer's information, and the fields a0 and a1 store customer
Introduction
names and addresses. If you display your table in data components such as a DataGrid,
it will display
Chapter 1 - ADO.NET Basics
the table name as MyTable and the column names as a0 and a1, which
makes no sense to user.
Chapter 2 - Data Components in Visual Studio .NET
Chapter 3 - ADO.NET in Disconnected
Using Environments
table mappings, you can change the table name to Customers Table. Using
Chapter 4 - ADO.NET in Connected
column mapping,Environments
you can change the columns' names to Customer Name and Customer
Chapter 5 - Handling ADO.NET
Address. Events
After this mapping, DataGrid will display the table name as Customers Table
Chapter 6 - Integrating
and theXML with ADO.NET
columns as Customer Name and Customer Address, which make more sense to
Chapter 7 a user. and
- Data Binding We discuss
Windowstable
Formsand column mappings
Data-Bound Controls in Chapter 3 in more detail.
Chapter 8 - Constraints and Data Relations
Chapter 9 - ADO.NET Exception Handling
Chapter 10 - Working with the ODBC .NET Data Provider
Chapter 11 - Stored Procedures and Views
If you click the TableMappings property, it opens the Table Mappings dialog box. The Table Mappings
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
dialog box has two columns: Source Table and Dataset Table (see Figure 2-1). If you have more than one
Chapter
table in13 - Developing a Custom
a DataAdapter, Dataall
you'll see Provider
the tables listed in the Source Table list box. By default the source
Chapter 14 - Developing Database Web Applications
table Table is listed in the list box. The Source Table using ASP.NET
column is a list of actual columns, and the Dataset
Chapter 15 - Using
Table column is aADO.NET
list of theincolumn
Xml Web Services
names used in the DataSet. By default, DataSet columns names
Chapter
are the16 - ASP.NET
same as the Server
sourceControls andisData
table. This Binding
useful when you want to use different names in a program. You
can change
Chapter 17 - Building
DataSet columnsWeb
Real-World by editing the column itself. Of course, you can't change source columns,
Applications
but you18
Chapter can reorder them by Mapping
- Object-Relational using theinColumn
.NET Mappings drop-down list.
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
Chapter 20 - COM Interoperability and ADO.NET
Chapter 21 - Messaging
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Appendix A - Relational Databases: Some Basic Concepts
Appendix B - Commonly Used SQL Statements
Appendix C - ADO.NET Frequently Asked Questions
Index
List of Figures
List of Tables
List of Listings
List of Sidebars
By using this dialog box, you can even delete columns from your mapping using the Delete button.
Note You should take the time to look at the code so you know what goes under the hood when you
use the IDE to write your code. It'll help you in the long run.
Table of Contents
Applied ADO.NETBuilding Data-Driven Solutions
All source code generated by the Windows form designer is defined in the InitializeComponent
Introduction
method of the file. Right-click your form and choose View Code. Upon examining the source code, you'll
Chapter 1 -the
see where ADO.NET
wizardBasics
has added two components, sqlConnection1 and sqlDataAdapter1, to your
Chapter
source 2file-as
Data Components
well in Visual Studio
as four SqlCommand .NET
components. Scroll down to the Windows Designer Generated
Chapter 3 - ADO.NET
Code option in Disconnected
and expand Environments
it. This reveals the contents of the InitializeComponent routine (see Listing 2-
Chapter
1). 4 - ADO.NET in Connected Environments
Chapter 5 - Handling ADO.NET Events
Listing62-1:
Chapter Added SqlXML
- Integrating Server Provider Components
with ADO.NET
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
Chapter
Friend 8 WithEvents
- Constraints and Data Relations
DataGrid1 As System.Windows.Forms.DataGrid
Chapter 9 - ADO.NET
Friend Exception
WithEvents Handling
SqlDataAdapter1 As System.Data.SqlClient.SqlDataAdapter
Friend
Chapter WithEvents
10 - Working with theSqlSelectCommand1
ODBC .NET Data ProviderAs System.Data.SqlClient.SqlCommand
Friend
Chapter WithEvents
11 - Stored SqlInsertCommand1
Procedures and Views As System.Data.SqlClient.SqlCommand
Friend
Chapter WithEvents
12 - Oracle, SQLXML, SqlUpdateCommand1 As System.Data.SqlClient.SqlCommand
and Other .NET Data Providers
Friend
Chapter WithEvents
13 - Developing SqlDeleteCommand1
a Custom Data Provider As System.Data.SqlClient.SqlCommand
Friend
Chapter WithEvents
14 - Developing SqlConnection1
Database Web ApplicationsAs System.Data.SqlClient.SqlConnection
using ASP.NET
Friend WithEvents DataSet11 As MyFirstADONetApp.DataSet1
Chapter 15 - Using ADO.NET in Xml Web Services
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Chapter 16 - ASP.NET Server Controls and Data Binding
Me.DataGrid1 = New System.Windows.Forms.DataGrid()
Chapter 17 - Building Real-World Web Applications
Me.SqlDataAdapter1 = New System.Data.SqlClient.SqlDataAdapter()
Chapter 18 - Object-Relational Mapping in .NET
Me.SqlSelectCommand1 = New System.Data.SqlClient.SqlCommand()
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
Me.SqlInsertCommand1 = New System.Data.SqlClient.SqlCommand()
ChapterMe.SqlUpdateCommand1
20 - COM Interoperability and
= ADO.NET
New System.Data.SqlClient.SqlCommand()
ChapterMe.SqlDeleteCommand1
21 - Messaging = New System.Data.SqlClient.SqlCommand()
Chapter 22 - SQL Server and
Me.SqlConnection1 = ADO.NET: Notes on Performance
New System.Data.SqlClient.SqlConnection()
Appendix A - Relational Databases: Some Basic Concepts
Appendix B - Commonly Used SQL Statements
Appendix C - ADO.NET Frequently Asked Questions
Search for the ConnectionString by hitting Ctrl+F to bring up VS .NET's Find dialog box. If you examine
Index
theof
List InitializeComponent()
Figures method, you'll see that the wizard sets SqlConnection's
ConnectionString
List of Tables property to the following:
List of Listings
Me.SqlConnection1.ConnectionString
List of Sidebars = _
"data source=localhost;initial catalog=Northwind;" & _
"integrated security=SSPI;persist " & _
"security info=False;workstation id=MCB;packet size=4096"
It also sets the CommandText property of the SqlCommand with the corresponding SELECT,INSERT,
UPDATE, and DELETE SQL statements. The Connection property of SqlCommand is set to
SqlConnection:
TableMe.SqlDataAdapter1.DeleteCommand
of Contents = Me.SqlDeleteCommand1
AppliedMe.SqlDataAdapter1.InsertCommand
ADO.NETBuilding Data-Driven Solutions = Me.SqlInsertCommand1
Introduction
Me.SqlDataAdapter1.SelectCommand = Me.SqlSelectCommand1
ChapterMe.SqlDataAdapter1.TableMappings.AddRange(_
1 - ADO.NET Basics
ChapterNew
2 -System.Data.Common.DataTableMapping()
Data Components in Visual Studio .NET { _
ChapterNew
3 -System.Data.Common.DataTableMapping("Table",
ADO.NET in Disconnected Environments "Employees", _
ChapterNew
4 -System.Data.Common.DataColumnMapping()
ADO.NET in Connected Environments { _
ChapterNew
5 -System.Data.Common.DataColumnMapping("EmployeeID",
Handling ADO.NET Events "EmployeeID"), _
ChapterNew
6 -System.Data.Common.DataColumnMapping("LastName",
Integrating XML with ADO.NET "LastName"), _
ChapterNew
7 -System.Data.Common.DataColumnMapping("FirstName",
Data Binding and Windows Forms Data-Bound Controls "FirstName")})})
Me.SqlDataAdapter1.UpdateCommand
Chapter 8 - Constraints and Data Relations
= Me.SqlUpdateCommand1
Chapter 9 - ADO.NET Exception Handling
Chapter 10 - Working with the ODBC .NET Data Provider
Chapter 11 - Stored Procedures and Views
It looks like the wizard did a lot of the work for you!
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Step 7:13
Chapter Filling the DataGrid
- Developing Control
a Custom with Data
Data Provider
Chapter 14 - Developing Database Web Applications using ASP.NET
Until now, you haven't had to write a single line of code. Now, though, you'll add few lines of code and then
Chapter 15 - Using ADO.NET in Xml Web Services
you'll be all set to see the data from your data source. Now you have two options. First, you can use the
Chapter 16 - ASP.NET Server Controls and Data Binding
typed DataSet to read the data, and second, you can create a DataSet object programmatically and fill it
Chapter 17 - Building Real-World Web Applications
using the SqlDataAdapter'sFill method.
Chapter 18 - Object-Relational Mapping in .NET
Chapter 19 - Mapped
You'll create Objects:
a DataSet Performance
object Considerations
programmatically anditData
and use to fillBinding
data in a DataGrid. Add the code in
Listing 20
Chapter 2-3-toCOM
the Interoperability
form load eventand
handler. As you can see, this code creates a DataSet object and fills it
ADO.NET
by calling
Chapter 21 SqlDataAdapter's
- Messaging Fill method. The Fill method of SqlDataAdapter fills data from a
22 - SQL to
DataAdapter
Chapter the DataSet.
Server You Notes
and ADO.NET: call the
onFill method in the FillDBGrid method. Once you have a
Performance
DataSet
Appendix A -containing
Relational data, you can
Databases: do anything
Some with it, including creating views for that data. In this example,
Basic Concepts
you set aB DataGrid
Appendix - Commonlycontrol's
Used SQL Statements property to the DataSet.DefaultViewManager, which
DataSource
binds theC DataSet
Appendix - ADO.NETobject to theAsked
Frequently DataGrid control.
Questions
Index
Listing 2-3: Form's Load Event Handler
List of Figures
List of Tables
Private
List Sub Form1_Load(ByVal sender As System.Object, _
of Listings
ByVal e As System.EventArgs) Handles MyBase.Load
List of Sidebars
Dim ds As DataSet = New DataSet()
SqlDataAdapter1.Fill(ds)
DataGrid1.DataSource = ds.DefaultViewManager
End Sub
Another option is to use the typed DataSet you generated using the Generate DataSet option. The wizard
added an instance of DataSet1 called DataSet11 to the project. Now just call the Fill method of
DataAdapter and bind the DataSet's default view to the DataGrid. Just write the following two lines on
the form load event handler:
SqlDataAdapter1.Fill(DataSet11)
Applied ADO.NET:
DataGrid1.DataSource Building Data-Driven Solutions
= DataSet11.DefaultViewManager
by Mahesh Chand and David Talbot ISBN:1590590732
Apress 2003 (928 pages)
Finally, build andThis
run the
text project
providesusing eithercoverage
extensive of the two
of methods. The result looks like Figure 2-3. Easy,
ADO.NET technology
huh? including ADO.NET internals, namespaces, classes, and
interfaces, and takes a comprehensive look at XML
namespaces and classes, and how to integrate both with
ADO.NET.
Table of Contents
Applied ADO.NETBuilding Data-Driven Solutions
Introduction
Chapter 1 - ADO.NET Basics
Chapter 2 - Data Components in Visual Studio .NET
Chapter 3 - ADO.NET in Disconnected Environments
Chapter 4 - ADO.NET in Connected Environments
Chapter 5 - Handling ADO.NET Events
Chapter 6 - Integrating XML with ADO.NET
Figure 2-3: Output of the Employee data to a DataGrid control
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
Chapter 8 - Constraints and Data Relations
Chapter 9 - ADO.NET Exception Handling
Chapter 10 - Working with the ODBC .NET Data Provider
Chapter 11 - Stored Procedures and Views
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Chapter 13 - Developing a Custom Data Provider
Chapter 14 - Developing Database Web Applications using ASP.NET
Chapter 15 - Using ADO.NET in Xml Web Services
Chapter 16 - ASP.NET Server Controls and Data Binding
Chapter 17 - Building Real-World Web Applications
Chapter 18 - Object-Relational Mapping in .NET
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
Chapter 20 - COM Interoperability and ADO.NET
Chapter 21 - Messaging
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Appendix A - Relational Databases: Some Basic Concepts
Appendix B - Commonly Used SQL Statements
Appendix C - ADO.NET Frequently Asked Questions
Index
List of Figures
List of Tables
List of Listings
List of Sidebars
Using DataSet and
Applied DataView
ADO.NET: BuildingComponents
Data-Driven Solutions
by Mahesh Chand and David Talbot ISBN:1590590732
After discussing DataAdapters
Apress 2003 (928 and data connections, you should have a pretty good idea of how to take
pages)
advantage of the This
VS .NET design-time support
text provides extensive to develop
coverage databound
of ADO.NET Windows Form database
technology
applications. including ADO.NET internals, namespaces, classes, and
interfaces, and takes a comprehensive look at XML
TheDataSet andnamespaces
DataViewand components
classes, andare twotopowerful
how integrateand
botheasy-to-use
with components of the
ADO.NET model.ADO.NET.
In this section, you'll learn how to utilize DataSet and DataView components at
design-time. In Chapter 4, we discuss their properties and methods in more detail and show how to use
them programmatically. The DataSet and DataView components fall into the disconnected
Table of Contents
components category, which means you can use these components with or without data providers. We
Applied ADO.NETBuilding Data-Driven Solutions
discuss disconnected data components in Chapter 3.
Introduction
Chapter 1 - ADO.NET Basics
Understanding
Chapter Typed
2 - Data Components DataSets
in Visual Studio .NET in VS .NET
Chapter 3 - ADO.NET in Disconnected Environments
There are two types of DataSets: typed and untyped. As discussed in Chapter 1 (and in more detail in
Chapter 4 - ADO.NET in Connected Environments
Chapter 4), a typedDataSet has an XML schema attached to it. The XML schema defines members for
Chapter 5 - Handling ADO.NET Events
aDataSet corresponding to database table columns, and you can access data through these columns.
Chapter 6 - Integrating XML with ADO.NET
Untyped datasets are ones that are created at runtime and don't have a schema attached to them. In the
Chapter 7 section,
following - Data Binding
we showandyou
Windows Forms
how you can Data-Bound Controls
generate typed datasets using a VS .NET wizard.
Chapter 8 - Constraints and Data Relations
Generating
Chapter Typed
9 - ADO.NET DataSets
Exception Using
Handling a DataAdapter
Chapter 10 - Working with the ODBC .NET Data Provider
As you 11
Chapter saw earlier,Procedures
- Stored you can generate typed datasets by using the Generate Dataset option from a
and Views
DataAdapter's
Chapter Properties
12 - Oracle, dialog
SQLXML, and box..NET
Other AndData
as mentioned
Providers earlier, the Generate DataSet option adds an
XML schema to the project and also adds a class to the project inherited from the DataSet class. The
Chapter 13 - Developing a Custom Data Provider
designer looks like Figure 2-4.
Chapter 14 - Developing Database Web Applications using ASP.NET
Chapter 15 - Using ADO.NET in Xml Web Services
Chapter 16 - ASP.NET Server Controls and Data Binding
Chapter 17 - Building Real-World Web Applications
Chapter 18 - Object-Relational Mapping in .NET
Figure 2-4: ADataSet's Properties window showing a typed DataSet
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
Chapter 20 - COM Interoperability and ADO.NET
Again, you can see a typed DataSet's properties by right-clicking the DataSet and using the Properties
Chapter 21 - Messaging
menu option.
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
EveryDataSet
Appendix generated
A - Relational by theSome
Databases: IDE creates an XML schema for the DataSet. If you look at the bottom
Basic Concepts
of the Properties
Appendix window
B - Commonly of SQL
Used a DataSet, you'll see two links: View Schema and DataSet Properties. The
Statements
View Schema
Appendix option Frequently
C - ADO.NET lets you view the Questions
Asked DataSet schema, and the DataSet Properties hyperlink lets you
set the DataSet properties. By following these links you can also set the DataSet's column names and
Index
other
List properties.
of Figures
List of Tables
Now you can use this DataSet as discussed earlier.
List of Listings
List of Sidebars
Adding a Typed DataSet
In the previous discussion, you saw how you can generate DataSet objects from a DataAdapter. There
are also other ways to create a typed DataSet object.
You can click the Project menu and choose Add New Item. This brings up the Add New Item window
where you'll find the DataSet template (see Figure 2-5). The default name of the DataSet template is
DataSet1.xsd, but you can change it by entering something in the Name text box.
Applied ADO.NET: Building Data-Driven Solutions
by Mahesh Chand and David Talbot ISBN:1590590732
Apress 2003 (928 pages)
This text provides extensive coverage of ADO.NET technology
including ADO.NET internals, namespaces, classes, and
interfaces, and takes a comprehensive look at XML
namespaces and classes, and how to integrate both with
ADO.NET.
Table of Contents
Applied ADO.NETBuilding Data-Driven Solutions
Introduction
Chapter 1 - ADO.NET Basics
Chapter 2 - Data Components in Visual Studio .NET
Figure
Chapter 3 - 2-5: Creating
ADO.NET a typed DataSet
in Disconnected from the Add New Item window
Environments
Chapter 4 - ADO.NET in Connected Environments
After adding the DataSet, the designer creates an XSD (XML Schema) file and adds it your project area.
Chapter 5 - Handling ADO.NET Events
By default the schema is empty the first time you add a DataSet schema using the Add New Item. You
Chapter 6 - Integrating XML with ADO.NET
can see the contents of a DataSet schema by double-clicking DataSet1.xsd in the Solution Explorer.
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
As you can see from Figure 2-6, the designer has two options: the Server Explorer and the Toolbox. If you
Chapter 8 Server
click the - Constraints
Explorerand Data
link, Relations the Server Explorer. The XML designer has its own Toolbox,
it launches
Chapter 9 - ADO.NET Exception Handling
which contains various XML schema items.
Chapter 10 - Working with the ODBC .NET Data Provider
Chapter 11 - Stored Procedures and Views
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Chapter 13 - Developing a Custom Data Provider
Chapter 14 - Developing Database Web Applications using ASP.NET
Chapter 15 - Using ADO.NET in Xml Web Services
Chapter 16 - ASP.NET Server Controls and Data Binding
Chapter 17 - Building Real-World Web Applications
Chapter 18 - Object-Relational Mapping in .NET
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
Chapter 20 - COM Interoperability and ADO.NET
Chapter 21 - Messaging
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Appendix A - Relational Databases: Some Basic Concepts
Appendix B - Commonly Used SQL Statements
Appendix C - ADO.NET Frequently Asked Questions
Index
Figure 2-6: EmptyDataset1.xsd in the VS .NET IDE
List of Figures
List of Tables
The
List of next step is to fill this XML schema with data and connect to a database. The easiest way to do this is
Listings
to use
List the Server Explorer. Open the Server Explorer by clicking the Sever Explorer link in the designer.
of Sidebars
You can expand any database and simply drop a database object such as a table, a view, or a stored
procedure on the designer from the Server Explorer. You can even drop multiple database objects. To
keep it simple, drop only one table, the Employees table from the SQL Server Northwind database.
Dragging the Employees table to the designer adds one XML schema (see Figure 2-7).
Applied ADO.NET: Building Data-Driven Solutions
by Mahesh Chand and David Talbot ISBN:1590590732
Apress 2003 (928 pages)
This text provides extensive coverage of ADO.NET technology
including ADO.NET internals, namespaces, classes, and
interfaces, and takes a comprehensive look at XML
namespaces and classes, and how to integrate both with
ADO.NET.
Table of Contents
Applied ADO.NETBuilding Data-Driven Solutions
Introduction
Chapter 1 - ADO.NET Basics
Chapter 2 - Data Components in Visual Studio .NET
Chapter 3 - ADO.NET in Disconnected Environments
Chapter 4 - ADO.NET in Connected Environments
Chapter 5 - Handling ADO.NET Events
Chapter 6 - Integrating XML with ADO.NET
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
Figure
Chapter 8 - 2-7: Designand
Constraints viewData
of the DataSet's XML schema
Relations
Chapter 9 - ADO.NET Exception Handling
It also automatically adds the typed DataSet class that inherits from DataSet. If you go to the Class
Chapter 10 - Working with the ODBC .NET Data Provider
View, you can see the DataSet1 class. If you expand this class, you'll notice this class is derived from the
Chapter 11 - Stored Procedures and Views
DataSet class. You can explore the code added by the designer. However, you'll never use these class
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
members directly.
Chapter 13 - Developing a Custom Data Provider
Chapter 14 -have
Once you Developing
a typedDatabase
DataSet,Web
youApplications
can bind itusing
to anyASP.NET
data-bound control (as discussed earlier in this
Chapter 15 - Using ADO.NET in Xml Web Services
chapter).
Chapter 16 - ASP.NET Server Controls and Data Binding
Chapter 17 - Building Real-World Web Applications
Understanding the DataView
Chapter 18 - Object-Relational Mapping in .NET
ADataView
Chapter represents
19 - Mapped a view
Objects: of a DataSet
Performance object. and Data Binding
Considerations
Chapter 20 - COM Interoperability and ADO.NET
Chapter 21 - Messaging Question and Answer
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Appendix A - Relational Databases: Some Basic Concepts
Q: Why do I need a DataView when I can use a DataSet's
Appendix B - Commonly Used SQL Statements
DefaultViewManager?
Appendix C - ADO.NET Frequently Asked Questions
Index Answers
List of Figures
List of Tables
A:
List of Listings Actually, the DefaultViewManager provides a view of all the available tables in a
List of Sidebars DataSet. What if you want to display only one table? Or what if you want to filter or sort
data?
ADataView provides you with Filter and Sort properties; by using them you can filter and sort the
data. There are many occasions when you don't want all data from a table. You can apply a filter criteria
on a DataView and bind the DataView to the data-bound controls. You can also separate multiple
tables of a DataSet by associating each table with a DataViewl. For example, you can create a
DataSet with three tables and create three different DataView objects for each table. Once you have a
DataView object, you can attach it with any data-bound control, such as a DataGrid or a ComboBox
control using the data-bound control's DataSource property. Or you can filter only records based on a
date or an ID.
Applied ADO.NET: Building Data-Driven Solutions
by Mahesh
Note In this chapter, weChand and David
concentrate Talbot
on the VS .NET part of DataView. We discuss the DataView
ISBN:1590590732
class andApress
its members
2003 (928in more detail in Chapter 4.
pages)
This text provides extensive coverage of ADO.NET technology
Creating and attaching a DataView
including with a data
ADO.NET internals, source is classes,
namespaces, simple inand
the designer. In this sample, you'll
create and attachinterfaces,
a DataViewand takes
with aaDataSet.
comprehensive look
Before at XMLa DataView, though, you need to have a
creating
DataSet. namespaces and classes, and how to integrate both with
ADO.NET.
First, you create a DataAdapter by simply dragging a database table from the Server Explorer to the
form. This action adds a Connection and a DataAdapter to the application and makes them available
Table of Contents
at design-time. Second, you generate a DataSet from a DataAdapter by selecting the Generate
Applied ADO.NETBuilding Data-Driven Solutions
Dataset menu option available after right-clicking the DataAdapter.
Introduction
Chapter
Now you1 need
- ADO.NET
to addBasics
a DataView. You simply drag a DataView by dragging the DataView control from
Chapter
Toolbox2 -Data
Dataonto
Components in Visual
your form. Studioadds
This action .NETa DataView1 to the project.
Chapter 3 - ADO.NET in Disconnected Environments
Next, attach
Chapter DataView1
4 - ADO.NET to the DataSet.
in Connected You can do that by simply setting the Table property of the
Environments
DataView.
Chapter 5
The Table property of DataView1 lists the DataSet and DataSet tables. In this case,
- Handling ADO.NET Events
selectDataSet11.Employees as the Table property of DataView1 (see Figure 2-8).
Chapter 6 - Integrating XML with ADO.NET
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
Chapter 8 - Constraints and Data Relations
Chapter 9 - ADO.NET Exception Handling
Chapter 10 - Working with the ODBC .NET Data Provider
Chapter 11 - Stored Procedures and Views
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Chapter 13 - Developing a Custom Data Provider
Chapter 14 - Developing Database Web Applications using ASP.NET
Chapter 15 - Using ADO.NET in Xml Web Services
Chapter 16 - ASP.NET Server Controls and Data Binding
Chapter 17 - Building Real-World Web Applications
Chapter 18 - Object-Relational Mapping in .NET
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
Chapter 20 - COM Interoperability and ADO.NET
Chapter 21 - Messaging
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Appendix A - Relational Databases: Some Basic Concepts
Figure 2-8: DataView Properties window
Appendix B - Commonly Used SQL Statements
Appendix C - ADO.NET
This is where Frequently
the DataView Asked Questions
is useful. The DataView has two properties: Sort and RowFilter. The
Index
Sort property takes an expression with the name of the column followed by the sort order. For example, if
List
youofwant
Figures
to sort data based on the FirstName column in ascending order, you set the FirstName ASC
string
List as the Sort property of DataView.
of Tables
List of Listings
TheRowFilter property filters the data of a DataView. This property works as a WHERE clause of the
List of Sidebars
SELECT statement. The RowFilter property takes an expression with the column name and the criteria.
For example, if you want to retrieve records where the country is USA, you simply set "Country='USA'"
as the filter. As you can see in Figure 2-8, we set the RowFilter and Sort properties.
Once you have a DataView, you can bind it to a data-bound control such as a DataGrid by setting data-
bound control's DataSource property. To test this, you can drop a DataGrid control onto the form and
setDataGrid'sDataSource property as DataView1. You can simply set that from the Properties
window of DataGrid.
Now if you compile and run your project, you'll only see USA records sorted on the FirstName column
(see Figure 2-9).
Applied ADO.NET: Building Data-Driven Solutions
by Mahesh Chand and David Talbot ISBN:1590590732
Apress 2003 (928 pages)
This text provides extensive coverage of ADO.NET technology
including ADO.NET internals, namespaces, classes, and
interfaces, and takes a comprehensive look at XML
namespaces and classes, and how to integrate both with
ADO.NET.
Table of Contents
Figure
Applied 2-9: Sorted and
ADO.NETBuilding filtered data
Data-Driven in a DataGrid
Solutions
Introduction
Chapter 1 - ADO.NET Basics
Chapter 2 - Data Components in Visual Studio .NET
Chapter 3 - ADO.NET in Disconnected Environments
Chapter 4 - ADO.NET in Connected Environments
Chapter 5 - Handling ADO.NET Events
Chapter 6 - Integrating XML with ADO.NET
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
Chapter 8 - Constraints and Data Relations
Chapter 9 - ADO.NET Exception Handling
Chapter 10 - Working with the ODBC .NET Data Provider
Chapter 11 - Stored Procedures and Views
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Chapter 13 - Developing a Custom Data Provider
Chapter 14 - Developing Database Web Applications using ASP.NET
Chapter 15 - Using ADO.NET in Xml Web Services
Chapter 16 - ASP.NET Server Controls and Data Binding
Chapter 17 - Building Real-World Web Applications
Chapter 18 - Object-Relational Mapping in .NET
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
Chapter 20 - COM Interoperability and ADO.NET
Chapter 21 - Messaging
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Appendix A - Relational Databases: Some Basic Concepts
Appendix B - Commonly Used SQL Statements
Appendix C - ADO.NET Frequently Asked Questions
Index
List of Figures
List of Tables
List of Listings
List of Sidebars
Using the Data Form
Applied Wizard
ADO.NET: Building Data-Driven Solutions
by Mahesh Chand and David Talbot ISBN:1590590732
The Data Form Wizard
Apress is one (928
2003 most useful tools for developing database applications. You can use the Data
pages)
Form Wizard to develop your database application
This text provides extensive coveragewith
of viewing,
ADO.NETupdating,
technologyand deleting capabilities. This is
probably the fastest way to develop database applications in .NET
including ADO.NET internals, namespaces, classes, and (unless you're an extremely fast typist!).
interfaces, and takes a comprehensive look at XML
namespaces
In the following sections, you'lland classes,
use andForm
the Data how to integrate
Wizard bothawith
to write fully functional database application including
ADO.NET.
features such as inserting, updating, and deleting data without writing a single line of code. In this simple
example, you'll use the familiar Northwind database, and you'll use both the Customers and Orders tables to
build a data relationship between table data.
Table of Contents
Applied ADO.NETBuilding
First, you'll Data-Driven
create a Windows Solutions
application. Second, you'll add a Data Form Wizard to it and then call the Data
Introduction
Form Wizard from the main application. Like many parts of this book, this topic is in the form of tutorial. Just
Chapter 1 -simple
follow the ADO.NET Basics
steps, and in a few minutes you'll be able to run the application.
Chapter 2 - Data Components in Visual Studio .NET
Step 1:
Chapter 3 Selecting
- ADO.NET in a Project Template
Disconnected Environments
Chapter 4 - ADO.NET in Connected Environments
Create 5a new
Chapter Windows
- Handling by selecting File New Project Visual Basic Projects Windows Application
projectEvents
ADO.NET
and typing-MyDataFormWizardSamp
Chapter 6
as your application name.
Integrating XML with ADO.NET
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
Step 2: Adding a Data Form Wizard Item
Chapter 8 - Constraints and Data Relations
Chapter
Now add9 a- Data
ADO.NET
FormException Handling
Wizard by selecting Project Add New Item Data Form Wizard from the available
Chapter 10 - You
templates. Working with the
can type ODBC .NET Data
DataForm1.vb Provider
as the name of your DataForm class in the Name field of the dialog box
(see Figure
Chapter 11 - 2-10).
Stored (If you're using
Procedures andC# language, the filename would be DataForm1.cs.)
Views
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Chapter 13 - Developing a Custom Data Provider
Chapter 14 - Developing Database Web Applications using ASP.NET
Chapter 15 - Using ADO.NET in Xml Web Services
Chapter 16 - ASP.NET Server Controls and Data Binding
Chapter 17 - Building Real-World Web Applications
Chapter 18 - Object-Relational Mapping in .NET
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
Chapter 20 - COM Interoperability and ADO.NET
Chapter 21 - Messaging
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Appendix A - Relational Databases: Some Basic Concepts
Appendix B - Commonly Used SQL Statements
Appendix C - ADO.NET Frequently Asked Questions
Index
List of Figures
Figure 2-10: Adding a Data Form Wizard
List of Tables
List
Now of click
Listings
Open, which calls the Data Form Wizard.
List of Sidebars
Step 3: Walking through the Data Form Wizard
The first page of the wizard is a welcome page telling you what the wizard is about to do.
When you run the final program, you'll see how you can filter all orders for a customer based on the CustomerID.
As you can see from Figure 2-12, you need to pick one table as parent and another table as a child based on the
relationship between them. In this example, the Customers table is the parent table, and the Orders table is the
child table.
Applied ADO.NET: Building Data-Driven Solutions
by Mahesh Chand and David Talbot ISBN:1590590732
Apress 2003 (928 pages)
This text provides extensive coverage of ADO.NET technology
including ADO.NET internals, namespaces, classes, and
interfaces, and takes a comprehensive look at XML
namespaces and classes, and how to integrate both with
ADO.NET.
Table of Contents
Applied ADO.NETBuilding Data-Driven Solutions
Introduction
Chapter 1 - ADO.NET Basics
Chapter 2 - Data Components in Visual Studio .NET
Chapter 3 - ADO.NET in Disconnected Environments
Chapter 4 - ADO.NET in Connected Environments
Chapter 5 - Handling ADO.NET Events
Chapter 6 - Integrating XML with ADO.NET
Chapter 7 - 2-12:
Figure Data Binding andCustomers
Selecting Windows Forms
as theData-Bound
parent andControls
Orders as the child table to create the
Chapter relationship
8 - Constraints and Data
CustOrderRelation Relations
Chapter 9 - ADO.NET Exception Handling
Chapter 10 - Working with the ODBC .NET Data Provider
Step 8: Choosing Tables and Columns to Display on the Form
Chapter 11 - Stored Procedures and Views
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
The next page of the wizard lets you select which tables and columns you want to show on the form. For this
Chapter 13 select
example, - Developing
all the acolumns
Custom from
Data Provider
both of the tables (this is the default selection). As you can see in Figure 2-
Chapter 14 - Developing Database Web
13, the Customers table is the master, Applications using table
and the Orders ASP.NETis the detail table. On this page, you can select
Chapter 15 - Using ADO.NET in Xml Web Services
whatever column you want to display on the form.
Chapter 16 - ASP.NET Server Controls and Data Binding
Chapter 17 - Building Real-World Web Applications
Chapter 18 - Object-Relational Mapping in .NET
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
Chapter 20 - COM Interoperability and ADO.NET
Chapter 21 - Messaging
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Appendix A - Relational Databases: Some Basic Concepts
Appendix B - Commonly Used SQL Statements
Appendix C - ADO.NET Frequently Asked Questions
Index
List of Figures
List of Tables
List of Listings
List of Sidebars
Table of Contents
Applied ADO.NETBuilding Data-Driven Solutions
Introduction
Chapter 1 - ADO.NET Basics
Chapter 2 - Data Components in Visual Studio .NET
Chapter 3 - ADO.NET in Disconnected Environments
Chapter 4 - ADO.NET in Connected Environments
Chapter 5 - Handling ADO.NET Events
Chapter 6 - Integrating XML with ADO.NET
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
Chapter 8 - Constraints and Data Relations
Chapter 9 - ADO.NET Exception Handling
Chapter 10 - Working with the ODBC .NET Data Provider
Figure 2-14: Choosing between a grid and individual controls on the Data Form Wizard
Chapter 11 - Stored Procedures and Views
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
The output
Chapter 13 - of All Records
Developing in a Grid
a Custom Datalooks like Figure 2-15. After that you can resize or move the controls on the
Provider
form. 14 - Developing Database Web Applications using ASP.NET
Chapter
Chapter 15 - Using ADO.NET in Xml Web Services
Chapter 16 - ASP.NET Server Controls and Data Binding
Chapter 17 - Building Real-World Web Applications
Chapter 18 - Object-Relational Mapping in .NET
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
Chapter 20 - COM Interoperability and ADO.NET
Chapter 21 - Messaging
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Appendix A - Relational Databases: Some Basic Concepts
Appendix B - Commonly Used SQL Statements
Appendix C - ADO.NET Frequently Asked Questions
Index
List of Figures
List of Tables
List of Listings
Figure 2-15: Grid DataForm output
List of Sidebars
The second option, Single Record in Individual Controls, shows data in text boxes and provides you with
navigation controls. As you can see from Figure 2-16, the Single Record in Individual Controls option activates
Add, Delete, Cancel, and Navigation Controls check boxes. You can uncheck these check boxes if you don't
want to add those features to your project.
Applied ADO.NET: Building Data-Driven Solutions
by Mahesh Chand and David Talbot ISBN:1590590732
Apress 2003 (928 pages)
This text provides extensive coverage of ADO.NET technology
including ADO.NET internals, namespaces, classes, and
interfaces, and takes a comprehensive look at XML
namespaces and classes, and how to integrate both with
ADO.NET.
Table of Contents
Applied ADO.NETBuilding Data-Driven Solutions
Introduction
Chapter 1 - ADO.NET Basics
Chapter 2 - Data Components in Visual Studio .NET
Chapter 3 - ADO.NET in Disconnected Environments
Chapter 4 - ADO.NET in Connected Environments
Figure- 2-16:
Chapter 5
The Single Record in Individual Controls option
Handling ADO.NET Events
Chapter 6 - Integrating XML with ADO.NET
The form generated by this option looks like Figure 2-17. As you can see, each column of the table has a field on
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
the form.
Chapter 8 - Constraints and Data Relations
Chapter 9 - ADO.NET Exception Handling
Chapter 10 - Working with the ODBC .NET Data Provider
Chapter 11 - Stored Procedures and Views
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Chapter 13 - Developing a Custom Data Provider
Chapter 14 - Developing Database Web Applications using ASP.NET
Chapter 15 - Using ADO.NET in Xml Web Services
Chapter 16 - ASP.NET Server Controls and Data Binding
Chapter 17 - Building Real-World Web Applications
Chapter 18 - Object-Relational Mapping in .NET
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
Chapter 20 - COM Interoperability and ADO.NET
Chapter 21 - Messaging
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Appendix A - Relational Databases: Some Basic Concepts
Appendix B - Commonly Used SQL Statements
Figure
Appendix C - 2-17: Data
ADO.NET Form Wizard-generated
Frequently Asked Questions form for the Single Record in Individual Controls option
Index
List of Figures
After selecting the data display style, click the Finish button. The Data Form Wizard adds the Windows form
List of Tables and the class DataForm1.vb corresponding to it.
DataForm1
List of Listings
Step
List 10: Calling
of Sidebars the Data Form Wizard Form from the Application
Now you need to change one more thing. You need to call the DataForm1 form. Generally, you call a
DataForm from a menu or a button click event handler. Say you've added two DataForm objects, DataForm1
andDataForm2, using both the options. The code in Listing 2-4 calls DataForm1.
ThebtnUpdate_Click and btnLoad_Click methods are the event handlers for the Update and Load
buttons, respectively. As you can see from Listing 2-6, the btnLoad_Click method calls LoadDataSet, and
thebtnUpdate_Click method calls the UpdateDataSet method.
Listing 2-6: The Load and Update Button Click Event Handlers
Applied ADO.NET: Building Data-Driven Solutions
by Mahesh Chand and David Talbot ISBN:1590590732
Private Sub btnUpdate_Click(ByVal
Apress 2003 (928 pages) sender As System.Object, _
ByVal e As System.EventArgs) Handles btnUpdate.Click
This text provides extensive coverage of ADO.NET technology
Try including ADO.NET internals, namespaces, classes, and
'Attempt to update
interfaces, the
and takes datasource.
a comprehensive look at XML
namespaces and classes, and how to integrate both with
Me.UpdateDataSet()
ADO.NET.
Catch eUpdate As System.Exception
'Add your error handling code here.
'Display error message, if any.
Table of Contents
System.Windows.Forms.MessageBox.Show(eUpdate.Message)
Applied ADO.NETBuilding Data-Driven Solutions
End Try
Introduction
Chapter 1 - ADO.NET Basics
End Sub
Chapter 2 - Data Components in Visual Studio .NET
Private Sub btnLoad_Click(ByVal sender As System.Object, _
Chapter 3 - ADO.NET in Disconnected Environments
ByVal e As System.EventArgs) Handles btnLoad.Click
ChapterTry
4 - ADO.NET in Connected Environments
Chapter 5 'Attempt
- Handling to
ADO.NET
loadEvents
the dataset.
Chapter 6 Me.LoadDataSet()
- Integrating XML with ADO.NET
ChapterCatch
7 - Data Binding
eLoad Asand Windows Forms Data-Bound Controls
System.Exception
Chapter 8 'Add
- Constraints and Data
your error Relations code here.
handling
Chapter 9 'Display
- ADO.NET error
Exception Handling if any.
message,
Chapter 10System.Windows.Forms.MessageBox.Show(eLoad.Message)
- Working with the ODBC .NET Data Provider
End Try
Chapter 11 - Stored Procedures and Views
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Chapter 13 - Developing a Custom Data Provider
Chapter 14 - Developing Database Web Applications using ASP.NET
TheLoadDataSet method loads the data from the data source into the controls by calling FillDataSet (see
Chapter 15 - Using ADO.NET in Xml Web Services
Listing 2-7). As you can see from the code, it assigns the MyDS DataSet generated by the Data Form Wizard as
Chapter 16 - ASP.NET Server Controls and Data Binding
a temporary DataSet and fills it using the FillDataSet method.
Chapter 17 - Building Real-World Web Applications
Chapter
Listing18 - Object-Relational
2-7: LoadDataSet Mapping in .NET
Method Generated by the Data Form Wizard
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
Chapter 20 - COM Interoperability and ADO.NET
Public Sub LoadDataSet()
Chapter 21 - Messaging
'Create a new dataset to hold the records returned
Chapter'A 22 temporary
- SQL Server and ADO.NET:
dataset is Notes
usedonbecause
Performance
filling the existing dataset would
Appendix A - Relational Databases: Some Basic
'require the databindings to be rebound. Concepts
AppendixDimB -objDataSetTemp
Commonly Used SQL As Statements
MyDataFormWizardSamp.MyDS
Appendix C - ADO.NET Frequently
objDataSetTemp = NewAsked Questions
MyDataFormWizardSamp.MyDS()
Index Try
List of Figures
'Attempt to fill the temporary dataset.
Me.FillDataSet(objDataSetTemp)
List of Tables
List of Listings eFillDataSet As System.Exception
Catch
'Add your error handling code here.
List of Sidebars
Throw eFillDataSet
End Try
Try
'Empty the old records from the dataset.
objMyDS.Clear()
'Merge the records into the main dataset.
objMyDS.Merge(objDataSetTemp)
Catch eLoadMerge As System.Exception
'Add your error handling code here.
Throw eLoadMerge
End Try
End Sub
Applied ADO.NET: Building Data-Driven Solutions
by Mahesh Chand and David Talbot ISBN:1590590732
TheFillDataSetApress
fills the
2003 from the DataAdapter by calling the Fill method on each
(928 pages)
DataSet
DataAdapter. Note that provides
This text with the extensive
Data Form Wizard,ofa ADO.NET
coverage is created for each table-one
technology
DataAdapter
including
DataAdapter for ADO.NETtable
the Customers internals, namespaces,
and one classes,for
DataAdapter andthe Orders table. Both DataAdapters fill
interfaces, and takes a comprehensive look at XML
the same DataSet. Listing 2-8 shows the FillDataSet method.
namespaces and classes, and how to integrate both with
ADO.NET.
Listing 2-8: The FillDataSet Method Generated by the Data Form Wizard
Table of Contents
Public Sub FillDataSet(ByVal dataSet As MyDataFormWizardSamp.MyDS)
Applied'Turn
ADO.NETBuilding Data-Driven
off constraint Solutions before the dataset is filled.
checking
Introduction
'This allows the adapters to fill the dataset without concern
Chapter'for
1 - ADO.NET Basics
dependencies between the tables.
ChapterdataSet.EnforceConstraints
2 - Data Components in Visual Studio
= .NET
False
Chapter Try
3 - ADO.NET in Disconnected Environments
Chapter 4 'Open
- ADO.NET
thein connection.
Connected Environments
Chapter 5 Me.OleDbConnection1.Open()
- Handling ADO.NET Events
Chapter 6 'Attempt
- Integratingto
XMLfill the dataset through the OleDbDataAdapter1.
with ADO.NET
Chapter 7 Me.OleDbDataAdapter1.Fill(dataSet)
- Data Binding and Windows Forms Data-Bound Controls
Chapter 8 Me.OleDbDataAdapter2.Fill(dataSet)
- Constraints and Data Relations
Chapter Catch fillException
9 - ADO.NET As System.Exception
Exception Handling
'Add your error handling code here.
Chapter 10 - Working with the ODBC .NET Data Provider
Throw fillException
Chapter 11 - Stored Procedures and Views
Finally
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
'Turn constraint checking back on.
Chapter 13 - Developing a Custom Data Provider
dataSet.EnforceConstraints = True
Chapter 14 - Developing Database Web Applications using ASP.NET
'Close the connection whether or not the exception was thrown.
Chapter 15 Me.OleDbConnection1.Close()
- Using ADO.NET in Xml Web Services
Chapter End- ASP.NET
16 Try Server Controls and Data Binding
Chapter 17 - Building Real-World Web Applications
Chapter 18 - Object-Relational Mapping in .NET
End Sub
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
Chapter 20 - COM Interoperability and ADO.NET
Chapter 21 - Messaging
Note
Chapter 22 One
- SQLthing youand
Server may notice isNotes
ADO.NET: that the
on Data Form Wizard uses the OleDb provider to write the Data Form
Performance
Appendix A Wizard code.
- Relational Databases: Some Basic Concepts
Appendix B - Commonly Used SQL Statements
TheUpdateDataSource method updates the data source from the DataSet. This method is called by the
Appendix C - ADO.NET
UpdateDataSet Frequently
method Asked Questions
and utilizes the Update command of the DataAdapters. Listing 2-9 shows the
Index
UpdateDataSource method.
List of Figures
Listing
List 2-9: The UpdateDataSource and UpdateDataSet Methods Generated by the Data Form Wizard
of Tables
List of Listings
List ofPublic
Sidebars Sub UpdateDataSet()
'Create a new dataset to hold the changes that have been made to the main dataset.
Dim objDataSetChanges As MyDataFormWizardSamp.MyDS = _
New MyDataFormWizardSamp.MyDS()
'Stop any current edits.
Me.BindingContext(objMyDS, "Customers").EndCurrentEdit()
Me.BindingContext(objMyDS, "Orders").EndCurrentEdit()
'Get the changes that have been made to the main dataset.
objDataSetChanges = CType(objMyDS.GetChanges, MyDataFormWizardSamp.MyDS)
'Check to see if any changes have been made.
If (Not (objDataSetChanges) Is Nothing) Then
Try
'There are changes that need to be made, so attempt to update"
Applied
'calling theADO.NET:
updateBuilding
method Data-Driven
and passingSolutions
the dataset and any parameters.
by Mahesh Chand and David Talbot
Me.UpdateDataSource(objDataSetChanges) ISBN:1590590732
Apress 2003 (928 pages)
objMyDS.Merge(objDataSetChanges)
This text provides extensive coverage of ADO.NET technology
objMyDS.AcceptChanges()
including ADO.NET
Catch eUpdate internals, namespaces, classes, and
As System.Exception
interfaces, and takes a comprehensive look at XML
'Add namespaces
your error and handling codeto here.
classes, and how integrate both with
ThrowADO.NET.
eUpdate
End Try
'Add your code to check the returned dataset for any errors"
Table of Contents
'pushed into the row object's error.
AppliedEnd
ADO.NETBuilding
If Data-Driven Solutions
Introduction
End Sub
Chapter 1 - ADO.NET Basics
Chapter
Public 2 Sub
- Data Components in Visual Studio .NET
UpdateDataSource(ByVal ChangedRows As MyDataFormWizardSamp.MyDS)
ChapterTry
3 - ADO.NET in Disconnected Environments
Chapter 4 'The data insource
- ADO.NET only
Connected needs to be updated if there are changes pending.
Environments
Chapter 5 If- Handling
(Not (ChangedRows)
ADO.NET Events Is Nothing) Then
Chapter 6 -'Open theXML
Integrating connection.
with ADO.NET
Chapter 7 -Me.OleDbConnection1.Open()
Data Binding and Windows Forms Data-Bound Controls
Chapter 8
'Attempt to update the data source.
- Constraints and Data Relations
OleDbDataAdapter1.Update(ChangedRows)
Chapter 9 - ADO.NET Exception Handling
OleDbDataAdapter2.Update(ChangedRows)
Chapter 10 - Working with the ODBC .NET Data Provider
End If
Chapter 11 - Stored Procedures and Views
Catch updateException As System.Exception
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
'Add your error handling code here.
Chapter 13 - Developing
Throw a Custom Data Provider
updateException
ChapterFinally
14 - Developing Database Web Applications using ASP.NET
Chapter 15 - Using ADO.NET
'Close in Xml Web Services
the connection whether or not the exception was thrown.
Chapter 16 - ASP.NET Server Controls and Data Binding
Me.OleDbConnection1.Close()
ChapterEnd
17 -Try
Building Real-World Web Applications
Chapter
End Sub18 - Object-Relational Mapping in .NET
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
Chapter 20 - COM Interoperability and ADO.NET
Chapter 21 - Messaging
ThebtnCancelAll_Click method is the Cancel All button click handler, which calls the DataSet's
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
RejectChanges method (see Listing 2-10).
Appendix A - Relational Databases: Some Basic Concepts
Appendix B - Commonly Used SQL Statements
Listing 2-10: Cancel All Button Click Event Handler
Appendix C - ADO.NET Frequently Asked Questions
Index
Private Sub btnCancelAll_Click(ByVal sender As System.Object, _
List of Figures
ByVal e As System.EventArgs) Handles btnCancelAll.Click
List of Tables
Me.objMyDS.RejectChanges()
List of Listings
End Sub
List of Sidebars
Summary Applied ADO.NET: Building Data-Driven Solutions
by Mahesh Chand and David Talbot ISBN:1590590732
Congratulations! Apress
You'venow
2003completed
(928 pages) one more step toward understanding ADO.NET and its
components. After completing this extensive
This text provides chapter, you should
coverage of have a good
ADO.NET idea of how to write database
technology
applications usingincluding
the VS .NET IDE.
ADO.NET internals, namespaces, classes, and
interfaces, and takes a comprehensive look at XML
namespaces
In this chapter, you and classes,
learned about and components
visual data how to integrate both
in VS with The Server Explorer is a handy
.NET.
ADO.NET.
utility added to VS .NET IDE to help you manage your database connections.
DataAdapters let you connect to a data source at design-time and populate DataSet objects. In
Table of Contents
addition, DataAdapters also allow you to add, update, and delete data through data command objects.
Applied
The VS ADO.NETBuilding Data-Driven
.NET IDE also lets Solutions
you generate typed DataSets, which are DataSets with properties of tables
Introduction
and columns specific to a data source.
Chapter 1 - ADO.NET Basics
ADataView
Chapter is a Components
2 - Data bindable view
in of a DataSet.
Visual You can sort and filter a DataSet with a DataView and
Studio .NET
use it to3 bind
Chapter to a graphical
- ADO.NET component
in Disconnected in many of the Windows form controls.
Environments
Chapter 4 - ADO.NET in Connected Environments
Finally, the Data Form Wizard is a useful tool for generating full-fledged database applications with
Chapter 5 - Handling ADO.NET Events
features such as inserting, deleting, and updating in no time.
Chapter 6 - Integrating XML with ADO.NET
Chapter 7 -chapter,
In the next Data Binding and Windows
we discuss ADO.NETForms Data-Bound classes
disconnected Controls and components.
Chapter 8 - Constraints and Data Relations
Chapter 9 - ADO.NET Exception Handling
Chapter 10 - Working with the ODBC .NET Data Provider
Chapter 11 - Stored Procedures and Views
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Chapter 13 - Developing a Custom Data Provider
Chapter 14 - Developing Database Web Applications using ASP.NET
Chapter 15 - Using ADO.NET in Xml Web Services
Chapter 16 - ASP.NET Server Controls and Data Binding
Chapter 17 - Building Real-World Web Applications
Chapter 18 - Object-Relational Mapping in .NET
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
Chapter 20 - COM Interoperability and ADO.NET
Chapter 21 - Messaging
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Appendix A - Relational Databases: Some Basic Concepts
Appendix B - Commonly Used SQL Statements
Appendix C - ADO.NET Frequently Asked Questions
Index
List of Figures
List of Tables
List of Listings
List of Sidebars
Chapter Applied
3: ADO.NET in Disconnected
ADO.NET: Building Data-Driven Solutions
by Mahesh Chand and David Talbot
Environments
ISBN:1590590732
Apress 2003 (928 pages)
Overview This text provides extensive coverage of ADO.NET technology
including ADO.NET internals, namespaces, classes, and
In Chapter 1 and Chapter 2,and
interfaces, youtakes
learned about ADO.NET,
a comprehensive look and you learned how to use ADO.NET
at XML
components withnamespaces
Visual Studioand classes,
(VS) .NET.and how
You to learned
also integratehow
bothtowith
write code that binds ADO.NET
ADO.NET.
components to data-bound controls and how to use VS .NET's Integrated Development Environment
(IDE) wizards to write full-fledged database applications.
Table of Contents
In this chapter, you'll get a broad view of the ADO.NET architecture and the basic building blocks of
Applied ADO.NETBuilding Data-Driven Solutions
ADO.NET in a disconnected environment. Now, the first question on your mind might be, "What is a
Introduction
disconnected environment?" Generally, when we talk about ADO.NET and data access, we're talking
Chapter 1 - stored
about data ADO.NETin aBasics
database server such as a SQL Server or Oracle. Actually, ADO.NET not only
Chapter
provides2 a-way
DatatoComponents in Visual Studio
work with databases, it also.NET
allows you to access various kinds of data sources and even
Chapter 3 - representations
in-memory ADO.NET in Disconnected Environments
of data. In-memory data is stored in a system's memory and erased when an
Chapter 4 - is
application ADO.NET
closed. in Connected
Data Environments
that is held in-memory is referred to as a disconnected environment.
Chapter 5 - Handling ADO.NET Events
Why use
Chapter 6 in-memory data?
- Integrating XML Well, there may be occasions when you don't want to store data in a database
with ADO.NET
but you7want
Chapter to perform
- Data Binding some actionsForms
and Windows such as adding, deleting,
Data-Bound Controlssorting, and searching data, and once
you're done,
Chapter 8
you don't care what happens to the data. This scenario would be perfect for working with
- Constraints and Data Relations
disconnected data.
Chapter 9 - ADO.NET Exception Handling
Chapter 10 In
Note - Working
Chapter with
4, wethe
willODBC .NET Data
concentrate onProvider
working with connected data, where data will be stored in a
Chapter 11 database.
- Stored Procedures and Views
In the connected environment, you use a data provider to connect to a database and
Chapter 12 read
- Oracle,
and SQLXML,
write dataand Other
using the.NET
dataData Providers
provider classes.
Chapter 13 - Developing a Custom Data Provider
ADO.NET
Chapter 14 disconnected classes Web
- Developing Database are basic buildingusing
Applications blocks of the ADO.NET architecture. The classes are
ASP.NET
independent
Chapter of data
15 - Using providers
ADO.NET andWeb
in Xml dataServices
sources. In other words, you can use these classes with data
providers as well as without data providers.
Chapter 16 - ASP.NET Server Controls and Data Binding
Chapter
ADO.NET 17 -data
Building Real-World
providers Web
are sets ofApplications
classes designed to work with multiple data sources to provide the
Chapter
best of 18
all -the
Object-Relational
database access Mapping in .NET ADO.NET provides many data providers to work with
technologies.
Chapter 19kinds
different - Mapped Objects:
of data Performance
sources, Considerations
including OleDb, ODBC,andandData
Sql.Binding
Chapter 20 - COM Interoperability and ADO.NET
Note
Chapter 21 You can access SQL Server 6.5 or previous versions using ODBC or OleDb data providers.
- Messaging
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Although ADO.NET is a new programming model, it still uses old native data access technologies to
Appendix A - Relational Databases: Some Basic Concepts
access different data sources. For example, OleDb data providers use the native OLE DB Application
Appendix B - Commonly Used SQL Statements
Programming Interface (API) to access OLE DB data sources. Similar to OLE DB data sources, ODBC
Appendix C - ADO.NET
data providers Frequently
use ODBC Asked
drivers Questions
and the ODBC Administration to access ODBC data sources. ADO.NET
Index
data providers wrap up these technologies for easier programming.
List of Figures
So,ofwhat's
List Tablesnew in ADO.NET? That is a good question. Weren't you using the ODBC and OLE DB APIs in
previous
List data access technologies? You're right. ADO.NET uses the same native API. The only difference
of Listings
is, of
List ADO.NET
Sidebars provides high-level, object-oriented classes that are easy to program and understand.
Further, all the data providers supply the same programming model. So, if you know how to write
applications using OleDb data providers, you'll be able to write applications using ODBC or Sql providers in
no time. It's just a matter of changing the class names and connection strings. When working with SQL
Server databases, the Sql data provider is much more efficient and faster in comparison to the OleDb or
ODBC data providers. Unlike ODBC and OleDb data providers, which use ODBC and OLE DB data layers
to connect to a SQL Server database, the Sql data provider uses the native SQL Server layer to connect to
the databases. We discuss this in more detail in later chapters.
Understanding
Appliedthe ADO.NET
ADO.NET: BuildingArchitecture
Data-Driven Solutions
by Mahesh Chand and David Talbot ISBN:1590590732
You briefly lookedApress
at theADO.NET architecture in Chapter 1. Now you'll see a broad view of the ADO.NET
2003 (928 pages)
architecture and learn how disconnected
This text provides extensiveandcoverage
connected components
of ADO.NET (classes) provide access to multiple
technology
data sources. In this section, we talk about objects in general.
including ADO.NET internals, namespaces, classes, and
interfaces, and takes a comprehensive look at XML
Figure 3-1 showsnamespaces and classes,ofand
the basic architecture thehow to integrate
ADO.NET both
model. Aswith
you can see, the entire ADO.NET
ADO.NET.
model sits between the data source and client applications that can be built using Windows Forms, Web
Forms, or even console-based applications. The Connection is the first component that talks to a data
source. In ADO.NET, each data provider (OleDb, Sql, Odbc, or Oracle) has its own Connection class.
Table of Contents
TheConnection component is a mediator between a DataAdapter or a Command component. The
Applied ADO.NETBuilding Data-Driven Solutions
DataAdapter components create SQL INSERT,SELECT,UPDATE, and DELETE statements that add,
Introduction
read, update, and delete data from a data source, respectively. Not only does a DataAdapter create
Chapter 1 - ADO.NET Basics
these SQL statements, it also executes these statements. Basically, a DataAdapter (with the help of
Chapter 2 -physically
Command) Data Components
updatesinand
Visual Studio
reads data.NET
from a data source. In Figure 3-1, an arrow shows this flow
Chapter 3
of data. - ADO.NET in Disconnected Environments
Chapter 4 - ADO.NET in Connected Environments
Chapter 5 - Handling ADO.NET Events
Chapter 6 - Integrating XML with ADO.NET
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
Chapter 8 - Constraints and Data Relations
Chapter 9 - ADO.NET Exception Handling
Chapter 10 - Working with the ODBC .NET Data Provider
Chapter 11 - Stored Procedures and Views
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Chapter 13 - Developing a Custom Data Provider
Chapter 14 - Developing Database Web Applications using ASP.NET
Chapter 15 - Using ADO.NET in Xml Web Services
Chapter 16 - ASP.NET Server Controls and Data Binding
Chapter 17 - Building Real-World Web Applications
Chapter 18 - Object-Relational Mapping in .NET
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
Chapter 20 - COM Interoperability and ADO.NET
Chapter 21 - Messaging
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Appendix A - 3-1:
Figure Relational Databases:
ADO.NET Some Basic Concepts
architecture
Appendix B - Commonly Used SQL Statements
You canCuse
Appendix the Command
- ADO.NET components
Frequently with or without a DataAdapter. You can directly execute
Asked Questions
commands and read data in a DataReader, which provides a read-only, forward-only fast access to data.
Index
This
List of is best when you need to read data in applications that are not data-bound. You can also see from
Figures
Figure
List 3-1 that all arrows are double-sided arrows except the arrow connecting a DataReader and
of Tables
Command.
List A double-sided arrow means data transfer is possible on both sides. A DataReader can only
of Listings
read data, which is why the DataReader has only a one-sided arrow. This shows that you can fill a
List of Sidebars
DataReader from the Command, but you can't send back data from a DataReader to the Command.
ADataAdapter sits between a data source and a DataSet. It provides Fill and Update methods to
fill a DataSet from a data source based on the SELECT statement, and the Update method saves a
DataSet's changes to the data source. The DataSet plays a vital role in data-bound Graphical User
Interface (GUI) applications to display and manipulate data. Not only does it provide fast data manipulation
using Extensible Markup Language (XML) schemas, it also provides multiple views of data that can be
bound with multiple Windows Forms and Web Forms data-bound controls.
Table of Contents
Applied ADO.NETBuilding Data-Driven Solutions
Introduction
Chapter 1 - ADO.NET Basics
Chapter 2 - Data Components in Visual Studio .NET
Chapter 3 - ADO.NET in Disconnected Environments
Chapter 4 - ADO.NET in Connected Environments
Chapter 5 - Handling ADO.NET Events
Chapter 6 - Integrating XML with ADO.NET
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
Chapter 8 - Constraints and Data Relations
Chapter 9 - ADO.NET Exception Handling
Chapter 10 - Working with the ODBC .NET Data Provider
Chapter 11 - Stored Procedures and Views
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Chapter 13 - Developing a Custom Data Provider
Chapter 14 - Developing Database Web Applications using ASP.NET
Chapter 15 - Using ADO.NET in Xml Web Services
Chapter 16 - ASP.NET Server Controls and Data Binding
Chapter 17 - Building Real-World Web Applications
Chapter 18 - Object-Relational Mapping in .NET
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
Chapter 20 - COM Interoperability and ADO.NET
Chapter 21 - Messaging
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Appendix A - Relational Databases: Some Basic Concepts
Appendix B - Commonly Used SQL Statements
Appendix C - ADO.NET Frequently Asked Questions
Index
List of Figures
List of Tables
List of Listings
List of Sidebars
Exploring the ADO.NET
Applied ClassData-Driven
ADO.NET: Building Hierarchy
Solutions
by Mahesh Chand and David Talbot ISBN:1590590732
Before you start swimming in the
Apress 2003 (928 deep
pages) ocean of ADO.NET, you need to take a quick look at the ADO.NET
class hierarchy provided by the .NET Runtime
This text provides extensive Class Library
coverage (alsotechnology
of ADO.NET known as Base Class Library, or BCL).
These classes represent ADO.NET components.
including ADO.NET internals, namespaces, classes, and
interfaces, and takes a comprehensive look at XML
namespaces
All ADO.NET functionality and.NET
in the classes, and how
Runtime to integrate
Class Library isboth with in three general namespaces and
defined
ADO.NET.
a number of provider-specific namespaces. System.Data and System.Data.Common are two general
namespaces common to all data providers. The System.Data.SqlTypes namespace is a SQL Server-
specific namespace. The remainder of the functionality is defined in the data provider-specific
Table of Contents
namespaces; some of them are System.Data.OleDb,System.Data.ODBC, and
Applied ADO.NETBuilding Data-Driven Solutions
System.Data.SqlClient.
Introduction
Chapter 1 - ADO.NETnamespace
TheSystem.Data Basics defines classes that you can use with all the data providers or without
Chapter 2 - Data
data providers at Components in Visual Studio
all. This namespace .NET interfaces that are base classes for the data provider
also defines
classes.
Chapter 3Figure 3-2 shows
- ADO.NET the System.Data
in Disconnected namespace's class hierarchy.
Environments
Chapter 4 - ADO.NET in Connected Environments
Chapter 5 - Handling ADO.NET Events
Chapter 6 - Integrating XML with ADO.NET
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
Chapter 8 - Constraints and Data Relations
Chapter 9 - ADO.NET Exception Handling
Chapter 10 - Working with the ODBC .NET Data Provider
Chapter 11 - Stored Procedures and Views
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Chapter 13 - Developing a Custom Data Provider
Chapter 14 - Developing Database Web Applications using ASP.NET
Chapter 15 - Using ADO.NET in Xml Web Services
Chapter 16 - ASP.NET Server Controls and Data Binding
Chapter 17 - Building Real-World Web Applications
Chapter 18 - Object-Relational Mapping in .NET
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
Chapter 20 - COM Interoperability and ADO.NET
Chapter 21 - Messaging
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Appendix A - Relational Databases: Some Basic Concepts
Appendix B - Commonly Used SQL Statements
Appendix C - ADO.NET Frequently Asked Questions
Index
List of Figures
List ofFigure
Tables 3-2: TheSystem.Data namespace class hierarchy
List of Listings
The
List ofSystem.Data.Common
Sidebars namespace defines classes common to all data providers. Figure 3-3 shows
theSystem.Data.Common namespace hierarchy.
Applied ADO.NET: Building Data-Driven Solutions
by Mahesh Chand and David Talbot ISBN:1590590732
Apress 2003 (928 pages)
This text provides extensive coverage of ADO.NET technology
including ADO.NET internals, namespaces, classes, and
interfaces, and takes a comprehensive look at XML
namespaces and classes, and how to integrate both with
ADO.NET.
Table of Contents
Applied ADO.NETBuilding Data-Driven Solutions
Introduction
Chapter 1 - ADO.NET Basics
Chapter 2 - Data Components in Visual Studio .NET
Chapter 3 - ADO.NET in Disconnected Environments
Chapter 4 - ADO.NET in Connected Environments
Chapter 5 - Handling ADO.NET Events
Chapter 6 - Integrating XML with ADO.NET
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
Chapter 8 - Constraints and Data Relations
Chapter 9 - ADO.NET Exception Handling
Figure 3-3: TheSystem.Data.Common namespace hierarchy
Chapter 10 - Working with the ODBC .NET Data Provider
Chapter 11 - Stored Procedures and Views
TheSystem.Data.SqlTypes
Chapter 12 - Oracle, SQLXML, and namespace defines
Other .NET Data classes for native SQL Server data types that provide
Providers
type-safe
Chapter 13 conversion
- Developingbetween the
a Custom .NET
Data data types and the SQL Server native data types. Figure 3-4
Provider
shows the System.Data.SqlTypes namespace hierarchy.
Chapter 14 - Developing Database Web Applications using ASP.NET
Chapter 15 - Using ADO.NET in Xml Web Services
Chapter 16 - ASP.NET Server Controls and Data Binding
Chapter 17 - Building Real-World Web Applications
Chapter 18 - Object-Relational Mapping in .NET
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
Chapter 20 - COM Interoperability and ADO.NET
Chapter 21 - Messaging
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Appendix A - Relational Databases: Some Basic Concepts
Appendix B - Commonly Used SQL Statements
Appendix C - ADO.NET Frequently Asked Questions
Index
List of Figures
List of Tables
List of Listings
List of Sidebars
In addition to these three namespaces, there are a number of provider-specific namespaces. The class
hierarchy models of these namespaces are similar except for the name of the class. The classes defined
in the provider-specific namespaces start with the data provider name. For example, the Sql data provider
classes start withApplied
Sql, and ADO.NET:
the OleDb Building Data-Driven
data provider classesSolutions
start with OleDb. The Command object class
by Mahesh Chand and David Talbot
of the Sql data provider is SqlCommand, and the Command object ISBN:1590590732
class of the OleDb data provider is
OleDbCommand. Apress 2003 (928 pages)
This text provides extensive coverage of ADO.NET technology
including
In this section, you'll ADO.NET
see only internals, namespaces, namespace
the System.Data.OleDb classes, and class hierarchy because all the data
interfaces,
providers (including and takes a comprehensive
System.Data.Sql look at XML
and System.Data.Odbc) implement the same class hierarchy
namespaces and classes, and how to integrate both with
model (with minorADO.NET.
changes). Figure 3-5 shows the System.Data.OleDb namespace hierarchy.
Table of Contents
Applied ADO.NETBuilding Data-Driven Solutions
Introduction
Chapter 1 - ADO.NET Basics
Chapter 2 - Data Components in Visual Studio .NET
Chapter 3 - ADO.NET in Disconnected Environments
Chapter 4 - ADO.NET in Connected Environments
Chapter 5 - Handling ADO.NET Events
Chapter 6 - Integrating XML with ADO.NET
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
Chapter 8 - Constraints and Data Relations
Chapter 9 - ADO.NET Exception Handling
Chapter 10 - Working with the ODBC .NET Data Provider
Chapter 11 - Stored Procedures and Views
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Chapter 13 - Developing a Custom Data Provider
Chapter 14 - Developing Database Web Applications using ASP.NET
Chapter 15 - Using ADO.NET in Xml Web Services
Chapter 16 - ASP.NET Server Controls and Data Binding
Chapter 17 - Building Real-World Web Applications
Chapter 18 - Object-Relational Mapping in .NET
Figure
Chapter 19 - 3-5: TheObjects:
Mapped System.Data.OleDb namespaceand
Performance Considerations hierarchy
Data Binding
Chapter 20 - COM Interoperability and ADO.NET
Chapter 21 - Messaging
We discuss these namespaces and their classes in more detail throughout this chapter and Chapter 4.
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Appendix A - Relational Databases: Some Basic Concepts
Appendix B - Commonly Used SQL Statements
Appendix C - ADO.NET Frequently Asked Questions
Index
List of Figures
List of Tables
List of Listings
List of Sidebars
Choosing aApplied
DataADO.NET:
Provider
Building Data-Driven Solutions
by Mahesh Chand and David Talbot ISBN:1590590732
As you saw earlier, many
Apress data(928
2003 providers
pages) are available in ADO.NET. There may be cases when you can
access a data source
This text providesthan
using more one data
extensive provider.
coverage Now thetechnology
of ADO.NET question arises: Which one is better?
When choosing aincluding
data provider, the main criteria of selection is
ADO.NET internals, namespaces, classes, andperformance and multiple data source
connectivity. interfaces, and takes a comprehensive look at XML
namespaces and classes, and how to integrate both with
ADO.NET.
In brief, to work with SQL Server 7 or later databases, the Sql data provider is the best choice. The Sql
data provider bypasses many layers and directly connects to the internal layer of the infrastructure. Not
only that, but the Sql data provider provides classes that help you to convert from native SQL Server data
Table of Contents
types to the .NET data types, and vice versa.
Applied ADO.NETBuilding Data-Driven Solutions
Introduction
OleDb data provider uses native OLE DB providers to access OLE DB data sources. OleDb data providers
Chapter 1 -because
are useful ADO.NETsome
Basicsdatabase providers don't implement ODBC drivers to connect to a database
Chapter
through2 ODBC.
- Data Components in Visual Studio .NET
Chapter 3 - ADO.NET in Disconnected Environments
The Odbc
Chapter 4 -data provider
ADO.NET provides aEnvironments
in Connected way to work with different kinds of data sources through ODBC drivers.
ODBC 5is an
Chapter older data
- Handling accessEvents
ADO.NET technology, but many applications still use ODBC to access data sources.
ODBC data
Chapter 6
providers provide a way to access ODBC data sources through ODBC drivers and ODBC
- Integrating XML with ADO.NET
Administration. Database venders generally provide the ODBC drivers. Using ODBC you can access any
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
data source for which you have an ODBC driver installed.
Chapter 8 - Constraints and Data Relations
Chapter 9 - Odbc
In general, ADO.NET
dataException
provider Handling
connectivity is faster than OLE-DB because of OLE DB's COM nature,
Chapter
which is10very
- Working with
"chatty." Sqlthe ODBC
data .NET is
provider Data Provider
faster than ODBC to work with SQL Server databases. But
Chapter
ODBC 11 - Stored
is useful whenProcedures
you needandto Views
write a generic class that can access multiple data sources through
ODBC.12
Chapter For- Oracle,
example, say you're
SQLXML, writing.NET
and Other an application that can work with multiple back-end servers
Data Providers
including
Chapter 13 SQL Server, Oracle,
- Developing Access,
a Custom and MySql. When you install these back-end servers, you also
Data Provider
install the
Chapter 14 ODBC driverDatabase
- Developing for theseWeb
databases. So, you
Applications can
using write a generic application that accesses these
ASP.NET
data sources
Chapter based
15 - Using on the in
ADO.NET ODBC DataServices
Xml Web Source Name (DSN). You can also pass the driver and data
source 16
Chapter information
- ASP.NETinServer
the application itself,
Controls and DatabutBinding
the user has to only create a DSN from ODBC, and the
application
Chapter 17 - can use Real-World
Building that DSN as theApplications
Web connection string in the application for the Odbc data provider.
Chapter 18 - Object-Relational Mapping in .NET
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
Chapter 20 - COM Interoperability and ADO.NET
Chapter 21 - Messaging
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Appendix A - Relational Databases: Some Basic Concepts
Appendix B - Commonly Used SQL Statements
Appendix C - ADO.NET Frequently Asked Questions
Index
List of Figures
List of Tables
List of Listings
List of Sidebars
Understanding
AppliedADO.NET Disconnected
ADO.NET: Building Classes
Data-Driven Solutions
by Mahesh Chand and David Talbot ISBN:1590590732
ADO.NET disconnected
Apress classes
2003 (928are the basic building blocks of the ADO.NET architecture. These classes
pages)
loosely couple with data providers. The coverage of namespace
System.Data
This text provides extensive defines these classes.
ADO.NET technology
including ADO.NET internals, namespaces, classes, and
interfaces, and takes a comprehensive look at XML
The System.Data Namespace
namespaces and classes, and how to integrate both with
ADO.NET.
TheSystem.Data namespace consists of classes that are the basic building blocks of the ADO.NET
architecture. These classes are also known as disconnected classes because they store disconnected
Table
dataof Contents
and can work without data providers.
Applied ADO.NETBuilding Data-Driven Solutions
Table 3-1 describes some of the common classes of the System.Data namespaces. We discuss these
Introduction
classes1in -more
Chapter detailBasics
ADO.NET throughout this chapter.
Chapter 2 - Data Components in Visual Studio .NET
Table 3-1: The System.Data Namespace Classes
Chapter 3 - ADO.NET in Disconnected Environments
Chapter
CLASS 4 - ADO.NET in Connected Environments
DESCRIPTION
Chapter 5 - Handling ADO.NET Events
Constraint,
Chapter 6 Constraints are rules set on a database table and its
- Integrating XML with ADO.NET
ConstraintCollection, columns to help maintain the integrity of the data or to
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
UniqueConstraint, enforce business rules. The Constraint class object
Chapter 8 - Constraints and Data Relations
ForeignKeyConstraint represents a constraint that you can apply on a
Chapter 9 - ADO.NET Exception Handling
DataColumn object. Some of these constraints are
Chapter 10 - Working with the ODBC .NET Data Provider
primary key, uniqueness, and foreign key. The
Chapter 11 - Stored Procedures and ViewsConstraintCollection class represents a collection of
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
constraints for a DataTable.UniqueConstraintand
Chapter 13 - Developing a Custom Data Provider
ForeignKeyConstraint represent unique and foreign
Chapter 14 - Developing Database Web Applications using ASP.NET
key constraints.
Chapter 15 - Using ADO.NET in Xml Web Services
DataColumn, TheDataColumn object represents a column of a table.
Chapter 16 - ASP.NET Server Controls and Data Binding
DataColumnCollection DataColumnCollection represents a collection of
Chapter 17 - Building Real-World Web Applications
columns of a table.
Chapter 18 - Object-Relational Mapping in .NET
Chapter 19 - Mapped Objects: PerformanceThe
DataRelation, DataRelation
Considerations object
and Data represents a parent/child
Binding
DataRelationCollection
Chapter relationship between two DataTable objects.
20 - COM Interoperability and ADO.NET
Chapter 21 - Messaging DataRelationCollection represents a collection of
DataRelation.
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Appendix A - Relational
DataRow, Databases: Some Basic
DataRowCollection Concepts
ADataRow object represents a row of a table, and
Appendix B - Commonly Used SQL Statements
DataRowCollection represent a collection of rows.
Appendix C - ADO.NET Frequently Asked Questions
DataRowView
Index
DataRowView represents a view of DataRow. It's useful
when you want to attach a DataRow with data-bound
List of Figures
controls such as a DataGrid.
List of Tables
ListDataSet
of Listings In ADO.NET, a DataSet object is a replacement of the
List of Sidebars ADO recordset and represents an in-memory cache of
data. A DataSet is a collection of DataTableobjects.
DataTable, ADataTable object represents an in-memory cache of a
DataTableCollection table, and DataTableCollection is a collection of one
or more DataTable objects.
DataView Represents a data-bindable, customized view of a
DataTable for sorting, filtering, searching, editing, and
navigation.
DataViewManager TheDefaultViewManager represents the default view of
aDataSet or DataTableCollection.
TheSystem.Data namespace also defines many enumerations and delegates that we discuss
Applied ADO.NET: Building Data-Driven Solutions
throughout this chapter.
by Mahesh Chand and David Talbot ISBN:1590590732
Once you have an idea
Apress of2003
what classes
(928 pages) the System.Data.Common namespace constaints, you'll have no
problem understanding how
This text to useextensive
provides these classes in aofsample
coverage application.
ADO.NET technology
including ADO.NET internals, namespaces, classes, and
interfaces, and takes a comprehensive look at XML
The System.Data.Common Namespace
namespaces and classes, and how to integrate both with
ADO.NET.
As its name says, the System.Data.Common namespace contains classes shared by the .NET data
providers. Some of these classes are the base classes for the .NET data provider classes. Table 3-2
Table of Contents
defines some of these classes.
Applied ADO.NETBuilding Data-Driven Solutions
Introduction
Table 3-2: The System.Data.Common Namespace Classes
Chapter 1 - ADO.NET Basics
CLASS
Chapter DESCRIPTION
2 - Data Components in Visual Studio .NET
Chapter 3 - ADO.NET in Disconnected Environments
DataAdapter TheDataAdapter class represents a DataAdapter
Chapter 4 - ADO.NET in Connected Environments
that works as a bridge between a data source and
Chapter 5 - Handling ADO.NET Events DataSet. It implements the Fill and Update
Chapter 6 - Integrating XML with ADO.NET methods. The Fill method fills data from a data source
Chapter 7 toData-Bound
- Data Binding and Windows Forms a DataSetControls
using Command objects. This class is a
Chapter 8 - Constraints and Data Relations base class for the DbDataAdapter class, which itself is
Chapter 9 - ADO.NET Exception Handling a base class for the OleDbDataAdapter,
SqlDataAdapter,
Chapter 10 - Working with the ODBC .NET Data Provider and ODBC DataAdapter classes.
Chapter 11 - Stored Procedures and Views These classes are discussed in the "The DataAdapter:
Chapter 12 - Oracle, SQLXML, and Other .NETAdapting to Your Environment" section of Chapter 4.
Data Providers
Chapter 13 - Developing a Custom Data Provider
DataColumnMapping If you don't want to use the default column names of a
Chapter 14 - Developing Database Web Applications
table tousing ASP.NET
access these columns, you can define your own
Chapter 15 - Using ADO.NET in Xml Web Services
names. You map your custom names with the original
column
Chapter 16 - ASP.NET Server Controls and Data names through DataAdapters and use these
Binding
names in your application. The SourceColumn and
Chapter 17 - Building Real-World Web Applications
DataSetColumnproperties of this class represent the
Chapter 18 - Object-Relational Mapping in .NET
source column
Chapter 19 - Mapped Objects: Performance Considerations name
and Data and DataSet column name.
Binding
Chapter 20 - COM Interoperability and ADO.NET
DataColumnMappingCollection Collection of DataColumnMapping objects.
Chapter 21 - Messaging
22 - SQL Server and ADO.NET: NotesYou
DataTableMapping
Chapter can even map a database table to a DataTable
on Performance
and
Appendix A - Relational Databases: Some Basic use this DataTable as the source in your
Concepts
Appendix B - Commonly Used SQL Statements
applications. The ColumnMappings property returns
DataColumnMappingCollection for the
Appendix C - ADO.NET Frequently Asked Questions
DataTable. The DataSetTable and SourceTable
Index
properties represent the DataTable and source tables.
List of Figures
ListDataTableMappingCollection
of Tables Collection of DataTableMapping objects.
List of Listings
DbDataAdapter Inherited from DataAdapter, this class implements the
List of Sidebars
IdbDataAdapter interface. This class is used as the
base class of a data provider's DataAdapterclasses.
DBDataPermission Ensures that data providers have security to access
data. This class is a base class from the
OleDbDataPermission,OdbcDataPermission,
andSqlDataPermission classes.
Working with DataTables
Applied ADO.NET: Building Data-Driven Solutions
by Mahesh Chand and David Talbot ISBN:1590590732
ADataTable object Apressrepresents
2003 (928apages)
database table. A data table is a collection of columns and rows. The
DataRow object Thisrepresents a table row, andcoverage
text provides extensive the DataColumn
of ADO.NET object represents a column or a field of the
technology
table. Assuming you haven't imported, reengineered, or otherwise
including ADO.NET internals, namespaces, classes, and "inherited" a database and its
DataTables, theinterfaces,
first step and takes a with
to working comprehensive
these threelook at XML
objects is to create a DataTable schema, which is
namespaces and classes, and
defined by the DataColumnCollection how to
object. integrate
You use theboth
Addwithmethod of DataColumnCollection
ADO.NET.
to add columns to the collection. The Columns property of the DataTable object represents the
DataColumnCollection, which is a collection of DataColumn objects in a DataTable. You use a
DataRow
Table object to add data to a DataTable. The DataRowCollection object represents a collection
of Contents
of rows of a DataTable Data-Driven
Applied ADO.NETBuilding object, which can be accessed by its Rows property.
Solutions
Introduction
Figure 3-6 shows the relationship between the DataTable, the DataRow, and the DataColumn.
Chapter 1 - ADO.NET Basics
Chapter 2 - Data Components in Visual Studio .NET
Chapter 3 - ADO.NET in Disconnected Environments
Chapter 4 - ADO.NET in Connected Environments
Chapter 5 - Handling ADO.NET Events
Chapter 6 - Integrating XML with ADO.NET
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
Chapter 8 - Constraints and Data Relations
Chapter 9 - ADO.NET Exception Handling
Chapter 10 - Working with the ODBC .NET Data Provider
Chapter 11 - Stored Procedures and Views
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Chapter 13 - Developing a Custom Data Provider
Chapter 14 - Developing Database Web Applications using ASP.NET
Chapter 15 - Using ADO.NET in Xml Web Services
Chapter 16 - ASP.NET Server Controls and Data Binding
Chapter 17 - Building Real-World Web Applications
Chapter 18 - Object-Relational Mapping in .NET
Figure 3-6: Relationship between the DataTable, the DataRow, and the DataColumn
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
Chapter 20 - COM Interoperability and ADO.NET
A database table schema is the structure or design of the table, which includes table columns, their types,
Chapter 21 - Messaging
relationships, and constraints. You can view a database schema from the Server Explorer as well as from
Chapter 22 - SQL
other places Server
such and
as the ADO.NET:
SQL Server Notes on Performance
Enterprise Manager or Visio. To view a table schema from the
Appendix A - Relational
Server Explorer, Databases:
simply right-clickSome BasicinConcepts
the table the Server Explorer and then click the Design Table menu
Appendix B - see
item. You'll Commonly Used SQL
the Column Name,Statements
Data Type, Length, and Allow Nulls columns. These columns
Appendix C the
represent - ADO.NET Frequently
name, data Asked Questions
type, length, and whether the column allows null values, respectively. The
Columns area represents the properties of a column; you can see and specify the description, default
Index
value,
List formula if any, and other properties of a column.
of Figures
List of Tables
Note A database table column is also called a field.
List of Listings
List
So,ofwhen
Sidebars
we talk about creating a DataTable, we mean building a database table (in memory, of
course) and its schema using the DataTable and the DataColumn objects. Based on a column
requirement, you can also apply constraints on a column. A constraint is a rule that restricts adding
unwanted data to a column. For example, the uniqueness of a column means that a column can't have
duplicate values. You'll see constraints in more detail in Chapter 8. After creating a data table schema, the
next step is to add DataRows to the DataTable. You use DataRows using the DataRow object. A
DataRow object represents a row in a table.
Tip To see data in the Customers table, double-click the Customers table in the Server Explorer.
OK, now you'll learn how to accomplish this task in ADO.NET using the DataTable,DataColumn, and
DataRow objects. First we discuss the DataColumn and the DataRow objects, followed by the
DataRelation and the DataTable objects. Then, you'll create a sample project containing all these
objects to build a DataTable and add data to it programmatically.
Applied ADO.NET: Building Data-Driven Solutions
by Mahesh Chand and David Talbot ISBN:1590590732
The DataColumn
Apress 2003 (928 pages)
Creating a DataColumn
TheDataColumn class provides five overloaded constructors to create a DataColumn. By using these
constructors you can initialize a DataColumn with its name, data type, expressions, attributes, and any
combination of these.
public DataColumn()
For example:
Applied ADO.NET: Building Data-Driven Solutions
by Mahesh Chand and David Talbot ISBN:1590590732
Dim dtColumn As DataColumn = New DataColumn()
Apress 2003 (928 pages)
This text provides extensive coverage of ADO.NET technology
This is the formatincluding ADO.NET internals, namespaces, classes, and
for creating a DataColumn with the column name:
interfaces, and takes a comprehensive look at XML
namespaces and classes, and how to integrate both with
ADO.NET.
Public DataColumn(String)
Table of Contents
Applied ADO.NETBuilding
where String Data-Driven
is the column Solutions
name. For example:
Introduction
Chapter 1 - ADO.NET Basics
// Create Quantity Column
Chapter 2 - Data Components in Visual Studio .NET
DataColumn qtCol = new DataColumn("Quantity");
Chapter 3 - ADO.NET in Disconnected Environments
Chapter 4 - ADO.NET in Connected Environments
This is 5the-format
Chapter for ADO.NET
Handling creating aEvents
DataColumn with the column name and its type:
Chapter 6 - Integrating XML with ADO.NET
Chapter
Public 7 DataColumn(String,
- Data Binding and Windows Forms Data-Bound Controls
Type)
Chapter 8 - Constraints and Data Relations
Chapter 9 - ADO.NET Exception Handling
where String
Chapter is thewith
10 - Working column name.NET
the ODBC and Data is the column data type.
TypeProvider
Chapter 11 - Stored Procedures and Views
This is the format for creating a DataColumn with the column name, its type, and its expression:
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Chapter 13 - Developing a Custom Data Provider
Public DataColumn(String, Type, String)
Chapter 14 - Developing Database Web Applications using ASP.NET
Chapter 15 - Using ADO.NET in Xml Web Services
Chapter 16 -String
where first ASP.NET is
Server Controls
the column and Data
name, TypeBinding
is the data type, and the second String is an expression.
Chapter 17 - Building Real-World Web Applications
For example:
Chapter 18 - Object-Relational Mapping in .NET
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
Chapter 20 - COM Interoperability
Dim myDataType and ADO.NET
As System.Type
myDataType
Chapter = System.Type.GetType("System.String")
21 - Messaging
Dim dtColumn
Chapter As DataColumn
22 - SQL Server and ADO.NET: = NewonDataColumn("Name",myDataType)
Notes Performance
Appendix A - Relational Databases: Some Basic Concepts
Appendix B - Commonly Used SQL Statements
This is the format for creating a DataColumn with the column name, expression, and MappingType:
Appendix C - ADO.NET Frequently Asked Questions
Index
public DataColumn(String, Type, String, MappingType);
List of Figures
List of Tables
List of Listings
where String is the column name, Type is the data type, the second String is an expression, and
List of Sidebars is an attribute.
MappingType
In the following example, strExpr is an expression, which is the result of the Price and the Quantity
column multiplication:
// Creating an expression
string strExpr = "Price * Quantity";
// Create Total Column, which is result of Price*Quantity
DataColumn totCol = new DataColumn("Total", myDataType, strExpr,
MappingType.Attribute);
Applied ADO.NET: Building Data-Driven Solutions
Note As you can see from the previous code, the expression strExpr is a multiplication of the Price
by Mahesh Chand and David Talbot ISBN:1590590732
andQuantity columns. The Price and Quantity columns must exist in the table before you
Apress 2003 (928 pages)
use them in an expression. Otherwise, the compiler will throw an exception of "column not
This text provides extensive coverage of ADO.NET technology
found."including ADO.NET internals, namespaces, classes, and
interfaces, and takes a comprehensive look at XML
Listing 3-1 summarizes all theand
namespaces constructors.
classes, andAs youtocan
how see, dcConstructorsTest
integrate both with creates the Price,
Quantity, and Total columns of a DataTable, which later is added to a DataSet. The DataSet
ADO.NET.
binds to a DataGrid using the SetDataBinding method.
Table of Contents
Listing 3-1: Creating Columns Using Different DataColumn Constructors
Applied ADO.NETBuilding Data-Driven Solutions
Introduction
Private Sub dcConstructorsTest()
Chapter 1 - ADO.NET Basics
' Create Customers table
ChapterDim2 -custTable
Data Components in Visual Studio
As DataTable = .NET
New DataTable("Customers")
ChapterDim3 -dtSet
ADO.NET Asin Disconnected
DataSet = Environments
New DataSet()
Chapter'4 Create
- ADO.NET in Connected
Price ColumnEnvironments
ChapterDim5 -myDataType
Handling ADO.NET As Events
System.Type
ChaptermyDataType
6 - Integrating
= XML with ADO.NET
System.Type.GetType("System.Int32")
ChapterDim7 -priceCol
Data BindingAs andDataColumn
Windows Forms= Data-Bound Controls
New DataColumn("Price", myDataType)
priceCol.Caption = "Price"
Chapter 8 - Constraints and Data Relations
ChaptercustTable.Columns.Add(priceCol)
9 - ADO.NET Exception Handling
Chapter'10 Create
- WorkingQuantity
with the ODBCColumn
.NET Data Provider
Chapter 11 - Stored Procedures and Views= New DataColumn()
Dim qtCol As DataColumn
ChapterqtCol.ColumnName
12 - Oracle, SQLXML, and = "Quantity"
Other .NET Data Providers
qtCol.DataType = System.Type.GetType("System.Int32")
Chapter 13 - Developing a Custom Data Provider
qtCol.Caption = "Quantity"
Chapter 14 - Developing Database Web Applications using ASP.NET
custTable.Columns.Add(qtCol)
Chapter 15 - Using ADO.NET in Xml Web Services
' Creating an expression
Chapter 16 - ASP.NET Server Controls and Data Binding
Dim strExpr As String = "Price * Quantity"
Chapter 17 - Building Real-World Web Applications
' Create Total Column, which is result of Price*Quantity
ChapterDim18 -totCol
Object-Relational Mapping in .NET
As DataColumn = New DataColumn("Total", myDataType, strExpr, _
Chapter 19 - Mapped Objects: Performance Considerations and Data BindingMappingType.Attribute)
ChaptertotCol.Caption
20 - COM Interoperability and ADO.NET
= "Total"
Chapter'21 - Messaging
Add Name column to the table.
ChaptercustTable.Columns.Add(totCol)
22 - SQL Server and ADO.NET: Notes on Performance
Appendix' AAdd
- Relational
custTable Databases: Some Basic Concepts
to DataSet
dtSet.Tables.Add(custTable)
Appendix B - Commonly Used SQL Statements
Appendix' CBind dataset
- ADO.NET to the
Frequently data
Asked grid
Questions
Index DataGrid1.SetDataBinding(dtSet, "Customers")
End Sub
List of Figures
List of Tables
List of Listings
List of Sidebars
To test this source code, you need to create a Windows application with a form and a DataGrid control
on it. After that you can call dcConstructorsTest from either Form_Load or the button click event
handler:
Listing 3-4: Creating the Id and Name Data Columns of the Customers Table
Table of Contents
Applied ADO.NETBuilding Data-Driven Solutions
Introduction
Chapter 1 - ADO.NET Basics
Chapter 2 - Data Components in Visual Studio .NET
Chapter 3 - ADO.NET in Disconnected Environments
Chapter 4 - ADO.NET in Connected Environments
Chapter 5 - Handling ADO.NET Events
Chapter 6 - Integrating XML with ADO.NET
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
Chapter 8 - Constraints and Data Relations
Chapter 9 - ADO.NET Exception Handling
Figure 3-7: The DataGrid view of an empty DataTable
Chapter 10 - Working with the ODBC .NET Data Provider
Chapter 11 - Stored Procedures and Views
More 12
Chapter DataColumn Properties
- Oracle, SQLXML, and Other .NET Data Providers
Chapter 13 - Developing a Custom Data Provider
You just saw some common properties of the DataColumn class, and you learned how to create and add
Chapter 14 - Developing Database Web Applications using ASP.NET
aDataColumn to a DataTable. But guess what? DataColumn isn't finished yet. It has more to offer.
Chapter 15 - Using ADO.NET in Xml Web Services
Now let's see the remaining properties of DataColumn.
Chapter 16 - ASP.NET Server Controls and Data Binding
Chapter 17 - Building Real-World
TheColumnMapping property Web Applications represents how a DataColumn is mapped in a DataSet
of DataColumn
Chapter
and how18the
- Object-Relational Mapping
value of the column in .NET
will be written when a DataSet is saved in XML format using the
Chapter 19 - method
WriteXml Mapped Objects: Performance
of DataSet. Considerations and
The ColumnMapping Data
takes Binding
a value of MappingType enumeration.
TheMappingType
Chapter enumerationand
20 - COM Interoperability hasADO.NET
four values: Attribute,Element,Hidden, and
SimpleContent,
Chapter which are mapped to an XML attribute, element, internal structure, and XmlText
21 - Messaging
(respectively).
Chapter 22 - SQL Listing
Server3-6and
shows you how
ADO.NET: to use
Notes the ColumnMapping property.
on Performance
Appendix A - Relational Databases: Some Basic Concepts
Listing 3-6: Using the ColumnMapping Property of DataColumn
Appendix B - Commonly Used SQL Statements
Appendix C - ADO.NET Frequently Asked Questions
Dim custTable As DataTable = New DataTable("Customers")
Index
Dim
List nameCol As DataColumn = New DataColumn("Name", _
of Figures
Type.GetType("System.Int32"),
List of Tables MappingType.Attribute)
nameCol.DataType
List of Listings = Type.GetType("System.String")
nameCol.ColumnMapping = MappingType.Element
List of Sidebars
custTable.Columns.Add(nameCol)
DataGrid1.DataSource = custTable
So far you saw how to create a new table column, set its various properties, and add it to a table. But what
if you wanted to store some custom information about a column, such as a description? Guess what? You
can do it. The Extended-Properties property of DataColumn lets you read and write custom
properties about a DataColumn. The ExtendedProperties property takes a value of type
PropertyCollection, which is inherited from the HashTable class. A hash table is a table that stores
data in a key/value pair. The PropertyCollection class defines methods to add, clear, and remover
properties to a collection. Some of the PropertyCollection class properties are Count,
IsFixedSize,IsReadOnly,IsSynchronized,Item,Keys, and Values.Listing 3-7 creates a
column and addsApplied ADO.NET:
four custom Building
properties to it. Data-Driven
After that, theSolutions
code removes the Description property
by Mahesh Chand and David Talbot ISBN:1590590732
and displays the rest of the properties using the ExtendedProperties property of DataColumn.
Apress 2003 (928 pages)
Listing 3-7: Adding
This and
text Removing Custom
provides extensive Properties
coverage of ADO.NET technology
including ADO.NET internals, namespaces, classes, and
interfaces, and takes a comprehensive look at XML
Dim custTablenamespaces
As DataTable = New
and classes, DataTable("Customers")
and how to integrate both with
ADO.NET.
Dim nameCol As DataColumn = New DataColumn("Name", _
Type.GetType("System.Int32"), MappingType.Attribute)
' Add custom properties
Table of Contents
nameCol.DataType = Type.GetType("System.String")
Applied ADO.NETBuilding Data-Driven Solutions
nameCol.ExtendedProperties.Add("Description", "The Name Column")
Introduction
nameCol.ExtendedProperties.Add("Author", "Mahesh Chand")
Chapter 1 - ADO.NET Basics
nameCol.ExtendedProperties.Add("UserId", "MCB")
Chapter 2 - Data Components in Visual Studio .NET
nameCol.ExtendedProperties.Add("PWD", "Password")
Chapter 3 - ADO.NET in Disconnected Environments
custTable.Columns.Add(nameCol)
Chapter
' Remove4 - ADO.NET
Author inproperty
Connected Environments
Chapter 5 - Handling ADO.NET Events
nameCol.ExtendedProperties.Remove("Author")
Chapter
' Read 6 custom
- Integrating XML with ADO.NET
properties
Dim str
Chapter 7 -AsDataString
Binding and Windows Forms Data-Bound Controls
Dim i8 As- Constraints
Chapter Integer and Data Relations
str = nameCol.ExtendedProperties("Description").ToString()
Chapter 9 - ADO.NET Exception Handling
str =10str
Chapter + ", with
- Working " +the
nameCol.ExtendedProperties("UserId").ToString()
ODBC .NET Data Provider
str = str + ", " + nameCol.ExtendedProperties("PWD").ToString()
Chapter 11 - Stored Procedures and Views
MessageBox.Show(str)
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Chapter 13 - Developing a Custom Data Provider
Chapter 14 - Developing Database Web Applications using ASP.NET
Chapter 15 - Using
TheOrdinal ADO.NET
property in only)
(read Xml Web Services
of DataColumn returns the position of a column in a
Chapter 16 - ASP.NET Server Controls
DataColumnCollection, and the MaxLengthand Data Binding
(get and set both types) property represents the
Chapter
maximum17 -length
Building
of Real-World Web Applications
a column. Listing 3-8 shows how to use the Ordinal and MaxLength properties.
Chapter 18 - Object-Relational Mapping in .NET
Listing19
Chapter 3-8: Using the
- Mapped Ordinal
Objects: and MaxLength
Performance Properties
Considerations and Data Binding
Chapter 20 - COM Interoperability and ADO.NET
Chapter 21 - Messaging
Dim custTable As DataTable = New DataTable("Customers")
Chapter 22 - SQL Server
Dim nameCol and ADO.NET:= Notes
As DataColumn New on Performance
DataColumn("Name", _
Appendix A - Relational Databases: Some Basic
Type.GetType("System.Int32"), Concepts
MappingType.Attribute)
Appendix B - Commonly Used SQL Statements
custTable.Columns.Add(nameCol)
nameCol
Appendix C -=ADO.NET
New DataColumn()
Frequently Asked Questions
nameCol.DataType = Type.GetType("System.String")
Index
nameCol.Caption
List of Figures = "New Column"
nameCol.ColumnName
List of Tables = "Col2"
nameCol.MaxLength
List of Listings = 240
custTable.Columns.Add(nameCol)
List of Sidebars
Dim str As String
str = "Ordinal " + nameCol.Ordinal.ToString()
str = str + " ,Length " + nameCol.MaxLength.ToString()
MessageBox.Show(str)
The DataRow
ADataRow represents a row of data in a DataTable. You add data to the DataTable using the
DataRow object. A DataRowCollection object represents a collection of DataRows of a DataTable.
You use the DataTable'sNewRow method to return a DataRow object, add values to the DataRow, and
add the row to theApplied ADO.NET:
DataTable againBuilding
by usingData-Driven Solutions Add method.
DataRowCollection's
by Mahesh Chand and David Talbot ISBN:1590590732
Table 3-4 describes
Apress
DataRow class
2003 (928 properties, and Table 3-5 describes the methods.
pages)
This text provides extensive coverage of ADO.NET technology
including Class
Table 3-4: The DataRow ADO.NET internals, namespaces, classes, and
Properties
interfaces, and takes a comprehensive look at XML
PROPERTY namespaces
DESCRIPTION and classes, and how to integrate both with
ADO.NET.
Item Represents an item of a row
After setting a row member's values, you add the row to the row collection with the
DataTable.Rows.Add method. The following code adds a row to the collection:
custTable.Rows.Add(row1)
TheRejectChanges method of the DataRow rejects recent changes on that row. For example, if you
have recently added row1 to the DataTable, then calling the RejectChanges method as follows:
row1.RejectChanges()
Applied ADO.NET: Building Data-Driven Solutions
by Mahesh Chand and David Talbot ISBN:1590590732
won't add the rowApress
to theDataTable.
2003 (928 pages)
This text provides extensive coverage of ADO.NET technology
You can also delete a rowADO.NET
including from a DataTable by calling the
internals, namespaces, classes, and Delete method:
DataRow's
interfaces, and takes a comprehensive look at XML
namespaces and classes, and how to integrate both with
Row1.Delete()ADO.NET.
Table of Contents
Caution
Applied TheRejectChanges
ADO.NETBuilding Data-Drivenand Delete methods may not work together if you're applying both
Solutions
Introduction methods on the same row because RejectChanges doesn't add a row to the DataTable.
Chapter 1 - ADO.NET Basics
Listing 3-10 shows a program that creates a DataTable with three columns (Id, Name, and Address) and
Chapter 2 - Data Components in Visual Studio .NET
adds three rows to the DataTable. At the end, this program attaches the newly created DataTable to a
Chapter 3 - ADO.NET in Disconnected Environments
DataGrid control using a DataSet.
Chapter 4 - ADO.NET in Connected Environments
Chapter
Listing53-10:
- Handling
AddingADO.NET
Rows toEvents
a DataTable Using DataRow
Chapter 6 - Integrating XML with ADO.NET
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
' This method creates Customers table
Chapter 8 - Constraints
Private and Data Relations
Sub CreateCustomersTable()
Chapter'9 Create
- ADO.NET Exception Handling
a new DataTable.
ChapterDim10 -custTable
Working with As
the ODBC .NET Data Provider
System.Data.DataTable = New DataTable("Customers")
ChapterDim11 -dtColumn
Stored Procedures and Views
As DataColumn
Chapter'12 - Oracle,id
Create SQLXML, and Other .NET Data Providers
Column.
ChapterdtColumn
13 - Developing
= Newa Custom Data Provider
DataColumn()
ChapterdtColumn.DataType
14 - Developing Database = Web
System.Type.GetType("System.Int32")
Applications using ASP.NET
ChapterdtColumn.ColumnName
15 - Using ADO.NET in Xml = Web"id"
Services
ChapterdtColumn.Caption = "Cust
16 - ASP.NET Server Controls and ID"
Data Binding
ChapterdtColumn.ReadOnly
17 - Building Real-World=Web True
Applications
ChapterdtColumn.Unique
18 - Object-Relational=Mapping
True in .NET
' Add id Column to the DataColumnCollection.
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
custTable.Columns.Add(dtColumn)
Chapter 20 - COM Interoperability and ADO.NET
' Create Name column.
Chapter 21 - Messaging
dtColumn = New DataColumn()
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
dtColumn.DataType = System.Type.GetType("System.String")
Appendix A - Relational Databases: Some Basic Concepts
dtColumn.ColumnName = "Name"
Appendix B - Commonly Used SQL
dtColumn.Caption Statements
= "Cust Name"
AppendixdtColumn.AutoIncrement =Questions
C - ADO.NET Frequently Asked False
Index dtColumn.ReadOnly = False
List of Figures
dtColumn.Unique = False
List of Tables
' Add Name column to the table.
List of Listings
custTable.Columns.Add(dtColumn)
' Create Address column.
List of Sidebars
dtColumn = New DataColumn()
dtColumn.DataType = System.Type.GetType("System.String")
dtColumn.ColumnName = "Address"
dtColumn.Caption = "Address"
dtColumn.ReadOnly = False
dtColumn.Unique = False
' Add Address column to the table.
custTable.Columns.Add(dtColumn)
' Make the ID column the primary key column.
Dim PrimaryKeyColumns() As DataColumn = New DataColumn(1) {}
PrimaryKeyColumns(0) = custTable.Columns("id")
custTable.PrimaryKey = PrimaryKeyColumns
Appliedthe
' Instantiate ADO.NET:
DataSet Building Data-Driven Solutions
variable.
by Mahesh Chand and David
Dim ds As DataSet = New DataSet("Customers")Talbot ISBN:1590590732
Apress 2003 (928 pages)
' Add the custTable to the DataSet.
This text provides extensive coverage of ADO.NET technology
ds.Tables.Add(custTable)
' Add rows including ADO.NET
to the internals,using
custTable namespaces,
its classes,
NewRowand method
interfaces, and takes a comprehensive look at XML
' I add three customers
namespaces and classes, with thier
and how addresses,
to integrate name and id
both with
Dim row1 ADO.NET.
As DataRow = custTable.NewRow()
row1("id") = 1001
row1("Address") = "43 Lanewood Road, Cito, CA"
Table of Contents
row1("Name") = "George Bishop "
AppliedcustTable.Rows.Add(row1)
ADO.NETBuilding Data-Driven Solutions
Introduction
Dim row2 As DataRow = custTable.NewRow()
Chapterrow2("id")
1 - ADO.NET = Basics
1002
Chapterrow2("Name")
2 - Data Components
= "Rock in Visual
JoeStudio
" .NET
Chapterrow2("Address") = "KingEnvironments
3 - ADO.NET in Disconnected of Prusssia, PA"
ChaptercustTable.Rows.Add(row2)
4 - ADO.NET in Connected Environments
ChapterDim
5 -row3 AsADO.NET
Handling DataRow = custTable.NewRow()
Events
Chapterrow3("id")
6 - Integrating= XML
1003 with ADO.NET
Chapterrow3("Name")
7 - Data Binding=and "Miranda
Windows Forms " Data-Bound Controls
row3("Address") = "279
Chapter 8 - Constraints and Data Relations
P. Avenue, Bridgetown, PA"
custTable.Rows.Add(row3)
Chapter 9 - ADO.NET Exception Handling
'row3.RejectChanges()
Chapter 10 - Working with the ODBC .NET Data Provider
'row2.Delete()
Chapter 11 - Stored Procedures and Views
' Bind dataset to the data grid
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
dataGrid1.DataSource = ds.DefaultViewManager
Chapter
End Sub13 - Developing a Custom Data Provider
Chapter 14 - Developing Database Web Applications using ASP.NET
Chapter 15 - Using ADO.NET in Xml Web Services
Chapter 16 - ASP.NET Server Controls and Data Binding
Caution
Chapter As youReal-World
17 - Building can see from
WebListing 3-10, the Id column of the Customers table is read only (the
Applications
ReadOnly property
Chapter 18 - Object-Relational is True).
Mapping in .NETThat means you won't be able to add data to the table. If you
want toObjects:
Chapter 19 - Mapped add data from the front
Performance end, you need
Considerations and to setBinding
Data the ReadOnly property to False.
Chapter 20 - COM Interoperability and ADO.NET
The output of the program looks like Figure 3-8.
Chapter 21 - Messaging
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Appendix A - Relational Databases: Some Basic Concepts
Appendix B - Commonly Used SQL Statements
Appendix C - ADO.NET Frequently Asked Questions
Index
List of Figures
List of Tables
List of Listings
List of Sidebars
Note To run this program, create a Windows application and drop a DataGrid control on the form.
After that you can either call CreateCustomersTable in Listing 3-3 from the form's Load
event or from a button click handler.You can write a Load event by double-clicking on the form
or by opening the Properties window.
If you uncomment row3.RejectChanges() and row2.Delete() at the end of Listing 3-10, the
RejectChanges method rejects the addition of row 3, and the Delete method deletes row 2.
Applied ADO.NET: Building Data-Driven Solutions
by Mahesh
Listing 3-11: Calling Chand RejectChanges
DataRow's and David Talbot and Delete Methods
ISBN:1590590732
Apress 2003 (928 pages)
This text provides extensive coverage of ADO.NET technology
row3.RejectChanges()
including ADO.NET internals, namespaces, classes, and
row2.Delete()interfaces, and takes a comprehensive look at XML
namespaces and classes, and how to integrate both with
ADO.NET.
TheDataRowState enumeration returns the current state of a row. It's useful during operations when
Table of Contents
you want to know the current state of a row. Table 3-6 lists the values of the DataRowState
Applied ADO.NETBuilding Data-Driven Solutions
enumeration.
Introduction
Chapter 1 - The
Table 3-6: ADO.NET Basics
DataRowState Enumeration Members
Chapter 2 - Data Components in Visual Studio .NET
MEMBER
Chapter DESCRIPTION
3 - ADO.NET in Disconnected Environments
Chapter
Added 4 - ADO.NET
Rowinhas
Connected Environments
been added, and AcceptChanges has not been called.
Chapter 5 - Handling ADO.NET Events
Deleted
Chapter Row was
6 - Integrating XML deleted using the Delete method.
with ADO.NET
Chapter 7 - Data Binding
Detached Row wasandcreated
WindowsbutForms Data-Bound
deleted Controls
before it was added to the collection.
Chapter 8 - Constraints and Data Relations
Modified
Chapter RowException
9 - ADO.NET has beenHandling
modified, but AcceptChanges has not been called yet.
Chapter 10 - Working
Unchanged with
Row the
has ODBC
not .NET Data
changed sinceProvider
the last AcceptChanges was called.
Chapter 11 - Stored Procedures and Views
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
TheRowState
Chapter propertya of
13 - Developing a DataRow
Custom returns the DataRowState enumeration. You can use this to find
Data Provider
out the14
Chapter current state of Database
- Developing a row. ForWeb
example, Listing
Applications 3-12ASP.NET
using calls RowState just after the Delete and
RejectChanges
Chapter methods.in Xml Web Services
15 - Using ADO.NET
Chapter 16 - ASP.NET Server Controls and Data Binding
Listing 3-12: Calling the RowState Property
Chapter 17 - Building Real-World Web Applications
Chapter 18 - Object-Relational Mapping in .NET
row3.RejectChanges()
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
MessageBox.Show(row2.RowState.ToString())
Chapter 20 - COM Interoperability and ADO.NET
row2.Delete()
Chapter 21 - Messaging
MessageBox.Show(row3.RowState.ToString())
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Appendix A - Relational Databases: Some Basic Concepts
Appendix B - Commonly Used SQL Statements
Appendix C - ADO.NET Frequently Asked Questions
The DataRelation
Index
List of Figures
To provide data integrity and consistency, you should use relationships between two tables. You achieve
List of Tables
this relationship by defining a primary key in one table and using a foreign key in the other table. Say a
List of Listings
customer has multiple orders; the Customers table stores the customer details, and the Orders table
List of Sidebars
stores all the order details. To avoid the redundancy of data, you define the primary key of the Customers
table as a foreign key in the Orders table.
In this example, the Customers table is also the parent table, and the Orders table is also the child table.
TheParentRelations property of DataTable represents the parent relationship, and
ChildRelations represents the child relationship.
Caution The data type of both columns, which you're linking through a relationship in the Customers
and the Orders tables, must be identical.
You can also access this relationship though a DataSet using its Relations property. To create a
relationship between two columns, you create two DataColumn objects and pass them as
DataRelation Applied ADO.NET: Building Data-Driven Solutions
arguments.
by Mahesh Chand and David Talbot ISBN:1590590732
Apress
Listing 3-13 shows you how to(928
2003 create a customer/order relationship between the Customers and Orders
pages)
table through theThis
Customers table's
text provides id column,
extensive referenced
coverage as CustId
of ADO.NET in the Orders table. The
technology
DataRelation including ADO.NET
constructor internals,
takes three namespaces,
arguments: classes,
the name and relationship, the first DataColumn,
of the
interfaces, andAfter
and the second DataColumn. takesthat
a comprehensive look at XML
you call DataTable's ParentRelation.Add method with
namespaces and classes, and how to integrate both with
as an argument. (Listing 3-15 shows the full source code of this example.) In this code,
DataRelation ADO.NET.
dtSet is a DataSet object, which we discuss in the following section.
Listing
Table 3-13: Creating a Customer/Order Relationship Using DataRelation
of Contents
Applied ADO.NETBuilding Data-Driven Solutions
Introduction
Private Sub BindData()
ChapterDim
1 -dtRelation
ADO.NET BasicsAs DataRelation
ChapterDim
2 -CustCol
Data Components in Visual Studio
As DataColumn .NET
= dtSet.Tables("Customers").Columns("id")
ChapterDim
3 -orderCol
ADO.NET in As DataColumn
Disconnected = dtSet.Tables("Orders").Columns("CustId")
Environments
ChapterdtRelation
4 - ADO.NET =
in New DataRelation("CustOrderRelation",
Connected Environments CustCol, orderCol)
ChapterdtSet.Tables("Orders").ParentRelations.Add(dtRelation)
5 - Handling ADO.NET Events
ChapterdataGrid1.SetDataBinding(dtSet,"Customers")
6 - Integrating XML with ADO.NET
End Sub
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
Chapter 8 - Constraints and Data Relations
Chapter 9 - ADO.NET Exception Handling
Chapter 10 - Working with the ODBC .NET Data Provider
The DataTable
Chapter 11 - Stored Procedures and Views
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
In the previous
Chapter sectionsa you've
13 - Developing Customseen
Datathat columns and rows are the building blocks of a DataTable. You
Provider
need to work with the DataColumn and DataRow objects to create DataTables and add data to them.
Chapter 14 - Developing Database Web Applications using ASP.NET
Besides creating a DataTable schema and adding rows to it, a DataTable has more to offer. The
Chapter 15 - Using ADO.NET in Xml Web Services
DataTable object represents a DataTable.
Chapter 16 - ASP.NET Server Controls and Data Binding
Chapter 17 -take
First you'll Building Real-World
a look Web Applications
at the DataTable class properties and methods. Table 3-7 describes some
Chapter
common 18DataTable
- Object-Relational Mapping
properties, andin .NET3-8 summarizes some of the common DataTable methods.
Table
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
Chapter 20 - The
Table 3-7: COMDataTable
Interoperability
ClassandProperties
ADO.NET
Chapter 21 - Messaging
PROPERTIES DESCRIPTION
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Appendix
ColumnsA - Relational Databases: Some
Represents allBasic
tableConcepts
columns
Appendix B - Commonly Used SQL Statements
Constraints Represents all table constaints
Appendix C - ADO.NET Frequently Asked Questions
Index
DataSet Returns the DataSet for the table
List of Figures
DefaultView Customized view of the DataTable
List of Tables
ListChildRelation
of Listings Returns child relations for the DataTable
List of Sidebars
ParentRelation Returns parent relations for the DataTable
PrimaryKey Represents an array of columns that function as primary key for the table
Rows All rows of the DataTable
TableName Name of the table
NewRow Creates a new row, which is later added by calling the Rows.Addmethod
Table of Contents
RejectChanges Rejects all changes made after the last AcceptChanges was called
Applied ADO.NETBuilding Data-Driven Solutions
Reset
Introduction Resets a DataTable's original state
Chapter
Select1 - ADO.NET Basics
Gets an array of rows based on the criteria
Chapter 2 - Data Components in Visual Studio .NET
Chapter 3 - ADO.NET in Disconnected Environments
TheDataTable
Chapter classinprovides
4 - ADO.NET methods
Connected and properties to remove, copy, and clone data tables. Not only
Environments
that, but
Chapter 5 you can alsoADO.NET
- Handling apply filters on a DataTable. The Constraints property provides access to all
Events
the constraints
Chapter that a DataTable
6 - Integrating has. You can also access the child/parent relationship using
XML with ADO.NET
ChildRelation
Chapter and ParentRelation.
7 - Data Binding and Windows FormsNow we'll create
Data-Bound two tables-Customers and Orders-and set a
Controls
relationship
Chapter between them.
8 - Constraints To test
and Data this application, you build a Windows application using Visual Basic and
Relations
add a DataGrid control to the form. After that you call the CreateCustomersTable,
Chapter 9 - ADO.NET Exception Handling
CreateOrdersTable, and BindData methods from the form constructor after
Chapter 10 - Working with the ODBC .NET Data Provider
InitializeComonent. The form constructor looks like Listing 3-14.
Chapter 11 - Stored Procedures and Views
Chapter
Listing12 - Oracle,
3-14: Form'sSQLXML, and Other
Constructor .NET Data
Calling Providers
CreateCustomersTable, CreateOrdersTable, and
Chapter 13 - Developing a Custom Data Provider
BindData
Chapter 14 - Developing Database Web Applications using ASP.NET
Chapter 15 - Using ADO.NET in Xml Web Services
Private Sub Form1_Load(ByVal sender As System.Object, _
Chapter 16 - ASP.NET Server Controls and Data Binding
ByVal e As System.EventArgs) Handles MyBase.Load
ChapterCreateCustomersTable()
17 - Building Real-World Web Applications
ChapterCreateOrdersTable()
18 - Object-Relational Mapping in .NET
ChapterBindData()
19 - Mapped Objects: Performance Considerations and Data Binding
Chapter
End Sub20 - COM Interoperability and ADO.NET
Chapter 21 - Messaging
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Appendix A - Relational Databases: Some Basic Concepts
You alsoBneed
Appendix to add aUsed
- Commonly DataSet variable, dtSet, in the beginning of your form:
SQL Statements
Appendix C - ADO.NET Frequently Asked Questions
Public Class Form1
Index
Inherits
List of Figures System.Windows.Forms.Form
Private
List of Tables dtSet As System.Data.DataSet
List of Listings
List of Sidebars
In Listing 3-15, the CreateCustomersTable method creates the Customers data table with Id, Name,
and Address columns and adds three data rows to it. The CreateOrdersTable method creates the
Orders table with OrderId, CustId, Name, and Description columns and adds data to it. The BindData
method creates a customer/orders relationship and binds the data to a DataGrid control using
DataSet.
Table of Contents
Applied ADO.NETBuilding Data-Driven Solutions
Figure 3-9: A DataGrid with data relations
Introduction
Chapter 1
If you click-the
ADO.NET Basics
CustOrderRelation link, the output looks like Figure 3-10.
Chapter 2 - Data Components in Visual Studio .NET
Chapter 3 - ADO.NET in Disconnected Environments
Chapter 4 - ADO.NET in Connected Environments
Chapter 5 - Handling ADO.NET Events
Chapter 6 - Integrating XML with ADO.NET
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
Chapter 8 - Constraints and Data Relations
Chapter 9 - ADO.NET Exception Handling
Chapter 10 - Working with the ODBC .NET Data Provider
Chapter 11 - Stored Procedures and Views
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Chapter 13 - Developing a Custom Data Provider
Chapter 14 - Developing Database Web Applications using ASP.NET
Figure 3-10: Orders record for Customers id 1001
Chapter 15 - Using ADO.NET in Xml Web Services
Chapter
As you 16
can- ASP.NET
see fromServer
FigureControls and Data Binding
3-10,DataGrid shows all the orders for Customer id 1001.
Chapter 17 - Building Real-World Web Applications
Chapter 18 - Object-Relational Mapping in .NET
More DataTable Operations
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
Chapter 20 - COM Interoperability and ADO.NET
Adding and deleting are two common operations when working with databases. You've already learned
Chapter 21 -to
about how Messaging
add data to a DataTable using a DataRow. In this section you'll see how to add, delete,
Chapter 22 - SQL Server
sort, and search and ADO.NET: Notes
data programmatically. on Performance
You'll keep all data in memory in the form of DataTables, but
Appendix A -see
you'll also Relational
a SaveDatabases: Some
option, which willBasic
saveConcepts
data in XML format. This is a simple Windows Forms
Appendix B - Commonly Used SQL Statements
application.
Appendix C - ADO.NET Frequently Asked Questions
The first step is to build a GUI (see Figure 3-11). To build this GUI, you create a Windows Application
Index
project. After that, add a DataGrid control, four Button controls, seven TextBox controls, five
List of Figures
GroupBox controls, and some Label controls. Then adjust them on your form. You can also change the
List of Tables
background color of the controls.
List of Listings
List of Sidebars
Applied ADO.NET: Building Data-Driven Solutions
by Mahesh Chand and David Talbot ISBN:1590590732
Apress 2003 (928 pages)
This text provides extensive coverage of ADO.NET technology
including ADO.NET internals, namespaces, classes, and
interfaces, and takes a comprehensive look at XML
namespaces and classes, and how to integrate both with
ADO.NET.
Table of Contents
Applied ADO.NETBuilding Data-Driven Solutions
Introduction
Chapter 1 - ADO.NET Basics
Chapter 2 - Data Components in Visual Studio .NET
Figure
Chapter 3 - 3-11: Add,
ADO.NET indelete, sort, and
Disconnected search operations in a DataTable
Environments
Chapter 4 - ADO.NET in Connected Environments
In this application,
Chapter 5
we show you all basic common operations such as adding, deleting, sorting, and
- Handling ADO.NET Events
searching rows. The Add Row button reads the name and address, adds a new row in the DataTable,
Chapter 6 - Integrating XML with ADO.NET
and displays the added row in the DataGrid. The Delete Rows button deletes rows based on the entered
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
criteria. To delete rows, you enter the column name and value, and the Delete Rows button will delete all
Chapter 8 - Constraints and Data Relations
the rows that meet the criteria. The Search button reads column name and values entered in the text
Chapter 9 - ADO.NET Exception Handling
boxes and returns data that matches the criteria. The Apply Sort button reads a column and sorts rows
Chapter
based on10 that
- Working with
column. theSave
The ODBCmethod
.NET Data Provider
saves the current data of the DataTable to an XML document.
Chapter 11 - Stored Procedures and Views
Note
Chapter 12 You don'tSQLXML,
- Oracle, have to create the .NET
and Other sameData
formProviders
as shown in Figure 3-11. The only thing you need to
Chapter 13 have is a DataGrid
- Developing a Customwith
Datathe same number of TextBox and Button controls.
Provider
Chapter 14 - Developing Database Web Applications using ASP.NET
Now, you change the names of the form controls and add the DataSet variable dtSet and the
Chapter 15 - Using ADO.NET in Xml Web Services
DataTable variable custTable to the beginning of the form. Besides the variables defined for the
Chapter 16 - ASP.NET Server Controls and Data Binding
controls (see the MoreDataTableOpsSamp sample available with the source code for details), add two
Chapter 17 - Building Real-World Web Applications
variables of type DataTable and DataSet, as shown in Listing 3-16.
Chapter 18 - Object-Relational Mapping in .NET
Chapter
Listing19 - Mapped
3-16: Objects:
Class-Level Performanceand
DataTable Considerations and Data Binding
DataSet Variables
Chapter 20 - COM Interoperability and ADO.NET
Chapter 21 - Messaging
Private custTable As DataTable
Chapter
Private22 -dtSet
SQL Server
As and ADO.NET: Notes on Performance
DataSet
Appendix A - Relational Databases: Some Basic Concepts
Appendix B - Commonly Used SQL Statements
Appendix C - ADO.NET Frequently Asked Questions
Now you create the Customers table with three columns: id, Name, and Address. You've already learned
Index
how
List of to add columns to a DataTable using a DataColumn and binding it to a DataGrid. The
Figures
CreateCustomersTable
List of Tables method creates the Customers table. After creating the Customers table, you
addofthe
List DataTable to the DataSet using the DataSet.Tables.Add method. The
Listings
CreateCustomersTable
List of Sidebars method looks like Listing 3-17.
As you can see from Figure 3-12, the Add Row button adds a new row to the Customers' DataTable with
the Name and Address columns reading from the Name and Address text boxes. The Delete Rows button
deletes the row number inserted in the Enter Row # text box. The Search button searches and returns
rows that contain the name entered in the Enter Name text box of the Search group box.
Applied ADO.NET: Building Data-Driven Solutions
by Mahesh Chand and David Talbot ISBN:1590590732
Apress 2003 (928 pages)
This text provides extensive coverage of ADO.NET technology
including ADO.NET internals, namespaces, classes, and
interfaces, and takes a comprehensive look at XML
namespaces and classes, and how to integrate both with
ADO.NET.
Table of Contents
Applied ADO.NETBuilding Data-Driven Solutions
Introduction
Chapter 1 - ADO.NET Basics
Chapter 2 - Data Components in Visual Studio .NET
Chapter 3 - 3-12:
Figure ADO.NET in Disconnected
Adding rows to the Environments
DataTable
Chapter 4 - ADO.NET in Connected Environments
Chapter
OK, now5 it's
- Handling ADO.NET
time to write codeEvents
for the button event handlers. You can write button event handlers by
double-clicking
Chapter the buttons
6 - Integrating XML or using
with the Properties windows. First, you write the event handler for the Add
ADO.NET
Row button
Chapter with the
7 - Data handler
Binding and name AddRow_Click.
Windows After
Forms Data-Bound that, write event handlers for the Delete Rows
Controls
and Search
Chapter buttons; theand
8 - Constraints event handler
Data names for these buttons are DeleteRow_Click and
Relations
SearchButton_Click,
Chapter respectively.
9 - ADO.NET Exception Handling
Chapter 10 - Working with the ODBC .NET Data Provider
You add a new row to the DataTable using DataRow and call the Add and AcceptChanges methods
Chapter 11 - Stored Procedures and Views
of the DataTable.Listing 3-18 shows the Add Row button click event handler.
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Chapter
Listing13 - Developing
3-18: a Custom Data Provider
The AddRowBtn_Click Method
Chapter 14 - Developing Database Web Applications using ASP.NET
Chapter 15 - Using ADO.NET in Xml Web Services
Private Sub AddRowBtn_Click(ByVal sender As System.Object, _
Chapter
ByVal16 -eASP.NET Server Controls and Data
As System.EventArgs) Binding AddRowBtn.Click
Handles
Chapter'17 - Building Real-World Web Applications
Add rows to the custTable using its NewRow method
Chapter'18
I -add
Object-Relational Mapping inwith
three customers .NET thier addresses, name and id
ChapterDim
19 -myDataRow
Mapped Objects:
As Performance
DataRow =Considerations and Data Binding
custTable.NewRow()
ChaptermyDataRow("Name")
20 - COM Interoperability= and ADO.NET
TextBox4.Text.ToString()
ChaptermyDataRow("Address")
21 - Messaging = TextBox5.Text.ToString()
ChaptercustTable.Rows.Add(myDataRow)
22 - SQL Server and ADO.NET: Notes on Performance
custTable.AcceptChanges()
Appendix A - Relational Databases: Some Basic Concepts
RefreshData()
Appendix B - Commonly Used SQL Statements
End Sub
Appendix C - ADO.NET Frequently Asked Questions
Index
List of Figures
List of Tables
As you can see, the code adds Name as TextBox4.Text and Address as TextBox4.Text.
List of Listings
List
You of call
Sidebars
NewRow of DataTable to add a new row to DataTable, set its field values, and call the
DataTable.Rows.Add method to add it. After the Add method, you also call
DataTable.AcceptChanges method to save the changes. At the end, you call the RefreshData
method to fill the DataGrid with the records.
If you add six rows to the DataTable using the Add Row button, the result looks like Figure 3-12.
The Delete Rows button deletes the records from a column that matches the given criteria. The Remove
Rows Section takes a column name and column value, and the Delete Rows button click event handler
removes the rows from the DataTable.
TheDeleteRowsBtn_Click method is the click event handler for the Delete Rows button (see Listing
3-19). As you can see, the code uses the Select method of DataTable. The Select method of
DataTable takes a criterion and returns the rows that meet the given criteria. In this case, you pass a
column name and Applied ADO.NET:
its value Building
as a criterion. TheData-Driven Solutions
Select method returns all the matching rows in an array of
by Mahesh Chand and David Talbot ISBN:1590590732
DataRow. Once you've retrieved these rows, you call DataRow.Delete method to delete the rows one
by one, followed Apress 2003
by a call (928 pages)
of DataRow.AcceptChanges method to save the changes.
This text provides extensive coverage of ADO.NET technology
Listing 3-19: Theincluding ADO.NET internals,
DeleteRow_Click Methodnamespaces, classes, and
interfaces, and takes a comprehensive look at XML
namespaces and classes, and how to integrate both with
ADO.NET.
Private Sub DeleteRowsBtn_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles DeleteRowsBtn.Click
Dim str As String = TextBox7.Text + "='" + TextBox6.Text + "'"
Table of Contents
Dim rows() As DataRow = custTable.Select(str)
Applied ADO.NETBuilding Data-Driven Solutions
' If no record found
Introduction
If rows.Length = 0 Then
Chapter 1 MessageBox.Show("Record
- ADO.NET Basics not found!")
Chapter 2 Return
- Data Components in Visual Studio .NET
ChapterEnd
3 -If ADO.NET in Disconnected Environments
ChapterDim
4 -iADO.NET in Connected Environments
As Integer
ChapterFor
5 -iHandling
= 0 To ADO.NET Events
rows.Length - 1 Step i + 1
Chapter 6 rows(i).Delete()
- Integrating XML with ADO.NET
Chapter 7 rows(i).AcceptChanges()
- Data Binding and Windows Forms Data-Bound Controls
Next
Chapter 8 - Constraints and Data Relations
ChapterRefreshData()
9 - ADO.NET Exception Handling
End Sub
Chapter 10 - Working with the ODBC .NET Data Provider
Chapter 11 - Stored Procedures and Views
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Chapter 13 - Developing a Custom Data Provider
In the end, you call the RefreshData method to refresh the grid.
Chapter 14 - Developing Database Web Applications using ASP.NET
Chapter
As you 15
can- Using ADO.NET
see from Figurein3-13,
Xml Web
if youServices
enter column name as Name with the value Puneet, then the
Chapter
Delete 16 - ASP.NET
Rows Server Controls
button removes the row and Data
with Id =Binding
102.
Chapter 17 - Building Real-World Web Applications
Chapter 18 - Object-Relational Mapping in .NET
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
Chapter 20 - COM Interoperability and ADO.NET
Chapter 21 - Messaging
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Appendix A - Relational Databases: Some Basic Concepts
Appendix B - Commonly Used SQL Statements
Appendix C - ADO.NET Frequently Asked Questions
Index
List of Figures
List of Tables
List of Listings
List of Sidebars
You just saw the usage of the DataTable.Select method, which sorts and filters the DataTable rows.
TheSelect method has four overloaded forms. The Select method can take an expression with
optional sort and row state parameters.
Afilter is a conditional statement that uses the SELECTWHERE clause to select conditional data from the
database. All SQL conditional operators are valid in the filter string. For example, to filter rows where the id
is greater than 22, the filter string will be Id>22; for selecting records with the name Ross, the filter string
will be Name='Ross'. The SeachBtn_Click method searches for the criteria you specify on the form.
Applied
As you can see from ADO.NET:
Listing 3-20, theBuilding
code firstData-Driven Solutions
calls the Select method with the given criteria, which
by Mahesh Chand and David Talbot
returns an array of DataRow objects. It creates a new DataTable ISBN:1590590732
called searchTable and adds all
rows returned by Apress 2003 (928
the Select pages)to this DataTable, and it later binds the searchTable to
method
DataGrid to view This
thetext provides extensive coverage of ADO.NET technology
rows.
including ADO.NET internals, namespaces, classes, and
Listing 3-20: Theinterfaces, and takes a comprehensive
SearchButtonClick Method look at XML
namespaces and classes, and how to integrate both with
ADO.NET.
Private Sub SearchBtn_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles SearchBtn.Click
Table of Contents
Applied ADO.NETBuilding Data-Driven Solutions
Dim searchTable As DataTable = New DataTable("SortTable")
Introduction
searchTable = custTable.Clone()
ChapterDim
1 -strADO.NET Basics
As String = TextBox1.Text & " ='" & TextBox2.Text + "'"
ChapterDim
2 -rows()
Data Components in Visual
As DataRow = Studio .NET
custTable.Select(str)
Chapter'3 If- ADO.NET
no recordin Disconnected
found Environments
ChapterIf
4 rows.Length
- ADO.NET in Connected
= 0 Then Environments
Chapter 5 MessageBox.Show("Name
- Handling ADO.NET Events not found!")
Chapter 6 Return
- Integrating XML with ADO.NET
ChapterEnd
7 -If Data Binding and Windows Forms Data-Bound Controls
Dim i As Integer
Chapter 8 - Constraints and Data Relations
For i = 0 ToException
Chapter 9 - ADO.NET rows.Length
Handling - 1 Step i + 1
Chapter 10 - Working with the ODBC =
Dim row As DataRow searchTable.NewRow()
.NET Data Provider
row("Name") = rows(i)("Name")
Chapter 11 - Stored Procedures and Views
row("Address") = rows(i)("Address")
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
searchTable.Rows.Add(row)
Chapter 13 - Developing a Custom Data Provider
Next
Chapter 14 - Developing Database Web Applications using ASP.NET
Dim sortdtSet As DataSet = New DataSet("SortedData")
Chapter 15 - Using ADO.NET in Xml Web Services
sortdtSet.Tables.Add(searchTable)
Chapter 16 - ASP.NET Server Controls and Data Binding
DataGrid1.DataSource = sortdtSet.DefaultViewManager
Chapter
End Sub17 - Building Real-World Web Applications
Chapter 18 - Object-Relational Mapping in .NET
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
Chapter 20 - COM Interoperability and ADO.NET
Now using
Chapter 21 -the Search Section text boxes, you can search for records with the name Amy by entering
Messaging
Name in
Chapter 22the Enter
- SQL Column
Server Name box,Notes
and ADO.NET: entering Amy in the Enter Value box, and clicking the Search
on Performance
button. The
Appendix result looks
A - Relational like Figure
Databases: 3-14.
Some Basic Concepts
Appendix B - Commonly Used SQL Statements
Appendix C - ADO.NET Frequently Asked Questions
Index
List of Figures
List of Tables
List of Listings
List of Sidebars
Table of Contents
Listing 3-21: Sorting Data Using the Select Method
Applied ADO.NETBuilding Data-Driven Solutions
Introduction
Private Sub SortBtn_Click(ByVal sender As System.Object, _
Chapter 1
ByVal -eADO.NET Basics
As System.EventArgs) Handles SortBtn.Click
Chapter 2 - Data Components in Visual Studio .NET
ChapterDim
3 -sortTable
ADO.NET in Disconnected
As DataTableEnvironments
= New DataTable("SortTable")
ChaptersortTable
4 - ADO.NET
= incustTable.Clone()
Connected Environments
ChapterDim
5 -strSort
Handling ADO.NET Events= TextBox3.Text
As String
ChapterIf
6 (CheckBox1.Checked)
- Integrating XML with ADO.NET
Then
Chapter 7 strSort
- Data Binding and Windows
= strSort & " Forms
DESC"Data-Bound Controls
ChapterElse
8 - Constraints and Data Relations
Chapter 9 strSort = Exception
- ADO.NET strSortHandling
& " ASC"
ChapterEnd
10 -If
Working with the ODBC .NET Data Provider
ChapterDim
11 -rows() As DataRow
Stored Procedures = _
and Views
ChaptercustTable.Select(String.Empty,
12 - Oracle, SQLXML, and Other .NET Data strSort)
Providers
Dim i As Integer
Chapter 13 - Developing a Custom Data Provider
For i = 0 To rows.Length - 1 Step i + 1
Chapter 14 - Developing Database Web Applications using ASP.NET
Dim row As DataRow = sortTable.NewRow()
Chapter 15 - Using ADO.NET in Xml Web Services
row("Name") = rows(i)("Name")
Chapter 16 - ASP.NET Server Controls and Data Binding
row("Address") = rows(i)("Address")
Chapter 17 - Building Real-World Web Applications
sortTable.Rows.Add(row)
ChapterNext
18 - Object-Relational Mapping in .NET
ChapterDim
19 -sortdtSet
Mapped Objects:
As Performance
DataSet =Considerations and Data Binding
New DataSet("SortedData")
ChaptersortdtSet.Tables.Add(sortTable)
20 - COM Interoperability and ADO.NET
ChapterDataGrid1.DataSource
21 - Messaging = sortdtSet.DefaultViewManager
Chapter
End Sub22 - SQL Server and ADO.NET: Notes on Performance
Appendix A - Relational Databases: Some Basic Concepts
Appendix B - Commonly Used SQL Statements
Appendix C - ADO.NET Frequently Asked Questions
To sort the records, you enter the column name Name and check the DESC check box. Now, if you click
Index
theofApply
List Sort button, you'll see the records are sorted on the name. If you uncheck the DESC check box,
Figures
you'll see the rows sorted in ascending order.
List of Tables
List
The of last
Listings
thing to do in this example is to create the Save button. The DataSet class provides methods to
List
readof Sidebars
and write XML documents. The WriteXml method of DataSet saves data to an XML document.
(We discuss XML and ADO.NET in more detail in Chapter 6.)
Listing 3-22 shows the Save method button click event handler. As you can see, the code calls a
SaveFileDialog and reads the name and path of the file. You can browse the path where you want to
save the file. After saving data, if you open the XML file, you'll see all data from the DataTable is stored in
this file.
Table of Contents
Applied ADO.NETBuilding Data-Driven Solutions
The Row and Column Collections
Introduction
Chapter 1 - ADO.NET Basics
Do you remember the Rows and Columns property of DataTable? As mentioned earlier, the Columns
Chapter 2 - Data Components in Visual Studio .NET
property of DataSet, represented by a DataColumnCollection object, stands for all columns of a
Chapter 3 - ADO.NET
DataTable. The Rowsin Disconnected Environmentsrepresents a collection of rows of a DataTable.
property of DataTable
Chapter 4 - ADO.NET in Connected Environments
Generally, you access the rows and columns collections through the Rows and Columns properties of a
Chapter 5 - Handling
DataTable. You've ADO.NET Events
already seen how to add columns and rows to a DataTable in the previous sections.
Chapter 6 - Integrating XML with ADO.NET
In the following sections, we discuss the methods and properties.
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
Chapter 8
- Constraints and Data Relations
The DataRowCollection
Chapter 9
- ADO.NET Exception Handling
Class
Chapter 10 - property
TheCount Working with the ODBC .NET Data Provider
of DataRowCollection returns the total number of rows in a collection. The
Chapter 11 code
following - Stored Procedures
reads the total and Views
number of rows in custTable:
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Chapter 13 - Developing
Dim rows a Custom Data Provider
As DataRowCollection = custTable.Rows
Chapter 14 - Developing
Dim counter Database Web Applications using ASP.NET
As Integer
Chapter
counter15 -=Using ADO.NET in Xml Web Services
rows.Count
Chapter 16 - ASP.NET Server Controls and Data Binding
Chapter 17 - Building Real-World Web Applications
TheClear
Chapter 18 - method of DataRowCollection
Object-Relational Mapping in .NET removes all the rows in a collection and sets the Rows
count to19zero:
Chapter - Mapped Objects: Performance Considerations and Data Binding
Chapter 20 - COM Interoperability and ADO.NET
Dim rows
Chapter As DataRowCollection = custTable.Rows
21 - Messaging
rows.Clear()
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Appendix A - Relational Databases: Some Basic Concepts
Appendix B - Commonly Used SQL Statements
TheRemove and RemoveAt methods remove a specified DataRow based on the DataRow and its index,
Appendix C - ADO.NET Frequently Asked Questions
respectively.
Index
The
List ofContains
Figures method looks for a primary key value in the collection. This method returns True if a
collection
List finds the specified value in the primary key column. The Contains method takes an argument
of Tables
of an
List object type.
of Listings
List of Sidebars
TheFind method is one more useful method of DataRowCollection; it searches for a row in the
collection. Similar to the Contains method, the Find method also takes an argument of object type,
which means Find can be used to find any types of values.
Listing 3-23 checks if the row collection's primary key column contains value 1002. If it does, it uses the
Find method, which returns a DataRow and calls the DataRowCollection.Remove method to
remove the row from the collection.
Table of Contents
As you saw in earlier sections, the Add method of DataRowCollection adds a new row at the end of a
Applied ADO.NETBuilding
collection. But what if youData-Driven Solutions
want to insert a row between two rows? The InsertAt method does the trick
Introduction
for you and inserts a row at the specified index, and the row at the index becomes the next row. Listing 3-
24 inserts
Chapter 1 -and removes
ADO.NET rows at the specified index using the InsertAt and RemoveAt methods.
Basics
Chapter 2 - Data Components in Visual Studio .NET
Listing 3-24:
Chapter 3
Using the InsertAt and RemoveAt Methods
- ADO.NET in Disconnected Environments
Chapter 4 - ADO.NET in Connected Environments
Dim newRow
Chapter As DataRow
5 - Handling ADO.NET Events
newRow
Chapter 6 =- Integrating
custTable.NewRow()
XML with ADO.NET
newRow("id")
Chapter = 1005
7 - Data Binding and Windows Forms Data-Bound Controls
newRow("Address")
Chapter = Data
8 - Constraints and "NewRelations
Address"
newRow("Name")
Chapter 9 - ADO.NET = "New Name"
Exception Handling
rows.InsertAt(newRow, 3)
Chapter 10 - Working with the ODBC .NET Data Provider
Chapter 11 - Stored Procedures and Views
If (Not rows(1).IsNull("id")) Then
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
rows.RemoveAt(1)
Chapter 13 - Developing a Custom Data Provider
End If
Chapter 14 - Developing Database Web Applications using ASP.NET
Chapter 15 - Using ADO.NET in Xml Web Services
Chapter 16 - ASP.NET Server Controls and Data Binding
Chapter 17 - Building Real-World Web Applications
The DataColumnCollection Class
Chapter 18 - Object-Relational Mapping in .NET
Similar19
Chapter to DataRowCollection, the Count
- Mapped Objects: Performance property of
Considerations DataColumnCollection
and Data Binding returns the number
of columns
Chapter 20 - in
COMa collection. You already
Interoperability saw in previous samples that you can use the Add method to add
and ADO.NET
a new column
Chapter to a collection.
21 - Messaging
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
You can use the CanRemove method to find out if a column can be removed from a collection. It returns
Appendix A - Relational Databases: Some Basic Concepts
True if a column can be removed from a collection; otherwise, it returns False. This method performs
Appendix B - Commonly Used SQL Statements
several operations to make sure the column exists in the table and it's not involved in a constraint or
Appendix
relation. CThe
- ADO.NET Frequently
Contains methodAsked Questions
checks if a column with a given name exists in the collection.
Index
The
List Figures and RemoveAt methods remove a column from a collection. The Remove method takes a
ofRemove
parameter
List of Tablesof type DataColumn or a name of the column. Listing 3-25 uses some of these methods.
List of Listings
Listing 3-25: Removing a Column from a Collection
List of Sidebars
ADataRowView class represents a customized view of a DataRow, which can be bound to data-bound
controls such as a DataGrid. When you work with a DataRow (update data of a DataRow), the
DataRow has different versions. These states are represented by a DataRowVersion enumeration,
which has four values: Current,Default,Proposed , and Original. The version of a DataRow
changes when you call the BeginEdit,CancelEdit, and EndEdit methods of DataRow as well as
theAcceptChanges and RejectChanges methods of DataTable.
After calling DataRow.BeginEdit and changing the value of a row, both the Current and Proposed
values become available. After calling DataRow.CancelEdit, the Proposed value isn't available. After
Applied ADO.NET:
a call of DataRow.EndEdit, Buildingvalue
the Current Data-Driven
becomesSolutions
the Proposed value, and the Proposed
by Mahesh Chand and David Talbot
value becomes unavailable. The call of DataRow.AcceptChanges ISBN:1590590732
means the original value becomes
Apress 2003 (928 pages)
identical to the Current value. A call of DataTable.RejectChanges means the Proposed value is
This text
removed. The version provides
becomes extensive coverage of ADO.NET technology
Current.
including ADO.NET internals, namespaces, classes, and
interfaces,
TheDataView property and takes a comprehensive
of DataRowView look
class returns at XML
a DataView object for a row, which can be
namespaces and classes, and how to integrate both with
bound to data-bound controls.
ADO.NET.
The IsEdit and IsNew properties represent whether a row is in edit mode
or new mode, respectively. The DataRow property returns the DataRow being viewed, and the
RowVersion property returns the version of a row.
Table of Contents
TheBeginEdit
Applied method Data-Driven
ADO.NETBuilding starts editingSolutions
a row, and the CancelEdit method cancels editing. The Delete
method deletes a row, and the EndEdit method ends the editing. Listing 3-27 starts editing a row and
Introduction
later calls the CancelEdit and EndEdit methods, followed by the AcceptChanges method.
Chapter 1 - ADO.NET Basics
Chapter
Listing23-27:
- Data Components
Editing in Visual
Rows Using Studio .NETCancelEdit, and EndEdit Methods
BeginEdit,
Chapter 3 - ADO.NET in Disconnected Environments
Chapter 4 - ADO.NET in Connected Environments
Dim row As DataRow
Chapter 5 - Handling ADO.NET Events
row = custTable.NewRow()
Chapter 6 - Integrating XML with ADO.NET
MessageBox.Show(row.RowState.ToString())
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
row("id") = 1007
Chapter 8 - Constraints and Data Relations
row("Name") = "Noak "
Chapterrow("Address")
9 - ADO.NET Exception Handling
= "Tame Lack, NJ"
ChaptercustTable.Rows.Add(row)
10 - Working with the ODBC .NET Data Provider
ChapterMessageBox.Show(row.RowState.ToString())
11 - Stored Procedures and Views
ChaptercustTable.Rows.Remove(row)
12 - Oracle, SQLXML, and Other .NET Data Providers
ChaptercustTable.AcceptChanges()
13 - Developing a Custom Data Provider
Chapter 14 - Developing Database Web Applications using ASP.NET
Chapter'15
Start
- UsingEditing the
ADO.NET in Xml Row
Web Services
ChaptercustTable.Rows(0).BeginEdit()
16 - ASP.NET Server Controls and Data Binding
ChaptercustTable.Rows(0)("id") = 1008
17 - Building Real-World Web Applications
ChaptercustTable.Rows(0)("Name") = "New Name"
18 - Object-Relational Mapping in .NET
ChaptercustTable.Rows(0)("Address") = "New Address"
19 - Mapped Objects: Performance Considerations and Data Binding
' Find out DataRowVersion
Chapter 20 - COM Interoperability and ADO.NET
If custTable.Rows(0).HasVersion(DataRowVersion.Proposed) Then
Chapter 21 - Messaging
MessageBox.Show(DataRowVersion.Proposed.ToString())
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
End If
Appendix A - Relational Databases: Some Basic Concepts
If custTable.Rows(0).HasVersion(DataRowVersion.Original) Then
Appendix B - Commonly Used SQL Statements
MessageBox.Show(DataRowVersion.Original.ToString())
AppendixEnd C -If
ADO.NET Frequently Asked Questions
Index ' Cancel the edit.
List of Figures
custTable.Rows(0).CancelEdit()
List of Tables
' BeginEdit again
List of Listings
custTable.Rows(0).BeginEdit()
List of Sidebars
custTable.Rows(0)("id") = 1008
custTable.Rows(0)("Name") = "New Name"
custTable.Rows(0)("Address") = "New Address"
custTable.Rows(0).EndEdit()
custTable.Rows(0).AcceptChanges()
DataGrid1.DataSource = custTable
Using DataSet,
AppliedDataView, andData-Driven
ADO.NET: Building DataViewManager
Solutions
by Mahesh Chand and David Talbot ISBN:1590590732
As you saw in Chapter
Apress2, ADO.NET
2003 provides components to view data in data-bound controls. You just
(928 pages)
drag and drop controls to a form, set their properties,
This text provides extensive and
coverage of bind them
ADO.NET to data-bound controls. Then you're
technology
all set to run yourincluding
programs. ADO.NET internals, namespaces, classes, and classes fall into this category. You
The DataView and DataViewManager
interfaces,
can use these classes and takes
to represent a comprehensive
different views of alook at XML
DataTable based on different filter and sort
criterion. You cannamespaces and classes,
use these classes eitherand how to integrate
at design-time or atboth with
runtime.
ADO.NET.
ADataSet is a key component in the ADO.NET data model. It's an in-memory representation of one or
multipleDataTables, relations, and constraints. A DataSet stores data from a data source and provides
Table of Contents
data to the client applications (Web Forms or Windows Forms). A DataSet's contents can be bound to
Applied ADO.NETBuilding Data-Driven Solutions
data-bound controls. (We discuss the DataSet class in more detail in "TheDataSet: The Heart of
Introduction
ADO.NET."
Chapter 1 - ADO.NET Basics
Chapter 2 - DataisComponents
TheDataView useful wheninyou
Visual
needStudio .NET
to bind a DataTable or multiple DataTable objects with data-
Chapter 3 - ADO.NET
bound controls. in Disconnected
You can Environments
also represent multiple views of the same data by applying a filter and sort on a
DataTable,
Chapter and youincan
4 - ADO.NET bind these
Connected multiple views to different data-bound controls such as DataGrid,
Environments
DataList,
Chapter 5 - ComboBox, and ListBox
Handling ADO.NET Events controls.
Chapter 6 - Integrating XML with ADO.NET
Figure 3-15 shows the relationship between a DataSet,DataTable,DataView, and Windows and Web
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
Forms controls. As you can see, a DataSet contains three DataTable objects, which are represented
Chapter 8 - Constraints and Data Relations
by three different views. You can bind the three different DataView objects to different data-bound
Chapter 9 - ADO.NET Exception Handling
controls to represent data in different ways.
Chapter 10 - Working with the ODBC .NET Data Provider
Chapter 11 - Stored Procedures and Views
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Chapter 13 - Developing a Custom Data Provider
Chapter 14 - Developing Database Web Applications using ASP.NET
Chapter 15 - Using ADO.NET in Xml Web Services
Chapter 16 - ASP.NET Server Controls and Data Binding
Chapter 17 - Building Real-World Web Applications
Chapter 18 - Object-Relational Mapping in .NET
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
Chapter 20 - COM Interoperability and ADO.NET
Chapter 21 - Messaging
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Appendix A - Relational Databases: Some Basic Concepts
Appendix B - 3-15:
Figure Commonly Used SQLbetween
Relationship Statements
the DataSet,DataTable, and DataView
Appendix C - ADO.NET Frequently Asked Questions
Index
Table of Contents
Applied ADO.NETBuilding Data-Driven Solutions
Introduction
Figure 3-16: The relationship between DataSet,DataAdapter, and DataView objects
Chapter 1 - ADO.NET Basics
As you 2saw
Chapter earlier,
- Data a DataSet
Components can have
in Visual multiple
Studio .NET DataTable objects. The DataTableCollection
object represents
Chapter 3 - ADO.NETall DataSet objects
in Disconnected related to a DataSet. The Tables property of the DataSet
Environments
represents
Chapter 4 - the collection
ADO.NET of DataTable
in Connected objects. The tables relate to each other with DataRelation
Environments
objects, discussed
Chapter 5
earlier. DataRelationCollection represents all the available relations in the
- Handling ADO.NET Events
DataSet. The Relations property represents the DataRelationCollection of a DataSet. A
Chapter 6 - Integrating XML with ADO.NET
DataSet object stores data in XML format. An XML schema represents a DataSet. A DataSet also
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
defines methods to read and write XML documents. The ReadXml method reads an XML document and
Chapter 8 - Constraints and Data Relations
fills the DataSet with the XML data, and the WriteXML method writes DataSet data to an XML
Chapter 9 - ADO.NET Exception Handling
document. This class also defines the methods ReadXmlSchema and WriteXmlSchema to read and
Chapter 10 - Working with the ODBC .NET Data Provider
write XML schema.
Chapter 11 - Stored Procedures and Views
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Creating a DataSet
Chapter 13 - Developing a Custom Data Provider
Chapter 14 - Developing
TheDataSet Database
class provides Web
three Applications
overloaded using ASP.NET
constructors to create a DataSet object. You create a
Chapter 15 - Using ADO.NET in Xml Web Services
DataSet with or without passing a DataSet name in the DataSet contructor. The following code
Chapter
creates16 - ASP.NET
two DataSet Server Controls
objects and Data
in different Binding
ways:
Chapter 17 - Building Real-World Web Applications
Chapter 18 - Object-Relational Mapping in .NET
Dim dtSet1 As DataSet
Chapter
dtSet1 19 =- Mapped Objects: Performance Considerations and Data Binding
New DataSet("DataSet1")
Chapter 20 - COMAs
Dim dtSet2 Interoperability
DataSet = and ADO.NET
New DataSet("DataSet2")
Chapter 21 - Messaging
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
The DataSet
Appendix Properties
A - Relational Databases: Some Basic Concepts
Appendix B - Commonly Used SQL Statements
You justClearned
Appendix howFrequently
- ADO.NET to create aAsked
DataSet object. In most cases, you'll probably create a DataSet and
Questions
use the DataAdapter'sFill and Update methods to fill and save data from a data source. But the
Index
DataSet class provides properties that you can get and set as needed.
List of Figures
List
The ofCaseSensitive
Tables property indicates whether the string comparison within DataTable objects is case
List of Listings
sensitive. This property affects how sorting, searching, and filtering operations are performed on
List of Sidebarsobjects of a DataSet, when |you use the Select method of DataTable to filter and sort
DataTable
data. By default the |CaseSensitive property is False. Use the following to set it to True:
DtSet1.CaseSensitive = True
TheDataSetName property represents the name of a DataSet. The following code first sets a DataSet
name and then displays it in a message box:
As mentioned earlier (and in more detail in Chapter 6), a DataSet is represented by an XML schema,
which has a namespace and prefix. The Namespace and Prefix properties represent the namespace
and prefix of the schema, respectively. These properties are both readable and writeable:
dtSet1.Namespace = "CustDSNamespace"
dtSet1.Prefix = "CustPrefix"
Applied ADO.NET: Building Data-Driven Solutions
TheRelations by property
Maheshreturns
Chandaand collection of relations that aISBN:1590590732
David Talbot DataSet has. (We discuss this property
in later sections and in Chapter
Apress 4.)pages)
2003 (928
This text provides extensive coverage of ADO.NET technology
As discussed earlier, the Tables
including ADO.NETproperty
internals,ofnamespaces,
a DataSet classes,
represents
anda collection of DataTables attached
to a DataSet. The Tablesand
interfaces, property
takes aiscomprehensive
of type DataTableCollection,
look at XML which was discussed earlier.
namespaces and
TheDataTableCollection classes,
class and how
provides to integrate
methods to add both with
and remove DataTable objects to a
ADO.NET.
collection.
Attaching
Table a DataTable
of Contents to a DataSet
Applied ADO.NETBuilding Data-Driven Solutions
You've already seen how to create a DataTable and add columns and rows to a DataTable by using
Introduction
theDataRow and DataColumn. As mentioned earlier, a DataSet is a collection of DataTable objects.
Chapter 1 - ADO.NET
TheTables propertyBasics
of DataSet gets all the attached DataTables of a DataSet. The Tables
Chapter 2 which
property, - DataisComponents in Visual Studio .NET
a type of DataTableCollection, also adds DataTable objects to a DataSet and
Chapter
removes3 them.
- ADO.NET
Listingin3-29
Disconnected Environments
creates four DataTable objects and adds them to a DataSet using the
Chapter 4 - ADO.NET in Connected
DataSet.Tables.Add method. Environments
The DataSet is bound to a DataGrid to view the contents in a
Chapter 5 - Handling ADO.NET Events
DataGrid.
Chapter 6 - Integrating XML with ADO.NET
Listing73-29:
Chapter Adding
- Data DataTable
Binding Objects
and Windows Formsto a DataSet
Data-Bound Controls
Chapter 8 - Constraints and Data Relations
Chapter 9 - ADO.NET
Dim tbl1 Exception =Handling
As DataTable New DataTable("One")
Dim tbl2
Chapter As DataTable
10 - Working = New
with the ODBC .NETDataTable("Two")
Data Provider
Dim tbl3
Chapter As DataTable
11 - Stored = New
Procedures and ViewsDataTable("Three")
Dim dtSet1
Chapter As SQLXML,
12 - Oracle, DataSetand
= Other
New .NET
DataSet("CustDtSet")
Data Providers
dtSet1.Tables.Add(custTable)
Chapter 13 - Developing a Custom Data Provider
dtSet1.Tables.Add(tbl1)
Chapter 14 - Developing Database Web Applications using ASP.NET
dtSet1.Tables.Add(tbl2)
Chapter 15 - Using ADO.NET in Xml Web Services
dtSet1.Tables.Add(tbl3)
Chapter 16 - ASP.NET Server Controls and Data Binding
DataGrid1.DataSource = dtSet1.DefaultViewManager
Chapter 17 - Building Real-World Web Applications
Chapter 18 - Object-Relational Mapping in .NET
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
Chapter 20 - COM
In this code, Interoperability
custTable and ADO.NET
is a DataTable created using the methods discussed.
Chapter 21 - Messaging
The output
Chapter 22 - of
SQLListing 3-29
Server andlooks like Figure
ADO.NET: Notes 3-17. If you click a DataTable link, you can see the data of
on Performance
theDataTable
Appendix (if it has
A - Relational any). Some Basic Concepts
Databases:
Appendix B - Commonly Used SQL Statements
Appendix C - ADO.NET Frequently Asked Questions
Index
List of Figures
List of Tables
List of Listings
List of Sidebars
Applied ADO.NET: Building Data-Driven Solutions
by Mahesh Chand and David Talbot ISBN:1590590732
Apress 2003 (928 pages)
This text provides extensive coverage of ADO.NET technology
including ADO.NET internals, namespaces, classes, and
interfaces, and takes a comprehensive look at XML
namespaces and classes, and how to integrate both with
ADO.NET.
Table of Contents
Applied ADO.NETBuilding Data-Driven Solutions
Introduction
Chapter 1 - ADO.NET Basics
Chapter 2 - Data Components in Visual Studio .NET
Chapter 3 - ADO.NET in Disconnected Environments
Chapter 4 - ADO.NET in Connected Environments
Chapter 5 - Handling ADO.NET Events
Chapter 6 - Integrating XML with ADO.NET
Chapter 7 - 3-17:
Figure Data Binding and
Attaching Windows Forms
DataTables to aData-Bound
DataSet Controls
Chapter 8 - Constraints and Data Relations
Chapter 9 - ADO.NET Exception Handling
Copying,
Chapter Cloning,
10 - Working with and Clearing
the ODBC DataSets
.NET Data Provider
Chapter 11 - Stored Procedures and Views
TheClear method removes all the rows from a DataSet; however, it does not destroy the structure of a
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
DataSet. The Copy method copies the contents with schema of a DataSet to another DataSet. The
Chapter 13 - Developing a Custom Data Provider
Clone method only copies the structure of a DataSet to another. Listing 3-30 uses all three members.
Chapter 14 - Developing Database Web Applications using ASP.NET
Chapter
Listing15 - Using
3-30: ADO.NET
Using in Xml Web
Copy,Clone, andServices
Clear Methods of DataSet
Chapter 16 - ASP.NET Server Controls and Data Binding
Chapter 17 - Building Real-World Web Applications
Dim dtSet1 As DataSet = New DataSet("CustDtSet")
Chapter 18 - Object-Relational Mapping in .NET
dtSet1.Tables.Add(custTable)
Chapter 19 - Mapped
Dim dtSet2 Objects: Performance
As DataSet Considerations and Data Binding
= New DataSet()
Chapter
dtSet2 20 =- COM Interoperability and ADO.NET
dtSet1.Clone()
Chapter
dtSet2 21 =- Messaging
dtSet1.Copy()
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
dtSet1.Clear()
Appendix A - Relational Databases: Some Basic Concepts
Appendix B - Commonly Used SQL Statements
Appendix C - ADO.NET Frequently Asked Questions
Getting
Index Changed Rows of a DataSet
List of Figures
So far, we've talked about filling data from a DataAdapter to a DataSet and saving data back to a data
List of Tables
source using the Update method of DataSet. The Update method takes a DataSet and saves its
List of Listings
results in a data source. A DataAdapter belongs to a data provider, so we discuss it in Chapter 4.
List of Sidebars
TheGetChanges method helps you find the changed data of a DataSet so you can send only changed
data back to the data source instead of sending an entire DataSet. It helps to reduce the network traffic
and make the save process faster.
TheGetChanges method returns a DataSet, which contains all the changes made to a DataSet since
it was last loaded or the AcceptChanges method was called.
TheGetChanges method has two overloaded forms. The first form takes no parameters and returns all
the results. The second form lets you filter the results based on the row states, and it takes a parameter of
typeDataRowState.
TheHasChanges method determines if a DataSet has any changes since it was last saved or loaded.
The following snippet shows how to use the HasChanges and GetChanges methods (you'll see these
methods in moreApplied
detail in ADO.NET:
Chapter 4).Building Data-Driven Solutions
by Mahesh Chand and David Talbot ISBN:1590590732
Apress 2003 (928 pages)
If Not dtSet1.HasChanges(DataRowState.Modified) Then Exit Sub
This text provides extensive coverage of ADO.NET technology
Dim dtSet2 Asincluding
DataSetADO.NET internals, namespaces, classes, and
dtSet2 = dtSet1.GetChanges(DataRowState.Modified)
interfaces, and takes a comprehensive look at XML
namespaces and classes, and how to integrate both with
SqlDbDataAdapter1.Update(dtSet2)
ADO.NET.
As you may recall from earlier discussions, there are two kinds of a DataSet: typed or untyped. A typed
Table of Contents
DataSet first comes from the DataSet class and then uses an XML schema (.xsd file) to generate a
Applied ADO.NETBuilding
new class. You saw how Data-Driven Solutions
to create a typed DataSet using VS .NET in Chapter 2. An untyped DataSet
Introduction
has no built-in schema. You create an instance of a DataSet class and call its methods and properties to
Chapter 1 the
work with - ADO.NET Basics All elements of an untyped DataSet are collections. In this chapter, you'll
data sources.
work with
Chapter 2 untyped
- Data Components
DataSets.in Visual Studio .NET
Chapter 3 - ADO.NET in Disconnected Environments
Both kinds-of
Chapter 4
DataSet have their own advantages and disadvantages. Typed DataSets take less time to
ADO.NET in Connected Environments
write applications but offer no flexibility. They're useful when you already know the schema of a database.
Chapter 5 - Handling ADO.NET Events
The biggest advantage of typed DataSets is the VS .NET IDE support. As you saw in Chapter 2, you can
Chapter 6 - Integrating XML with ADO.NET
drag a database table, its columns, or stored procedures to a form in your application, and the IDE
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
generates typed DataSet for you. After that, you can bind these DataSets to the controls. However,
Chapter 8 - Constraints and Data Relations
there are many occasions when you don't know the schema of a database. In those cases, the untyped
Chapter 9 - are
DataSets ADO.NET
useful.Exception Handling
The untyped DataSets also provide the flexibility of connecting with multiple data
Chapter 10 - Working with the ODBC
sources. And you can use them without .NET Data Provider
the VS .NET IDE.
Chapter 11 - Stored Procedures and Views
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
The DataView
Chapter 13 - Developing a Custom Data Provider
Chapter
Another14powerful
- Developing Database
feature Web Applications
of ADO.NET using
is the ability ASP.NET
to create several different views of the same data. You
Chapter 15 - Using ADO.NET in Xml Web Services
can sort these views differently and filter them on different criteria. They can contain different row state
Chapter 16 - ASP.NET Server Controls and Data Binding
information.
Chapter 17 - Building Real-World Web Applications
ADataView
Chapter represents a customized
18 - Object-Relational Mapping inview
.NETof DataTable that you can bind to Windows Forms and Web
Forms 19
Chapter controls. Using
- Mapped DataView
Objects: sort and
Performance filter features,
Considerations andyou canBinding
Data also have multiple views of a single
DataTable. Using RowFilter and Sort properties, you can apply a filter on a DataView and sort its
Chapter 20 - COM Interoperability and ADO.NET
contents before binding it to a data-bound control. The AddNew method adds a new row to a DataView,
Chapter 21 - Messaging
and the Delete method deletes a row from a DataView. You can use the Find and FindRows
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
methods to search for rows based on the defined criteria.
Appendix A - Relational Databases: Some Basic Concepts
Appendix B -describes
Table 3-9 Commonly Usedof
some SQL
theStatements
DataView properties, and Table 3-10 describes some of its methods.
Appendix C - ADO.NET Frequently Asked Questions
Index
Table 3-9: The DataView Class Properties
List of Figures
List of Tables
List of Listings
List of Sidebars
PROPERTY DESCRIPTION
Applied ADO.NET: Building Data-Driven Solutions
by Mahesh Chand and David Talbot ISBN:1590590732
AllowDelete Indicates whether deletes are allowed.
Apress 2003 (928 pages)
AllowEdit Indicates
This text provides whethercoverage
extensive edits areofallowed.
ADO.NET technology
including ADO.NET internals, namespaces, classes, and
AddNews interfaces, Indicates
and takeswhether new rowslook
a comprehensive canatbeXML
added.
namespaces and classes, and how to integrate both with
ADO.NET. Indicates whether to use default sort. True means use the default sort
ApplyDefaultSort
andFalse means no.
Count
Table of Contents Represents the number of records in a DataView after RowFilter
andRowStateFilter
Applied ADO.NETBuilding Data-Driven Solutions have been applied.
Introduction
DataViewManager DataViewManager associated with this view.
Chapter 1 - ADO.NET Basics
Item
Chapter 2 Represents
- Data Components an item
in Visual Studio of a row.
.NET
Chapter 3 - ADO.NET in Disconnected
RowFilter Environments
Represents the expression used to filter rows to view in the DataView.
Chapter 4 - ADO.NET in Connected Environments
RowStateFilter
Chapter 5
You can use a row state filter using this property.
- Handling ADO.NET Events
Chapter
Sort6 - Integrating XML Represents
with ADO.NET
the sort column and sort order.
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
Table DataTable attached with this view.
Chapter 8 - Constraints and Data Relations
Chapter 9 - ADO.NET Exception Handling
Chapter 10 - Working with the ODBC .NET Data Provider
Table 3-10: The DataView Class Methods
Chapter 11 - Stored Procedures and Views
Chapter
METHOD12 - Oracle,DESCRIPTION
SQLXML, and Other .NET Data Providers
Chapter 13 - Developing a Custom Data Provider
AddNew Adds a new row to the DataView
Chapter 14 - Developing Database Web Applications using ASP.NET
Chapter 15 - Using Begins
BeginInit ADO.NETtheinintialization
Xml Web Services
if a data view was previously used
Chapter 16 - ASP.NET Server Controls and Data Binding
EndInit Ends the initialization started by BeginInit
Chapter 17 - Building Real-World Web Applications
Delete
Chapter Deletes a row
18 - Object-Relational Mapping in .NET
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
Find Finds a row in the DataView based on the specified criteria
Chapter 20 - COM Interoperability and ADO.NET
FindRows
Chapter Returns an array of rows based on the specified criteria
21 - Messaging
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Appendix A - Relational Databases: Some Basic Concepts
Creating
Appendix a DataView
B - Commonly Used SQL Statements
Appendix C - ADO.NET Frequently Asked Questions
TheDataView constructor allows you to create a DataView object from a DataTable, which you can
Index
use with or without a DataSet. In Listing 3-33, the custTable and ordersTable are two DataTable
List of Figures
objects. As you can see, the code creates a DataView directly from a DataTable and creates a second
List of Tables through a DataSet.
DataView
List of Listings
Listing
List 3-33: CreatingDataView Objects from a DataTable
of Sidebars
Binding a DataView with a data-bound control is pretty easy. You set the DataSource and
DisplayMember properties of a data-bound control. For example, the following code binds two
Applied
DataView objects with a ADO.NET:
DataGridBuilding Data-Driven
and a ListBox Solutions
control.
by Mahesh Chand and David Talbot ISBN:1590590732
Apress 2003 (928 pages)
DataGrid1.DataSource = dtView1
This text provides extensive coverage of ADO.NET technology
ListBox1.DataSource = dtView2
including ADO.NET internals, namespaces, classes, and
ListBox1.DisplayMember = "Name"
interfaces, and takes a comprehensive look at XML
namespaces and classes, and how to integrate both with
ADO.NET.
Chapter 7 discusses data-bound controls in more detail.
Table of Contents
Adding, Editing, and Deleting Data Using DataView
Applied ADO.NETBuilding Data-Driven Solutions
Introduction
TheAddNew method of a DataView, which returns a DataRowView, adds a new row to the DataView.
Chapter 1 - ADO.NET Basics
TheAddNew method is followed by a call of EndEdit. The BeginEdit and EndEdit pair edits the
Chapter
values 2of a- row.
Data The
Components in VisualAllowNew,
AllowDelete, Studio .NET and AllowEdit properties allow deleting, adding, and
Chapter 3 in- a
updating ADO.NET in Disconnected
DataView if they're setEnvironments
to True.
Chapter 4 - ADO.NET in Connected Environments
TheDelete
Chapter method ADO.NET
5 - Handling of a DataView
Events deletes a row specified by the index of the row. The Count property
returns6the- total
Chapter number
Integrating of rows
XML in a DataView.
with ADO.NET
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
Listing 3-34 uses the previously discussed methods and properties to add, delete, and edit rows of a
Chapter 8 - Constraints and Data Relations
DataView.
Chapter 9 - ADO.NET Exception Handling
Chapter
Listing10 - Working
3-34: with
Adding, the ODBCand
Updating, .NETDeleting
Data Provider
Rows of a DataView
Chapter 11 - Stored Procedures and Views
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
' Creating a DataView from DataTable
Chapter 13 - Developing a Custom Data Provider
Dim dtView1 As DataView = New DataView(custTable)
Chapter 14 - Developing
' Creating Database
a DataView Web Applications
through DataSet using ASP.NET
Chapter 15 - Using ADO.NET in Xml
Dim dtSet1 As DataSet = New DataSet() Web Services
Chapter 16 - ASP.NET Server Controls and Data Binding
dtSet1.Tables.Add(ordersTable)
Chapter 17 - Building
Dim dtView2 As Real-World
DataViewWeb = Applications
New DataView(dtSet1.Tables(0))
Chapter
' Set18AllowDelete,
- Object-Relational Mapping inand
AllowNew .NET AllowEdit to true
Chapter 19 - Mapped Objects:=Performance
dtView1.AllowDelete True Considerations and Data Binding
dtView1.AllowNew
Chapter = True and ADO.NET
20 - COM Interoperability
dtView1.AllowEdit
Chapter 21 - Messaging = True
' Edit
Chapter 22 the
- SQLdata
Serverofandfirst row
ADO.NET: Notes on Performance
dtView1(0).BeginEdit()
Appendix A - Relational Databases: Some Basic Concepts
dtView1(0)("Name")
Appendix B - Commonly Used = SQL
"Edited Name"
Statements
dtView1(0)("Address") = "Edited
Appendix C - ADO.NET Frequently Asked Questions
Address"
dtView1(0).EndEdit()
Index
' Delete the first row from DataView
List of Figures
' the Delete method takes an index of row starting
List of Tables
' at 0
List of Listings
If dtView1.AllowDelete Then
List of Sidebars
dtView1.Delete(0)
End If
' Add a new row
Dim drv As DataRowView = dtView1.AddNew
' Change values in the DataRow.
drv("id") = 1010
drv("Name") = "New Name"
drv("Address") = "New Address"
drv.EndEdit()
' Count number of rows
MessageBox.Show(dtView1.Count.ToString())
Applied ADO.NET: Building Data-Driven Solutions
by Mahesh
Searching and SortingChand
Dataand David Talbot
Using DataView ISBN:1590590732
Apress 2003 (928 pages)
Searching and sorting areprovides
This text two major operations
extensive that aofDataView
coverage does to filter data. The Sort property of
ADO.NET technology
DataView sorts including
rows of aADO.NET
DataView.internals, namespaces,
The Sort propertyclasses,
takes aand
string value, which contains the sort
interfaces,
criteria with one or more than and takes
one a comprehensive
DataTable columns look at XML by a comma (,) and followed by ASC
separated
namespaces and classes, and how to integrate both with
or DESC, where ASC is for sorting rows in ascending order and DESC for sorting rows in descending
ADO.NET.
order. The following code shows how to use one or more than one column with the ASC and DESC
options:
Table of Contents
Applied ADO.NETBuilding
dtView1.Sort = "Name,Data-Driven
AddressSolutions
ASC"
Introduction
dtView1.Sort = "Name DESC"
Chapter 1 - ADO.NET Basics
Chapter 2 - Data Components in Visual Studio .NET
TheRowFilter
Chapter property
3 - ADO.NET of a DataView
in Disconnected filters the rows depending on the given criteria. The
Environments
RowFilter
Chapter takes a criteria,
4 - ADO.NET whichEnvironments
in Connected contains columns and their values. The following code returns all rows
that contain
Chapter Name column
5 - Handling values
ADO.NET of Miranda:
Events
Chapter 6 - Integrating XML with ADO.NET
dtView1.RowFilter
Chapter = "Name
7 - Data Binding and = Forms
Windows 'Miranda'"
Data-Bound Controls
Chapter 8 - Constraints and Data Relations
Chapter 9 - ADO.NET Exception Handling
Besides the Sort and RowFilter properties, the DataView class provides Find and FindRow
Chapter 10 - Working with the ODBC .NET Data Provider
methods to find rows. The Find method requires a Sort field and takes a parameter of type Object or
Chapter 11of- Object.
an array Stored Procedures and Views
The FindRow method returns an array of DataRowView, whose column matches
Chapter 12 - Oracle, SQLXML,
the specified sort key value. and Other .NET Data Providers
Chapter 13 - Developing a Custom Data Provider
Listing 14
Chapter 3-35 uses the Find
- Developing method
Database WebtoApplications
find the value "Data
using Quest" in the column Name, which returns an
ASP.NET
index of15the
Chapter row. ADO.NET in Xml Web Services
- Using
Chapter 16 - ASP.NET Server Controls and Data Binding
Listing 3-35: Finding Rows in a DataView Using the Find Method
Chapter 17 - Building Real-World Web Applications
Chapter 18 - Object-Relational Mapping in .NET
' Creating
Chapter a DataView
19 - Mapped from DataTable
Objects: Performance Considerations and Data Binding
Dim dtView1
Chapter 20 - COM As DataView and
Interoperability = New DataView(custTable)
ADO.NET
' Creating
Chapter a DataView through DataSet
21 - Messaging
Dim dtSet1 As DataSet = New DataSet()
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
dtSet1.Tables.Add(ordersTable)
Appendix A - Relational Databases: Some Basic Concepts
Dim dtView2 As DataView = New DataView(dtSet1.Tables(0))
Appendix B - Commonly Used SQL Statements
dtView2.Sort = "Name"
Appendix C - ADO.NET Frequently Asked Questions
Dim val As Object = "Data Quest"
Index
Dim pos As Integer = dtView2.Find(Val)
List of Figures
MessageBox.Show(pos.ToString())
List of Tables
List of Listings
List of Sidebars
The DataViewManager
ADataViewManager contains a collection of views of a DataSet-one view for each DataTable in the
DataSet. The DataViewManager has a DataViewSettings property that enables the user to
construct a different view for each DataTable in the DataSet. If you want to create two views on the
same DataTable, you need to create another instance of the DataViewManager and construct the
DataViewSettings for that particular view. Then you construct a DataView using the
DataViewManager. For example, in the Orders DataSet, you may want to filter out the orders with an
EmployeeID of 4 and sort the orders by the date they were shipped. You can retrieve records for
EmployeedId = 4 sorted on the date they were shipped using the sort and filter properties of the DataSet
and attaching the filtered and sorted data to a DataView or a DataViewManager.
To construct a DataViewManager, you can either
Applied ADO.NET: Building use the Solutions
Data-Driven Default constructor or pass in a DataSet
object. For example:
by Mahesh Chand and David Talbot ISBN:1590590732
Apress 2003 (928 pages)
view = new DataViewManager ()
This text provides extensive coverage of ADO.NET technology
including ADO.NET internals, namespaces, classes, and
interfaces, and takes a comprehensive look at XML
or, for example: namespaces and classes, and how to integrate both with
ADO.NET.
Table of Contents
Applied ADO.NETBuilding Data-Driven Solutions
Introduction
Chapter 1 - ADO.NET Basics
Chapter 2 - Data Components in Visual Studio .NET
Chapter 3 - ADO.NET in Disconnected Environments
Chapter 4 - ADO.NET in Connected Environments
Chapter 5 - Handling ADO.NET Events
Chapter 6 - Integrating XML with ADO.NET
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
Chapter 8 - Constraints and Data Relations
Chapter 9 - ADO.NET Exception Handling
Chapter 10 - Working with the ODBC .NET Data Provider
Chapter 11 - Stored Procedures and Views
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Figure
Chapter 13 - 4-1: A generic
Developing data provider
a Custom model
Data Provider
Chapter 14 - Developing Database Web Applications using ASP.NET
Chapter 15 - Using ADO.NET
TheConnection in Xml
component of aWeb
dataServices
provider is the first component, and it communicates with a data
Chapter
source.16 - ASP.NET Serversits
A DataAdapter Controls andaData
between Binding
DataSet and the data source and passes data back and forth.
TheDataAdapter's
Chapter Fill method
17 - Building Real-World Web fills data from a data source to a DataSet, and the Update method
Applications
of the DataAdapter
Chapter saves changes
18 - Object-Relational from
Mapping in a DataSet to a data source. In Chapter 3, you saw how to use
.NET
the data
Chapter 19once you have
- Mapped it in aPerformance
Objects: DataSet through the DataTable,
Considerations DataRow, and DataColumn objects.
and Data Binding
Chapter 20 - COM Interoperability and ADO.NET
TheCommand and CommandBuilder objects are two more important components of a data provider. A
Chapter 21 - Messaging
Command component uses SQL queries to transfer data back and forth from a data source to an
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
application and vice versa. A Command or CommandBuilder object can use a DataAdapter or a
Appendix A - Relational Databases: Some Basic Concepts
DataReader. The DataReader is a fast, read-only gateway of data.
Appendix B - Commonly Used SQL Statements
Appendix C - ADO.NET
You'll begin Frequently Asked
your understanding of the Questions
ADO.NET data providers by examining the Sql data provider
defined in the System.Data.SqlClient namespace. This name-space contains the classes necessary
Index
to manipulate
List of Figures the data providers.
List of Tables
List of Listings
List of Sidebars
Importing aApplied
Namespace
ADO.NET: Building Data-Driven Solutions
by Mahesh Chand and David Talbot ISBN:1590590732
Before anything else,
Apressyou need
2003 to pages)
(928 decide what data provider you'll use in your applications. Once you've
decided, you need to include the namespace in your applications
This text provides extensive coverage so the namespace objects are available
of ADO.NET technology
to you. You include a namespace by adding an Imports directive,
including ADO.NET internals, namespaces, classes, and followed by the namespace, to your
interfaces,
project. The following and takes
lines import theaSystem.Data,
comprehensive System.Data.Common,
look at XML
namespaces and
System.Data.SqlClient, andclasses, and how to integrate
System.Data.OleDb both with of ADO.NET:
namespaces
ADO.NET.
Imports System.Data
Table of Contents
Imports System.Data.Common
Applied
ImportsADO.NETBuilding Data-Driven Solutions
System.Data.SqlClient
Introduction
Imports System.Data.OleDb
Chapter 1 - ADO.NET Basics
Chapter 2 - Data Components in Visual Studio .NET
In later chapters,
Chapter 3
we discuss other data providers-such as Odbc and Oracle- and their related
- ADO.NET in Disconnected Environments
namespaces.
Chapter 4 - ADO.NET in Connected Environments
Chapter
You can5 also
- Handling
accessADO.NET Events objects by specifying the full namespace when you declare the
a namespace's
Chapter 6 - Integrating XML with ADO.NET
objects. For example, the following code accesses the SqlConnection class of the
Chapter 7 - Data Binding and Windows
System.Data.SqlClient namespaceForms
(inData-Bound Controls
this case, you don't need to use the Imports statement):
Chapter 8 - Constraints and Data Relations
Chapter 9 - ADO.NET
Dim conn Exception Handling
As SqlConnection = New SqlClient.SqlConnection()
Chapter 10 - Working with the ODBC .NET Data Provider
Chapter 11 - Stored Procedures and Views
The previous
Chapter code SQLXML,
12 - Oracle, is equivalent
and to the .NET
Other following
Data code:
Providers
Chapter 13 - Developing a Custom Data Provider
Chapter
Imports14 -System.Data.SqlClient
Developing Database Web Applications using ASP.NET
Dim conn
Chapter As SqlConnection
15 - Using = Services
ADO.NET in Xml Web New SqlConnection()
Chapter 16 - ASP.NET Server Controls and Data Binding
Chapter 17 - Building Real-World Web Applications
Chapter 18 - Object-Relational Mapping in .NET
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
Chapter 20 - COM Interoperability and ADO.NET
Chapter 21 - Messaging
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Appendix A - Relational Databases: Some Basic Concepts
Appendix B - Commonly Used SQL Statements
Appendix C - ADO.NET Frequently Asked Questions
Index
List of Figures
List of Tables
List of Listings
List of Sidebars
Exploring the System.SqlClient
Applied Namespace
ADO.NET: Building Data-Driven Solutions
by Mahesh Chand and David Talbot ISBN:1590590732
In this chapter, we use the
Apress SQL
2003 Server
(928 pages) database as the data source to test the code samples. Hence, we
use the System.Data.SqlClient (or justcoverage
This text provides extensive SqlClient) name-space
of ADO.NET most of the time. Before going any
technology
further, let's explore the SqlClient namespace and see what it
including ADO.NET internals, namespaces, classes, and has to offer.
interfaces, and takes a comprehensive look at XML
Table 4-1 describes the SqlClient
namespaces namespace
and classes, and how classes.
to integrate both with
ADO.NET.
Table 4-1: Sql Data Provider Classes
Table of Contents
CLASS DESCRIPTION
Applied ADO.NETBuilding Data-Driven Solutions
SqlClientPermission
Introduction Makes sure the user who is accessing the data has
Chapter 1 - ADO.NET Basics permission to access a data source.
Chapter 2 - Data Components in Visual StudioSets
SqlClientPermissionAttribute .NETpermission attributes.
Chapter 3 - ADO.NET in Disconnected Environments
SqlCommand
Chapter 4 Represents a SQL statement or stored procedure.
- ADO.NET in Connected Environments
Data can be returned in a DataReader by calling its
Chapter 5 - Handling ADO.NET Events
ExecuteReader method.
Chapter 6 - Integrating XML with ADO.NET
Chapter 7 - Data Binding and Windows Forms Provides
SqlCommandBuilder Data-Bound Controls
a mechanism to generate automatic
Chapter 8 - Constraints and Data Relations commands for a table.
Chapter 9 - ADO.NET Exception Handling
SqlConnection Represents a Connection object. This is first class
Chapter 10 - Working with the ODBC .NET Data Provider
you need to use to connect to a data source.
Chapter 11 - Stored Procedures and Views
SqlDataAdapter
Chapter Set ofProviders
12 - Oracle, SQLXML, and Other .NET Data commands that provides a link between
SqlConnection and DataSet.
Chapter 13 - Developing a Custom Data Provider
Chapter 14 - Developing Database Web Applications
SqlDataReader Reads using
dataASP.NET
in a forward-only direction through
Chapter 15 - Using ADO.NET in Xml Web Services
SqlCommand.
Chapter 16 - ASP.NET Server Controls and Data Binding
SqlError Collects error and warnings returned by the data
Chapter 17 - Building Real-World Web Applications
Chapter 18 - Object-Relational Mapping in .NET
source.
Chapter 19 - Mapped Objects: Performance Considerations
SqlErrorCollection andgenerated
Collects errors Data Binding
by Sql data providers.
Chapter 20 - COM Interoperability and ADO.NET
SqlException Exception handling class designed for Sql data
Chapter 21 - Messaging
sources.
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
A - Relational Databases: Some BasicProvides
SqlInfoMessageEventArgs
Appendix Conceptsdata for the InfoMessage event.
Appendix B - Commonly Used SQL Statements
SqlParameter This class represents a parameter used in
Appendix C - ADO.NET Frequently Asked Questions
SqlCommand.
Index
ListSqlParameterCollection
of Figures A collection of parameters.
ListSqlRowUpdateEventArgs
of Tables Provides data for the RowUpdated event.
List of Listings
ListSqlRowUpdatingEventArgs
of Sidebars Provides data from the RowUpdating event.
SqlTransaction A transaction that can be processed at a data source.
Like the Sql data provider, the OleDb, ODBC, and other data providers implement the same class
hierarchy model. Programmatically, the only difference is the prefix for each data provider namespace and
the connection string. Internally, each data provider uses a different native data access technology to
access the data source. For example, the OleDb provider classes begin with OleDb, the Sql Server
provider namespace classes start with Sql, and the ODBC provider classes begin with Odbc . The
System.Data classes have no provider-specific prefix, of course, because the classes defined in the
System.Data and System.Data.Common namespaces are used in memory and are shared by all the
providers.
The way ADO.NET works is that once you've connected to a database and dumped the data into the in-
Applied ADO.NET: Building Data-Driven Solutions
memory object (known as the DataSet), you can disconnect from the database and manipulate the data
until you're readybyto Mahesh Chand and David Talbot ISBN:1590590732
write it back to the database. The data provider classes serve as a bridge for moving
Apress 2003 (928 pages)
data back and forth between memory and the database. In the next section we discuss how to initially
This text
connect to a database provides
using theseextensive
providerscoverage
and howoftoADO.NET technology
implement the data provider classes to allow data
including ADO.NET internals, namespaces, classes, and
to use this efficient bridge.
interfaces, and takes a comprehensive look at XML
namespaces and classes, and how to integrate both with
In the sections that follow we describe how to connect to various databases with the data providers. Then
ADO.NET.
we show you how to use the data provider classes to execute queries and stored procedures. Also, you'll
learn how these powerful classes work together and how the data providers differ in certain capabilities.
Table ofalso
You'll Contents
learn how to do transaction locking, batch transactions, and transaction rollbacks.
Applied ADO.NETBuilding Data-Driven Solutions
Introduction
Chapter 1 - ADO.NET Basics
Chapter 2 - Data Components in Visual Studio .NET
Chapter 3 - ADO.NET in Disconnected Environments
Chapter 4 - ADO.NET in Connected Environments
Chapter 5 - Handling ADO.NET Events
Chapter 6 - Integrating XML with ADO.NET
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
Chapter 8 - Constraints and Data Relations
Chapter 9 - ADO.NET Exception Handling
Chapter 10 - Working with the ODBC .NET Data Provider
Chapter 11 - Stored Procedures and Views
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Chapter 13 - Developing a Custom Data Provider
Chapter 14 - Developing Database Web Applications using ASP.NET
Chapter 15 - Using ADO.NET in Xml Web Services
Chapter 16 - ASP.NET Server Controls and Data Binding
Chapter 17 - Building Real-World Web Applications
Chapter 18 - Object-Relational Mapping in .NET
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
Chapter 20 - COM Interoperability and ADO.NET
Chapter 21 - Messaging
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Appendix A - Relational Databases: Some Basic Concepts
Appendix B - Commonly Used SQL Statements
Appendix C - ADO.NET Frequently Asked Questions
Index
List of Figures
List of Tables
List of Listings
List of Sidebars
The Connection: Connecting
Applied ADO.NET: Building to a Data Solutions
Data-Driven Source
by Mahesh Chand and David Talbot ISBN:1590590732
As you saw in Figure 4-1,
Apress the first
2003 object that interacts with a data source is the Connection object. You
(928 pages)
can bypass a Connection object by using acoverage
This text provides extensive DataAdapter directly,
of ADO.NET but in that case a DataAdapter
technology
uses the Connection internally. The Connection class has a
including ADO.NET internals, namespaces, classes, and different name depending upon the data
interfaces, and
provider. The Connection takes
class for aOleDb,
comprehensive
Sql, and look
Odbcatare
XMLOleDbConnection, SqlConnection,
respectively. namespaces and classes, and how to integrate both with
ADO.NET.
Creating a Connection
Table of Contents
TheSqlConnection
Applied class
ADO.NETBuilding provides Solutions
Data-Driven two forms of constructors. The first doesn't take any parameters,
and the second takes a parameter of a connection string that points to the database to which you want to
Introduction
attach. 1The
Chapter connection
- ADO.NET string contains the server name, database name, user ID, password, and more.
Basics
Chapter 2 - Data Components in Visual Studio .NET
Listing 4-1 creates SqlConnection objects using both constructors.
Chapter 3 - ADO.NET in Disconnected Environments
Chapter
Listing44-1:
- ADO.NET
CreatinginSqlConnection
Connected Environments
Objects
Chapter 5 - Handling ADO.NET Events
Chapter 6 - Integrating XML with ADO.NET
Dim connString As String = "user id=sa;password=password;" & _
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
"initial catalog=northwind;data source=Northwind;Connect Timeout=30"
Chapter 8 - Constraints and Data Relations
Dim conn1 As SqlConnection = New SqlConnection(connString)
Chapter 9 - ADO.NET Exception Handling
Dim conn2 As SqlConnection = New SqlConnection()
Chapter 10 - Working with the ODBC
conn2.ConnectionString .NET Data Provider
= connString
Chapter 11 - Stored Procedures and Views
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Chapter 13 - Developing a Custom Data Provider
After creating
Chapter a connection,
14 - Developing you Web
Database call its Open method,
Applications using and when you're done with the connection, you call
ASP.NET
theClose
Chapter 15 -method.
Using ADO.NET in Xml Web Services
Chapter 16 - ASP.NET Server Controls and Data Binding
Understanding the Connection Properties and Methods
Chapter 17 - Building Real-World Web Applications
Chapter 18 - Object-Relational Mapping in .NET
TheConnection
Chapter 19 - Mappedclass (SqlConnection
Objects: in this case) and
Performance Considerations hasData
a connection
Binding string that contains a server and
a database
Chapter 20 - name. The connection
COM Interoperability andstring will vary depending upon the provider used. The connection
ADO.NET
string will
Chapter 21 typically contain a group of property-value pairs to describe how to connect to a database. For
- Messaging
theOleDbConnection
Chapter class,
22 - SQL Server and you have
ADO.NET: properties
Notes such as Provider and DataSource. For the
on Performance
SqlConnection class, you have the server name, initial catalog, user ID, and password. Table 4-2
Appendix A - Relational Databases: Some Basic Concepts
describes the Connection class properties. (Based on the data provider, some of these properties may
Appendix B - Commonly Used SQL Statements
not be applicable.)
Appendix C - ADO.NET Frequently Asked Questions
Index
Table 4-2: Connection Object Properties
List of Figures
List of Tables
List of Listings
List of Sidebars
PROPERTY DESCRIPTION
Applied ADO.NET: Building Data-Driven Solutions
by Mahesh Chand and David Talbot ISBN:1590590732
ConnectionString The connection string.
Apress 2003 (928 pages)
ConnectionTimeOut Waiting
This text provides time while
extensive establishing
coverage a connection.
of ADO.NET technology
including ADO.NET internals, namespaces, classes, and
DataBase Name
interfaces, and of athe
takes current database.
comprehensive look at XML
namespaces and classes, and how to integrate both with
DataSource ADO.NET. Filename of the data source.
Provider Name of the OLE DB provider. This property is not available for the
Table of Contents Sql and ODBC data providers.
Applied
StateADO.NETBuilding Data-Driven Solutions
Current state of the connection of type ConnectionState.
Introduction
1 - ADO.NET Basics Size of network packets. This is only available to Sql data providers.
PacketSize
Chapter
Chapter 2 - Data ComponentsSQL
ServerVersion in Visual Studio
Server .NET This is only available to Sql data providers.
version.
Chapter 3 - ADO.NET in Disconnected Environments
WorkStationId
Chapter 4 Database
- ADO.NET in Connected client ID. This is only available to Sql data providers.
Environments
Chapter 5 - Handling ADO.NET Events
A typical connection
Chapter 6
for SQL Server may also contain the security type, the workstation ID, and even the
- Integrating XML with ADO.NET
network packet size. The following code is a connection string for a SQL Server called MCB:
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
Chapter 8 - Constraints and Data Relations
connectionString
Chapter =
9 - ADO.NET Exception Handling
"data source=MCB;initial catalog=Northwind;"
Chapter 10 - Working with the ODBC .NET Data Provider
+ "integrated security=SSPI;persist security info=False;"
Chapter 11 - Stored Procedures and Views
+ "workstation id=MCB;packet size=4096";
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Chapter 13 - Developing a Custom Data Provider
Chapter 14 - Developing
TheConnection Database
can have Web states
different Applications using
such as ASP.NET
open, closed, connecting, and so on. The
Chapter 15 - Using ADO.NET
ConnectionType in Xml defines
enumeration Web Services
the members of the ConnectionState.Table 4-3 describes its
Chapter 16 - ASP.NET Server Controls and Data Binding
members.
Chapter 17 - Building Real-World Web Applications
Table 4-3:
Chapter 18 - The ConnectionType
Object-Relational Enumeration
Mapping in .NET Members
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
MEMBER DESCRIPTION
Chapter 20 - COM Interoperability and ADO.NET
Chapter
Broken21 - Messaging
Connection is broken after it was opened. This may be caused by network
failure.
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Appendix A - Relational Databases: Some Basic Concepts
Closed Connection is closed.
Appendix B - Commonly Used SQL Statements
Connecting
Appendix Opening
C - ADO.NET a new
Frequently connection.
Asked Questions
Index
Executing The connection is executing a command.
List of Figures
ListFetching
of Tables Retrieving data from a data source.
ListOpen
of Listings
Connection is open and ready to use.
List of Sidebars
Table 4-4 describes the Connection class methods. You'll see some of these methods throughout this
chapter. The purpose of this table is to give you an idea of available methods.
Now you'll connect to a SQL Server database using the Sql data provider. For this example, you'll use the
SQL Server 2000 Northwind database. Listing 4-4 shows the connection with the SQL Server database. As
you can see, the code first constructs a connection string with the SQL Server name MCB and the
database name Northwind. It uses Windows security in this connection, but depending on your SQL Server
setup you could alternatively use a SQL Server login and password. After constructing a connection string,
it calls the Open method to open the connection. After that it reads the connection properties and displays
them in a message box. In the end, it calls the Close method to close the connection and the Dispose
method to get rid of the connection resources.
Listing 4-4: Connecting to a SQL Server and Reading the SqlConnection Properties
Applied ADO.NET: Building Data-Driven Solutions
by Mahesh Chand and David Talbot ISBN:1590590732
' Create a Connection Object
Apress 2003 (928 pages)
Dim ConnectionString As String = "Integrated Security=SSPI;" & _
This text provides extensive coverage of ADO.NET technology
"Initial
including Catalog=Northwind;Data
ADO.NET Source=MCB;"
internals, namespaces, classes, and
Dim conn Asinterfaces,
SqlConnection
and takes a =comprehensive
New SqlConnection(ConnectionString)
look at XML
' Open the namespaces
connection and classes, and how to integrate both with
ADO.NET.
If conn.State <> ConnectionState.Open Then
conn.Open()
Table ofMessageBox.Show("Connection
Contents state: " + conn.State.ToString())
End If
Applied ADO.NETBuilding Data-Driven Solutions
' Show the connection properties
Introduction
MessageBox.Show("Connection String :" + conn.ConnectionString & _
Chapter 1 - ADO.NET Basics
", Workstation Id:" + conn.WorkstationId.ToString() & _
Chapter 2 - Data Components in Visual Studio .NET
", Packet Size :" + conn.PacketSize.ToString() & _
Chapter 3 - ADO.NET in Disconnected Environments
", Server Version " + conn.ServerVersion.ToString() & _
Chapter 4 - ADO.NET ",in DataSource
Connected Environments
:" + conn.DataSource.ToString() & _
Chapter 5 - Handling",ADO.NET
Server Events
Version:" + conn.ServerVersion.ToString() & _
Chapter 6 - Integrating
", XML with ADO.NET
Connection Time Out:" + conn.ConnectionTimeout.ToString())
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
Chapter 8 - Constraints
' Close and Data Relations
the connection
Chapter 9 - ADO.NET Exception
If conn.State Handling
= ConnectionState.Open Then
Chapterconn.Close()
10 - Working with the ODBC .NET Data Provider
ChapterMessageBox.Show("Connection
11 - Stored Procedures and Views state: " + conn.State.ToString())
End12If- Oracle, SQLXML, and Other .NET Data Providers
Chapter
' Dispose
Chapter the connection
13 - Developing a Custom Data Provider
If (Not
Chapter conn IsDatabase
14 - Developing Nothing) Then
Web Applications using ASP.NET
conn.Dispose()
Chapter 15 - Using ADO.NET in Xml Web Services
End If
Chapter 16 - ASP.NET Server Controls and Data Binding
Chapter 17 - Building Real-World Web Applications
Chapter 18 - Object-Relational Mapping in .NET
Chapter
You can 19even
- Mapped
pass aObjects:
user IDPerformance Considerations
and password and Data
in a connection Binding
string. For example, the following connection
Chapter 20 - COM Interoperability and
string uses a user ID and password: ADO.NET
Chapter 21 - Messaging
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Dim ConnectionString As String = "user id=sa;password=pass;" & _
Appendix A - Relational"Initial
Databases: Some Basic Concepts
Catalog=Northwind;Data Source=MCB;"
Appendix B - Commonly Used SQL Statements
Appendix C - ADO.NET Frequently Asked Questions
Index
List ofNote As you can see, we used MCB as the data source name. You can use localhost as your local
Figures
server.
List of Tables
List of Listings
Understanding Connection Pooling
List of Sidebars
Connection pooling is a mechanism to utilize and share connection resources already available in a
connection pool. In general, if an application needs a connection, it creates a new connection. There's a
whole process of establishing a new connection. When the application is done using a connection, it
closes the connection. Connection pooling plays a vital role in a three-tier development. For example, in a
three-tier development, say you're using a Web server. The opening and closing of a connection
consumes time and server resources in this scenario. Now say the application executes only a SELECT
statement, which returns only a few records from the database. It may be possible that establishing a
connection with the server may take more time than executing the query. This situation gets worse when
there are hundreds of users accessing the same server. Another scenario is that a user logs into a server
and then stays connected, never logging out. So, having a connection open until a user logs out is not a
feasible solution.
Applied ADO.NET: Building Data-Driven Solutions
by Mahesh
So how does connection Chandhelp
pooling and in
David Talbot
this scenario? In the .NET Framework, when an application
ISBN:1590590732
Apress
closes a connection, theconnection goes to a pool of available connections and stays active for a certain
2003 (928 pages)
interval of time even
Thisafter you closeextensive
text provides the connection.
coverageWhen a user technology
of ADO.NET connects, the provider compares the
connection stringincluding ADO.NET internals,
to the connection strings in namespaces, classes,
the pool. If the string and
matches, then a connection is returned
interfaces,
from the pool instead and takes
of creating and aopening
comprehensive look at XML
a new connection.
namespaces and classes, and how to integrate both with
ADO.NET.
The connection pooling mechanism works differently for different data providers. The Connection class
defines members that allow you to pool connection resources manually.
Table of Contents
OLE DB provides automatic connection pooling (also known as sessionpooling), which is handled by OLE
Applied ADO.NETBuilding Data-Driven Solutions
DB core components through its providers.
Introduction
Chapter
In ADO,1 you
- ADO.NET Basicsof the OLE DB Services parameter, which includes connection pooling as
set the value
well. This
Chapter 2 is an ADO
- Data connection
Components string Studio
in Visual passed to the Open method of an OLEDBConnection:
.NET
Chapter 3 - ADO.NET in Disconnected Environments
Chapter 4 - ADO.NET
Dim conn in Connected Environments
As OLEDBConnection = Nothing
Chapter 5 - Handling ADO.NET Events
Conn.Open("DSN=LocalServer;UID=sa;PWD=;OLE DB Services=-1")
Chapter 6 - Integrating XML with ADO.NET
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
Table 4-5
Chapter 8 -describes theand
Constraints values
Datafor the OLE DB Services parameter.
Relations
Chapter 9 - ADO.NET Exception Handling
Table 4-5:
Chapter 10 - The OLEwith
Working DB the
Services Settings
ODBC .NET Data Provider
Chapter 11 - Stored
SERVICES Procedures and Views
ENABLED VALUE
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
All services
Chapter (default) a Custom Data Provider
13 - Developing "OLE DB Services = 1;"
Chapter 14 - Developing
All services Database Web Applications using ASP.NET
except pooling "OLE DB Services = 2;"
Chapter 15 - Using ADO.NET in Xml Web Services
All services
Chapter except Server
16 - ASP.NET poolingControls
and auto enlistment
and Data Binding
"OLE DB Services = 4;"
Chapter 17 - Building
All services exceptReal-World Web Applications
client cursor "OLE DB Services = 5;"
Chapter 18 - Object-Relational Mapping in .NET
All services except client cursor and pooling "OLE DB Services = 6;"
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
Chapter 20 - COM Interoperability and ADO.NET
No services "OLE DB Services = 0;"
Chapter 21 - Messaging
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
For example,
Appendix the following
A - Relational string Some
Databases: disables theConcepts
Basic connection pooling:
Appendix B - Commonly Used SQL Statements
Dim connString
Appendix C - ADO.NET As String
Frequently = "Provider
Asked Questions = SQLOLEDB OLE DB Services = -2;" & _
"Data Source = MCB; Integrated Security = SSPI "
Index
List of Figures
List of Tables
ADO .NET manages connection pooling automatically when you call the Close or Dispose method of a
List of Listings
Connection object. Once a pool is created, you can add connections to this pool until the pool reaches
List of Sidebars
its maximum size. You can define the maximum size of a connection pool using the connection string. If a
pool reaches its maximum size, the next added connection will join a queue and wait until the pool
releases an existing connection.
You create a pool when you call the Open method of a connection based on the connection string. If
you're using the same database for two Connection objects, but the connection string is different
(including spaces and single characters), each connection will be added to a different pool. For example,
Listing 4-5 creates two connections: conn1 and conn2. The ConnectionString1 and
ConnectionString2 connection strings are different for both connections. Because these connections
have different connection strings, they'll be added to two different pools.
The following code creates a SqlCommand using the CreateCommand method of an already existing
SqlConnection object:
The third way of creating a Command object is to create a command by just passing a SQL query as the
argument and setting its Connection property later:
Listing 4-8 shows you how to connect to the Northwind SQL Server database, read all the records from the
Orders table, and output the first and second field's data to the console. The new things you'll notice in this
code are ExecuteReader and SqlDataReader. A SqlDataReader is a DataReader class, and
ExecuteReader fills data from a data source to the DataReader based on the SQL query. (We discuss
Applied
DataReader classes ADO.NET:
in the Building Data-Driven Solutions
next section.)
by Mahesh Chand and David Talbot ISBN:1590590732
Apress
Listing 4-8: Using 2003 (928 to
SqlCommand Read Data from a Database
pages)
This text provides extensive coverage of ADO.NET technology
including ADO.NET internals, namespaces, classes, and
' Connection interfaces,
and SQLand strings
takes a comprehensive look at XML
Dim ConnectionString
namespaces Asand String = how
classes, and "Integrated Security=SSPI;"
to integrate both with & _
ADO.NET.
"Initial Catalog=Northwind;Data Source=MCB;"
Dim SQL As String = "SELECT * FROM Orders"
' Create connection object
Table of Contents
Dim conn As SqlConnection = New SqlConnection(ConnectionString)
Applied ADO.NETBuilding Data-Driven Solutions
' Create command object
Introduction
Dim cmd As SqlCommand = New SqlCommand(SQL)
Chapter 1 - ADO.NET =
cmd.Connection Basics
conn
Chapter
' Open 2 connection
- Data Components in Visual Studio .NET
Chapter 3 - ADO.NET in Disconnected Environments
conn.Open()
Chapter
' Call 4 command's
- ADO.NET in ExecuteReader
Connected Environments
Chapter 5 - Handling
Dim reader ADO.NET Events = cmd.ExecuteReader()
As SqlDataReader
Chapter
While6 reader.Read()
- Integrating XML with ADO.NET
If Not
Chapter reader.IsDBNull(0)
7 - Data ThenData-Bound Controls
Binding and Windows Forms
Chapter 8 - Constraints and Data Relations reader.GetInt32(0).ToString())
Console.Write("OrderID:" +
Console.Write("
Chapter 9 - ADO.NET Exception,") Handling
Console.WriteLine("Customer:" + reader.GetString(1).ToString())
Chapter 10 - Working with the ODBC .NET Data Provider
End If
Chapter 11 - Stored Procedures and Views
End While
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
' close reader and connection
Chapter 13 - Developing a Custom Data Provider
reader.Close()
Chapter 14 - Developing Database Web Applications using ASP.NET
conn.Close()
Chapter 15 - Using ADO.NET in Xml Web Services
'Dispose
Chapter 16 - ASP.NET Server Controls and Data Binding
conn.Dispose()
Chapter 17 - Building Real-World Web Applications
Chapter 18 - Object-Relational Mapping in .NET
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
Chapter 20 - of
The output COM Interoperability
Listing 4-8 will list and ADO.NET
records from the Customers table to the console.
Chapter 21 - Messaging
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Creating and Using OleDbCommand
Appendix A - Relational Databases: Some Basic Concepts
Like the BSqlCommand
Appendix object,
- Commonly Used SQLyou create OleDb and ODBC Command objects by using the
Statements
OleDbCommand
Appendix and Frequently
C - ADO.NET OdbcCommandAskedclasses. You can pass the same arguments as discussed previously.
Questions
The only difference is the connection string. For example, Listing 4-9 uses OleDbCommand and
Index
OleDbConnection
List of Figures to connect to a SQL Server database. As you can see, the only changes are the
class
List prefixes and the connection string. Similarly, you can use the OdbcCommand object.
of Tables
List of Listings
Listing 4-9: UsingOleCommand to Access an Access Database
List of Sidebars
Table of Contents
SELECT Orders.ShippedDate, Orders.OrderID, "Order Subtotals".Subtotal,
Applied ADO.NETBuilding Data-Driven Solutions
DATENAME(yy,ShippedDate) AS Year
Introduction
FROM Orders INNER JOIN "Order Subtotals" ON Orders.OrderID =
Chapter 1 -Subtotals".OrderID
"Order ADO.NET Basics WHERE Orders.ShippedDate
Chapter 2 - Data
BETWEEN Components in Visual
@Beginning_Date ANDStudio .NET
@Ending_Date
Chapter 3 - ADO.NET in Disconnected Environments
Chapter 4 - ADO.NET in Connected Environments
Chapter 5 - Handling ADO.NET Events
This stored
Chapter procedure takes
6 - Integrating twoADO.NET
XML with parameters, Beginning_Date and Ending_Date. The procedure
selects7all -ofData
Chapter the Binding
orders between theseForms
and Windows two dates. It alsoControls
Data-Bound performs a join with the Order Subtotals
from the
Chapter 8 Order Subtotaland
- Constraints view, which
Data calculates the subtotals of each. If you want to execute this stored
Relations
procedure-inADO.NET
Chapter 9
ADO.NET, you just create a Command object of type StoredProcedure and then call the
Exception Handling
Command object's ExecuteReader method. You then cycle through the results in the reader that you're
Chapter 10 - Working with the ODBC .NET Data Provider
looking for from your stored procedure. Listing 4-12 executes a stored procedure that selects all the orders
Chapter 11 - Stored Procedures and Views
in July and displays their order IDs.
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Chapter
Listing13 - Developing
4-12: Executinga Custom Data Provider
and Reading the Results of a Stored Procedure
Chapter 14 - Developing Database Web Applications using ASP.NET
Chapter 15 - Using ADO.NET in Xml Web Services
Dim ConnectionString As String = "Integrated Security=SSPI;" & _
Chapter 16 - ASP.NET Server Controls and Data Binding
"Initial Catalog=Northwind;Data Source=MCB;"
Chapter 17 - Building Real-World Web Applications
Dim SQL As String = "SELECT * FROM Orders"
Chapter'18 - Object-Relational
Create connection Mapping in .NET
object
ChapterDim19 -conn
Mapped AsObjects: Performance Considerations
SqlConnection and Data Binding
= New SqlConnection(ConnectionString)
Chapter'20 - COM Interoperability
Create a SqlCommand and with
ADO.NETstored procedure as string
ChapterDim21 -cmd
Messaging
As SqlCommand = New SqlCommand("Sales By Year", conn)
Chaptercmd.Connection
22 - SQL Server and=ADO.NET:
conn Notes on Performance
Appendix' Aset- Relational
Command's Databases: Some Basic as
CommandType Concepts
StoredProcedure
cmd.CommandType = CommandType.StoredProcedure
Appendix B - Commonly Used SQL Statements
Appendix' C Create
- ADO.NETa SqlParameter and add a parameter
Frequently Asked Questions
Index Dim parm1 As SqlParameter = cmd.Parameters.Add("@Beginning_Date", _
SqlDbType.DateTime,
List of Figures 20)
parm1.Value = "7/1/1996"
List of Tables
Dim parm2 As SqlParameter = cmd.Parameters.Add("@Ending_Date", _
List of Listings
SqlDbType.DateTime, 20)
List of Sidebars
parm2.Value = "7/31/1996"
' Open connection
conn.Open()
' Call ExecuteReader to execute the stored procedure
Dim reader As SqlDataReader = cmd.ExecuteReader()
Dim orderlist As String = ""
' Read data from the reader
While reader.Read()
Dim result As String = reader("OrderID").ToString()
orderlist += result + " "
End While
' close the connection and reader
reader.Close()
Applied ADO.NET: Building Data-Driven Solutions
conn.Close()
by Mahesh Chand and David Talbot
conn.Dispose() ISBN:1590590732
Apress 2003 (928
' Print data on the console pages)
This text provides extensive
Console.WriteLine("Orders incoverage
July")of ADO.NET technology
Console.WriteLine("===============") classes, and
including ADO.NET internals, namespaces,
interfaces, and takes a comprehensive look at XML
Console.WriteLine(orderlist)
namespaces and classes, and how to integrate both with
ADO.NET.
Table
If youofwanted
Contents
to look at the subtotals along with the orders, you'd just add a DataReader index for
Applied ADO.NETBuilding
dereferencing the subtotalData-Driven Solutions
and concatenate with the order ID. Listing 4-13 shows the new DataReader
Introduction
loop.
Chapter 1 - ADO.NET Basics
Listing24-13:
Chapter Adding
- Data the Subtotal
Components Listing
in Visual Studioto the Output of the Stored Procedure Results
.NET
Chapter 3 - ADO.NET in Disconnected Environments
Chapter
While4 reader.Read()
- ADO.NET in Connected Environments
Dim nextID
Chapter As String
5 - Handling = reader("OrderID").ToString()
ADO.NET Events
Dim nextSubtotal
Chapter Aswith
6 - Integrating XML String = reader("Subtotal").ToString()
ADO.NET
orderlist
Chapter +=
7 - Data nextID
Binding + ", " Forms
and Windows + nextSubtotal + ", "
Data-Bound Controls
End While
Chapter 8 - Constraints and Data Relations
Chapter 9 - ADO.NET Exception Handling
Chapter 10 - Working with the ODBC .NET Data Provider
Chapter 11 - Stored Procedures and Views
The result of replacing this line of code in Listing 4-13 gives output that returns order IDs and subtotals in
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
the month of July in the Northwind database.
Chapter 13 - Developing a Custom Data Provider
Chapter 14 - Developing Database Web Applications using ASP.NET
Using TableDirect
Chapter 15 - Using ADO.NET in Xml Web Services
Chapter 16 - ASP.NET Server Controls and Data Binding
You can also use the TableDirect CommandType to read information directly from a table. You need
Chapter
to make17two
- Building
changes Real-World Web Applications
in the example to execute a table by setting TableDirect. First, you need to set
Chapter 18 - CommandText
Command's Object-Relationalproperty
Mappingtointhe
.NET
table name; second, you need to set the CommandType
Chapter 19to- CommandType.TableDirect.
property Mapped Objects: Performance Considerations and Data Binding
Chapter 20 - COM Interoperability and ADO.NET
The following
Chapter code reads the Customers table and sets the CommandType property to
21 - Messaging
CommandType.TableDirect:
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Appendix A - Relational Databases: Some Basic Concepts
cmd.CommandText
Appendix B - Commonly = "Customers"
Used SQL Statements
cmd.CommandType
Appendix = CommandType.TableDirect
C - ADO.NET Frequently Asked Questions
Index
List of Figures
List of Tables
Listing 4-14 reads information from the Customers table by setting the TableDirect method and
List of Listings
displaying it on the console.
List of Sidebars
Listing 4-14: UsingTableDirect to Read a Table
Similar to other data components, each data provider has a DataReader class. For example,
Table of Contents
OleDbDataReader is the DataReader class for OleDb data providers. Similarly, SqlDataReader and
Applied ADO.NETBuilding Data-Driven Solutions
ODBC DataReader are DataReader classes for the Sql and ODBC data providers, respectively.
Introduction
Chapter 1 - ADO.NET Basics
Initializing
Chapter 2 - Data a DataReader
Components in Visual Studio .NET
Chapter 3 - ADO.NET in Disconnected Environments
As you saw previously, you call the ExecuteReader method of the Command object, which returns an
Chapter 4 - ADO.NET in Connected Environments
instance of the DataReader. For example, you use the following code:
Chapter 5 - Handling ADO.NET Events
Chapter 6 - Integrating XML with ADO.NET
Dim cmd As SqlCommand = New SqlCommand(SQL, conn)
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
' Call ExecuteReader to return a DataReader
Chapter 8 - Constraints and Data Relations
Dim reader As SqlDataReader = cmd.ExecuteReader()
Chapter 9 - ADO.NET Exception Handling
Chapter 10 - Working with the ODBC .NET Data Provider
Chapter 11 - Stored
Once you're Procedures
done with and Views call the Close method to close a DataReader:
a DataReader,
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Chapter 13 - Developing a Custom Data Provider
reader.Close()
Chapter 14 - Developing Database Web Applications using ASP.NET
Chapter 15 - Using ADO.NET in Xml Web Services
Chapter 16 - ASP.NET Server Controls and Data Binding
Understanding DataReader Properties and Methods
Chapter 17 - Building Real-World Web Applications
Chapter 18 -describes
Table 4-9 Object-Relational Mapping inproperties,
the DataReader .NET and Table 4-10 describes the DataReader methods.
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
Chapter 20 - The
Table 4-9: COMDataReader
Interoperability and ADO.NET
Properties
Chapter 21 - Messaging
PROPERTY DESCRIPTION
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Appendix
DepthA - Relational Databases: Some
Indicates the Basic
depthConcepts
of nesting for a row
Appendix B - Commonly Used SQL Statements
FieldCount Returns
Appendix C - ADO.NET Frequently number
Asked of columns in a row
Questions
Index
IsClosed Indicates whether a DataReader is closed
List of Figures
Item
List of Tables
Gets the value of a column in native format
ListRecordsAffected
of Listings Number of rows affected after a transaction
List of Sidebars
as this:
With the GetString method of CustomerID, you don't need to do any conversion, but you do have to
know the zero-based column number of CustomerID (which, in this case, is zero).
InterpretingApplied
Batches of Building
ADO.NET: Queries Data-Driven Solutions
by Mahesh Chand and David Talbot ISBN:1590590732
TheDataReader also has methods that enable you to read data from a batch of SQL queries. The
Apress 2003 (928 pages)
following is an example of a batch transaction on the Customers and Orders tables. The NextResult
This text provides extensive coverage of ADO.NET technology
method allows you to obtain each query result from the batch of queries performed on both tables. In this
including ADO.NET internals, namespaces, classes, and
example, after creating a Connection
interfaces, object, you setlook
and takes a comprehensive up your Command object to do a batch query on the
at XML
Customers and the Orders tables:
namespaces and classes, and how to integrate both with
ADO.NET.
After that you call the NextResult method, which gets the next query result in the batch. The result is
processed again in the Read method loop. The code displays data from both tables.
Tip One of theApplied
commonlyADO.NET:
askedBuilding
questionsData-Driven Solutionsdiscussion forums and newsgroups is
on ADO.NET-related
about whenby Mahesh Chand and David
to use DataReader vs. Talbot
when to use a DataSet. Here is a simple answer: You use a
ISBN:1590590732
DataReaderApressinstead of apages)
2003 (928 DataSet when you need read-only data and you don't need to alter
the data. This
Seetext
the provides
"Using aextensive coverage
DataSet vs. Using of ADO.NET technology
a DataReader" section for a more in-depth answer.
including ADO.NET internals, namespaces, classes, and
interfaces, and takes a comprehensive look at XML
Understanding Command Behaviors
namespaces and classes, and how to integrate both with
ADO.NET.
TheExecuteReader method of a Command object such as SqlCommand has two over-loaded forms, as
shown:
Table of Contents
Applied ADO.NETBuilding Data-Driven Solutions
Overloads Public Function ExecuteReader() As SqlDataReader
Introduction
Overloads Public Function ExecuteReader(CommandBehavior) As SqlDataReader
Chapter 1 - ADO.NET Basics
Chapter 2 - Data Components in Visual Studio .NET
Chapter 3 form
The first - ADO.NET
doesn'tintake
Disconnected Environments
any arguments, but the second form takes an argument of type
Chapter 4 - ADO.NET inThe
CommandBehavior. Connected
Command Environments
behavior can control the action and return data as a result of
executing
Chapter 5 a - Handling
Command. ADO.NET Events
Chapter 6 - Integrating XML with ADO.NET
The default
Chapter 7
value passed in the ExecuteReader is CommandBehavior.Default, which returned the
- Data Binding and Windows Forms Data-Bound Controls
same results as ExecuteReader with no arguments.
Chapter 8 - Constraints and Data Relations
Chapter 9 - ADO.NET Exception Handling
WhenCommandBehavior.CloseConnection is passed in ExecuteReader, the associated
Chapter 10 - Working
Connection objectwith the ODBC
is closed when.NET
the Data Provider is closed. In this case, you don't have to call
DataReader
Chapter 11 - Stored Procedures
SqlConnection.Close and Views
explicitly.
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
You can
Chapter 13fetch only a single
- Developing row from
a Custom Data aProvider
database by executing a SqlCommand. The
CommandBehavior.SingleRow
Chapter value
14 - Developing Database Web passed in
Applications ExecuteReader
using ASP.NET returns the single row from a table
instead15
Chapter of -the result
Using set. in Xml Web Services
ADO.NET
Chapter 16 - ASP.NET Server Controls and Data provides
CommandBehavior.SequentialAccess Binding a way for the DataReader to handle rows that
Chapter 17 - Building Real-World Web Applications
contain large binary values (BLOB data) such as images or memo fields. SequentialAccess values
Chapter 18 - Object-Relational
enableDataReader to load Mapping
data as ainstream
.NET of bytes or characters.
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
By setting
Chapter 20 -the Interoperability and ADO.NET value, the DataReader doesn't return data. It returns the
CommandBehavior.KeyInfo
COM
table column
Chapter and primary key information instead. This is useful when you're collecting metadata.
21 - Messaging
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
TheCommandBehavior.SchemaOnly value returns column information only.
Appendix A - Relational Databases: Some Basic Concepts
Appendix B - Commonly Used SQL Statements
Appendix C - ADO.NET Frequently Asked Questions
Index
List of Figures
List of Tables
List of Listings
List of Sidebars
The DataAdapter: Adapting
Applied ADO.NET: toData-Driven
Building Your Environment
Solutions
by Mahesh Chand and David Talbot ISBN:1590590732
As you saw in Figure 4-1,
Apress a DataAdapter
2003 (928 pages) plays a vital role in the ADO.NET architecture. It sits between a
data source and a DataSet, and it passes data
This text provides extensive coveragefrom of
the data source
ADO.NET to the DataSet, and vice versa, with
technology
or without using commands.
including ADO.NET internals, namespaces, classes, and as DataSet, DataTable,
Now you'll use disconnected classes such
interfaces, and takes atocomprehensive
DataView, and DataViewManager look
write interactive at XML applications based on Windows Forms
database
and Web Forms.namespaces and classes, and how to integrate both with
ADO.NET.
TheDataAdapter enables you to connect to a database and specify SQL strings for retrieving data from or
writing data to a DataSet. As you know, a DataSet represents in-memory cached data. An in-memory
Table of Contents
object frees you from the confines of the specifics of a database and allows you to deal with the data in
Applied ADO.NETBuilding Data-Driven Solutions
memory. The DataAdapter serves as an intermediary between the database and the DataSet.
Introduction
Chapter 1 - ADO.NET Basics
Constructing
Chapter a DataAdapter
2 - Data Components in Visual Studio Object
.NET
Chapter 3 - ADO.NET in Disconnected Environments
TheDataAdapter constructor has many overloaded forms. You can create a DataAdapter using a
Chapter 4 - ADO.NET in Connected Environments
constructor with no arguments, pass a Command object, pass a Command object with Connection object as
Chapter 5 - Handling ADO.NET Events
arguments, or use a combination of these. You can also specify a SQL statement as a string for querying a
Chapter 6 table
particular - Integrating
or moreXML thanwith
oneADO.NET
table. You can also specify the connection string or a Connection object
Chapter 7 - Data Binding and Windows
to connect to the database. Listing 4-19 Forms Data-Bound
creates Controls
four SqlDataAdapter instances with different approaches.
Chapter
As you 8can- Constraints
see, the code andfirst
Data Relations
creates and opens SqlConnection and SqlCommand objects. Later you use
Chapter 9 -objects
these two ADO.NET Exception
to create Handling
DataAdapters. The first DataAdapter,da1, takes only one parameter of type
Chapter 10 - Working
SqlCommand. with SqlCommand
Because the ODBC .NETalready
Data Provider
has a SqlConnection, there's no need to specify a
connection
Chapter 11 - explicitly with the DataAdapter.
Stored Procedures and Views The second DataAdapter,da2, is created using no
argument,
Chapter 12 -and laterSQLXML,
Oracle, its SelectCommand
and Other .NET property is set to a SqlCommand. The third DataAdapter,da3,
Data Providers
takes a string argument as a SQL statement
Chapter 13 - Developing a Custom Data Provider and a second argument as SqlConnection. The last
DataAdapter takes both string arguments, one containing
Chapter 14 - Developing Database Web Applications using ASP.NET the SQL statement and the second containing
the connection string.
Chapter 15 - Using ADO.NET in Xml Web Services
Chapter 16 - ASP.NET Server Controls and Data Binding
Listing 4-19: CreatingSqlDataAdapter Instances
Chapter 17 - Building Real-World Web Applications
Chapter 18 - Object-Relational Mapping in .NET
' Create
Chapter a Connection
19 - Mapped Object Considerations and Data Binding
Objects: Performance
Dim ConnectionString
Chapter As and
20 - COM Interoperability String = "Integrated Security=SSPI;" & _
ADO.NET
"Initial Catalog=Northwind;Data Source=MCB;"
Chapter 21 - Messaging
Dim conn As SqlConnection = New SqlConnection(ConnectionString)
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Dim SQL As String = "SELECT * FROM Customers"
Appendix A - Relational Databases: Some Basic Concepts
' open a connection
Appendix B - Commonly Used SQL Statements
conn.Open()
Appendix C - ADO.NET Frequently Asked Questions
Dim cmd As SqlCommand = New SqlCommand(SQL, conn)
Index
' Creating SqlDataAdapter using different constructors
List
Dim of Figures
da1 As SqlDataAdapter = New SqlDataAdapter(cmd)
List
Dim Tables
of da2 As SqlDataAdapter = New SqlDataAdapter()
List of Listings
da2.SelectCommand = cmd
List
Dim of Sidebars
da3 As SqlDataAdapter = New SqlDataAdapter(SQL, conn)
Dim da4 As SqlDataAdapter = New SqlDataAdapter(SQL, ConnectionString)
As discussed, there's no difference between creating OleDb, Sql, and Odbc DataAdapters. The only
difference is the connection string. For example, Listing 4-20 shows you how to create an
OleDbDataAdapter object. Listing 4-20 uses the Access 2000 Northwind database and accesses all
records of the Orders table by using a SELECT * SQL query.
In this example, dataSet is a DataSet,startRecord is the zero-based record number to start with,
maxRecords is the maximum number of records to retrieve, and srcTable is the name of the source table
to use for table mapping. The following code calls the same overloaded method to get or refresh rows from
the 9th position toApplied
the 15th ADO.NET:
position of Building Data-Driven
the Orders Solutions
table. In other words, it fills the DataSet with seven rows if
found in the table:by Mahesh Chand and David Talbot ISBN:1590590732
Apress 2003 (928 pages)
This text provides extensive coverage of ADO.NET technology
adapter.Fill(ds, 9, 15, " Orders")
including ADO.NET internals, namespaces, classes, and
interfaces, and takes a comprehensive look at XML
namespaces and classes, and how to integrate both with
You can use a DataSet
ADO.NET.directly or a DataTable to fill or refresh the data of a DataSet. Listing 4-22 calls
theFill method to fill data to a DataSet, which later can bind with data-bound controls.
Table of Contents
Listing 4-22: Calling a DataAdapter'sFill Method
Applied ADO.NETBuilding Data-Driven Solutions
Introduction
' Create an OleDbDataAdapter object
Chapter 1 - ADO.NET Basics
Dim adapter As SqlDataAdapter = New SqlDataAdapter()
Chapter 2 - Data Components in Visual
adapter.SelectCommand Studio
= New .NET
SqlCommand(SQL, conn)
Chapter 3 - ADO.NET
' Create in Disconnected
DataSet Object Environments
Chapter
Dim4 ds- ADO.NET in Connected
As DataSet = NewEnvironments
DataSet("Orders")
Chapter 5 - Handling
' Call ADO.NET Events
DataAdapter's Fill method to fill data from the
Chapter 6 - Integratingto
' DataAdapter XMLthe
with DataSet
ADO.NET
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
adapter.Fill(ds)
Chapter 8 - Constraints and Data Relations
Chapter 9 - ADO.NET Exception Handling
Chapter 10 - Working with the ODBC .NET Data Provider
Chapter 11 - Stored Procedures and Views
Adding a DataTable to a DataSet
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
TheFillSchema
Chapter method
13 - Developing adds aData
a Custom Provider to a DataSet. The FillSchema method has two
DataTable
arguments;
Chapter the first is DataTable,
14 - Developing Database Weband the second
Applications is SchemaType.
using ASP.NET The SchemaType argument defines
the handling
Chapter of existing
15 - Using ADO.NETschema.
in XmlItWeb
has Services
two values: Mapped and Source. The SchemaType.Mapped value
means16
Chapter you- can applyServer
ASP.NET any existing table
Controls and mapping to the incoming schema and configure the DataSet with
Data Binding
the transformed
Chapter schema.
17 - Building The SchemaType.Source
Real-World Web Applications value means you can ignore any table mappings on
theDataAdapter
Chapter and configure
18 - Object-Relational the DataSet
Mapping in .NET using the incoming schema without applying any
transformations.
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
Chapter
Listing 20 - COM
4-23 usesInteroperability
the FillSchema and method
ADO.NETto add a DataTable to a DataSet.
Chapter 21 - Messaging
Listing22
Chapter 4-23: Using
- SQL theand
Server Method
ADO.NET: Notes
FillSchema of SqlDataAdapter
on Performance
Appendix A - Relational Databases: Some Basic Concepts
Appendix
' CreateB - Commonly Used SQL Statements
an OleDbDataAdapter object
Appendix C - ADO.NET
Dim adapter Frequently Asked Questions
As SqlDataAdapter = New SqlDataAdapter()
Index
adapter.SelectCommand = New SqlCommand(SQL, conn)
List
' of Figures DataSet Object
Create
List of Tables
Dim ds As DataSet = New DataSet("Orders")
List
' of Listings
Call DataAdapter's Fill method to fill data from the
' of
List DataAdapter
Sidebars to the DataSet
adapter.Fill(ds)
' Adding a DataTable to the DataSet
Dim table As DataTable() = _
adapter.FillSchema(ds, SchemaType.Mapped, "Categories")
Table of Contents
Applied ADO.NETBuilding Data-Driven Solutions
Introduction
Chapter 1 - ADO.NET Basics
Chapter 2 - Data Components in Visual Studio .NET
Chapter 3 - ADO.NET in Disconnected Environments
Chapter 4 - ADO.NET in Connected Environments
Chapter 5 - Handling ADO.NET Events
Chapter 6 - Integrating XML with ADO.NET
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
Chapter 8 - Constraints and Data Relations
Figure 4-3: Creating a Windows Forms application and adding controls to the form
Chapter 9 - ADO.NET Exception Handling
Chapter
Now add10 button
- Working
clickwith thehandlers
event ODBC .NET
for Data
both Provider
the OleDbDataAdapter and SqlDataAdapter buttons. You can
Chapter 11 - Stored Procedures and Views
add a button click event handler either by double-clicking the button or by using the Events tab of the
Chapter 12 -window.
Properties Oracle, SQLXML, and Other .NET Data
On the OleDbDataAdapter Providers
button click event handler, you'll write code to read data from
an OleDb data source and fill data to the DataGrid
Chapter 13 - Developing a Custom Data Provider control. On the SqlDataAdapter button click event
handler,
Chapter 14you'll write code
- Developing to readWeb
Database dataApplications
from a SQLusing
Server data source and fill data to the DataGrid.
ASP.NET
Chapter 15 - Using ADO.NET in Xml Web Services
Listing 4-24 shows the source code for the OleDbDataAdapter button click, and Listing 4-25 shows the
Chapter 16 - ASP.NET Server Controls and Data Binding
source code for the SqlDataAdapter button click. As you can see, you follow the same steps as before.
Chapter 17 - Building Real-World Web Applications
Open a connection, create a DataAdapter object with a SELECT string, create a DataSet object, call a
Chapter 18 - Object-Relational Mapping in .NET
DataAdapter'sFill method to fill the DataSet, and bind the DataSet to the DataGrid control using
Chapter 19 - Mapped Objects: Performance
theDataGrid.DataSouce Considerations and Data Binding
property of DataSet.DefaultViewManager, which represents the default
Chapter 20 - COM Interoperability
view of a DataSet object. and ADO.NET
Chapter 21 - Messaging
Listing22
Chapter 4-24: Displaying
- SQL Server andthe OrdersNotes
ADO.NET: TableonData in a DataGrid Using OleDbDataAdapter
Performance
Appendix A - Relational Databases: Some Basic Concepts
Appendix
Private B -Sub
Commonly Used SQL Statements
OleDbDataAdapter_Click(ByVal sender As System.Object, _
Appendix
ByValC e- ADO.NET Frequently Asked Questions
As System.EventArgs) Handles OleDbDataAdapter.Click
Index' Create a Connection Object
List ofDim
Figures
ConnectionString As String = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
List of"Data
Tables Source=c:\\Northwind.mdb"
List ofDim SQL As String = "SELECT * FROM Orders"
Listings
List ofDim conn As OleDbConnection = New OleDbConnection(ConnectionString)
Sidebars
' Open the connection
conn.Open()
' Create an OleDbDataAdapter object
Dim adapter As OleDbDataAdapter = New OleDbDataAdapter()
adapter.SelectCommand = New OleDbCommand(SQL, conn)
' Create DataSet Object
Dim ds As DataSet = New DataSet("Orders")
' Call DataAdapter's Fill method to fill data from the
' DataAdapter to the DataSet
adapter.Fill(ds)
' Bind data set to a DataGrid control
DataGrid1.DataSource = ds.DefaultViewManager
End Sub Applied ADO.NET: Building Data-Driven Solutions
by Mahesh Chand and David Talbot ISBN:1590590732
Apress 2003 (928 pages)
This text provides extensive coverage of ADO.NET technology
including ADO.NET
Listing 4-25: Displaying internals,
the Customers namespaces,
Table's Data inclasses, and
a DataGrid Using SqlDataAdapter
interfaces, and takes a comprehensive look at XML
namespaces and classes, and how to integrate both with
ADO.NET.
Private Sub SqlDataAdapter_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles SqlDataAdapter.Click
' Create a Connection Object
Table of Contents
Dim ConnectionString As String = "Integrated Security=SSPI;" & _
Applied ADO.NETBuilding Data-Driven Solutions
"Initial Catalog=Northwind;Data Source=MCB;"
Introduction
Dim conn As SqlConnection = New SqlConnection(ConnectionString)
Chapter 1 - ADO.NET Basics
Dim SQL As String = "SELECT * FROM Customers"
Chapter 2 - Data Components in Visual Studio .NET
' Open the connection
Chapter 3 - ADO.NET in Disconnected Environments
conn.Open()
Chapter 4 - ADO.NET
' Create in Connected Environments
an OleDbDataAdapter object
Chapter 5 - Handling ADO.NET Events
Dim adapter As SqlDataAdapter = New SqlDataAdapter()
Chapter 6 - Integrating XML with ADO.NET
adapter.SelectCommand = New SqlCommand(SQL, conn)
Chapter 7 - Data DataSet
' Create Binding andObject
Windows Forms Data-Bound Controls
Chapter 8 ds
Dim - Constraints
As DataSetand Data Relations
= New DataSet("Orders")
' Call
Chapter DataAdapter's
9 - ADO.NET Fill method to fill data from the
Exception Handling
' DataAdapter
Chapter 10 - Working withtothethe
ODBCDataSet
.NET Data Provider
adapter.Fill(ds)
Chapter 11 - Stored Procedures and Views
' Adding
Chapter a SQLXML,
12 - Oracle, DataTable to the
and Other .NETDataSet
Data Providers
Dim table As DataTable() = _
Chapter 13 - Developing a Custom Data Provider
adapter.FillSchema(ds, SchemaType.Mapped, "Categories")
Chapter 14 - Developing Database Web Applications using ASP.NET
' Bind data set to a DataGrid control
Chapter 15 - Using ADO.NET in Xml Web Services
DataGrid1.DataSource = ds.DefaultViewManager
Chapter 16 - ASP.NET Server Controls and Data Binding
End Sub
Chapter 17 - Building Real-World Web Applications
Chapter 18 - Object-Relational Mapping in .NET
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
Chapter 20 - of
The output COM Interoperability
Listing 4-24 looks and ADO.NET
like Figure 4-4.
Chapter 21 - Messaging
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Appendix A - Relational Databases: Some Basic Concepts
Appendix B - Commonly Used SQL Statements
Appendix C - ADO.NET Frequently Asked Questions
Index
List of Figures
List of Tables
List of Listings
List of Sidebars
Figure 4-4: Filling data from an Access database to a DataGrid control using OleDbDataAdapter
Table of Contents
Applied ADO.NETBuilding Data-Driven Solutions
Introduction
Figure
Chapter 1 - 4-5: Filling
ADO.NET data from a SQL Server database to a DataGrid control using SqlDataAdapter
Basics
Chapter 2 - Data Components in Visual Studio .NET
Chapter 3 - ADO.NET in Disconnected Environments
Filling -the
Chapter 4 DataAdapter
ADO.NET from a Recordset
in Connected Environments
Chapter 5 - Handling ADO.NET Events
Because
Chapter 6 Microsoft realized
- Integrating it would
XML with be difficult for some developers to let go of their ADO recordsets (or
ADO.NET
perhaps they
Chapter 7
have some legacy applications or components that would be difficult to convert), the
- Data Binding and Windows Forms Data-Bound Controls
DataAdapter'sFill method also allows you to fill a DataSet with an ADO recordset. You can't, however,
Chapter 8 - Constraints and Data Relations
go the other way and fill a recordset with a Dataset. The Fill method appends rows from the recordset to
Chapter 9 - ADO.NET Exception Handling
the existing DataSet'sDataTable. If a primary key exists for the DataRows in the DataSet, then the Fill
Chapter 10 - Working with the ODBC .NET Data Provider
method will attempt to update rows from the recordset with a matching primary key. You can call the
Chapter 11 - Stored Procedures and Views
recordset with the |following code:
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Chapter 13 - Developing a Custom Data Provider
OleDbDataAdapter1.Fill(ds, anADORecordset, SourceTableName)
Chapter 14 - Developing Database Web Applications using ASP.NET
Chapter 15 - Using ADO.NET in Xml Web Services
Chapter 16 - ASP.NET Server Controls and Data Binding
Updating the Database Using the Update Method
Chapter 17 - Building Real-World Web Applications
Chapter 18 - Object-Relational Mapping in .NET
The architecture of a DataAdapter has been designed so that you can make any changes you want to the
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
data in a filled DataSet, without affecting the database until you call the Update method. When Update is
Chapter
called, 20
the-DataAdapter
COM Interoperability and ADO.NET
will attempt to execute each query (UPDATE,INSERT,DELETE) on every row of
Chapter 21 - Messaging
theDataSet that has been updated, inserted, and deleted. For example, if you call Delete on a row in the
Chapter
DataSet,22 -then
SQL when
ServerUpdate
and ADO.NET: Notes
is called on Performance
on the DataAdapter, the DeleteCommand of the DataAdapter
Appendix A - Relational Databases: Some Basic Concepts
will be called using the particular row in the DataSet.
Appendix B - Commonly Used SQL Statements
NoteC Keep
Appendix in mind
- ADO.NET that this Asked
Frequently Update is different from a SQL UPDATE statement.
Questions
Index
To delete a row, you create an SqlCommand object with a DELETE statement and set the DeleteCommand
List of Figures
property of the DataAdapter.Listing 4-26 creates a SqlCommand object with a DELETE statement where
List of Tables
EmployeeId = 10.
List of Listings
List of Sidebars
Listing 4-26: Setting the DeleteCommand Property of DataAdapter
Also, you need to create a parameter for the command that maps to the EmployeeID in the database. (We
discuss parameters in more depth in the "Staying within the Parameters" section of this chapter.)
Listing 4-27 shows an example that creates and sets parameter properties for the Sql data provider.
Listing 4-27: Creating a SqlParameter
Applied ADO.NET: Building Data-Driven Solutions
by Mahesh Chand and David Talbot ISBN:1590590732
Dim workParamApress
As SqlParameter
2003 (928 pages) = Nothing
adapter.DeleteCommand = New SqlCommand(_
This text provides extensive coverage of ADO.NET technology
"DELETE from including
EmployeesADO.NETwhere EmployeeID
internals, = classes,
namespaces, 10", conn)
and
workParam = interfaces, and takes a comprehensive look at XML
adapter.DeleteCommand.Parameters.Add(_
namespaces
"@EmployeeID", and classes, and how to integrate both with
OleDbType.Integer)
ADO.NET.
workParam.SourceColumn = "EmployeeID"
workParam.SourceVersion = DataRowVersion.Original
Table of Contents
Applied ADO.NETBuilding Data-Driven Solutions
Introduction
Now you create a DataSet and fill it with the employees from the Employees table in the Northwind
Chapter 1 - ADO.NET Basics
database, as shown in Listing 4-28.
Chapter 2 - Data Components in Visual Studio .NET
Chapter
Listing34-28:
- ADO.NET
Callinginthe
Disconnected Environments
Fill Method of a DataAdapter
Chapter 4 - ADO.NET in Connected Environments
Chapter 5 - Handling ADO.NET Events
Dim ds As DataSet = New DataSet("EmployeeSet")
Chapter 6
- Integrating XML with ADO.NET
adapter.Fill(ds, "Employees")
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
Chapter 8 - Constraints and Data Relations
Chapter 9 - ADO.NET Exception Handling
Chapter 10 - Working
Now you're preparedwith the ODBC
to delete data.NET
fromData Provider
a table using a DataTable. By calling Delete on the last row in
theRows
Chapter 11collection, you mark and
- Stored Procedures the last row as deleted. To cause the actual deletion to take place in the
Views
Northwind
Chapter 12 -database, you need
Oracle, SQLXML, andtoOther
call Update onProviders
.NET Data the adapter. This causes the adapter to go through each
changed
Chapter 13row of the DataSet
- Developing and
a Custom seeProvider
Data which command needs to be called on that row. In the case of the last
row in the
Chapter 14 -Employees
Developingtable, you Web
Database call the DeleteCommand
Applications (see Listing 4-29).
using ASP.NET
Chapter 15 - Using ADO.NET in Xml Web Services
Listing 4-29: Removing a Row and Calling the Update Method of a DataAdapter
Chapter 16 - ASP.NET Server Controls and Data Binding
Chapter 17 - Building Real-World Web Applications
Dim Dt
Chapter 18 As DataTable =Mapping
- Object-Relational ds.Tables("Employees")
in .NET
Dim lastRow
Chapter As Objects:
19 - Mapped Integer = Dt.Rows.Count
Performance - and
Considerations 1 Data Binding
Dim firstName
Chapter As String and
20 - COM Interoperability = Dt.Rows(lastRow)("FirstName").ToString()
ADO.NET
Dim lastName As String = Dt.Rows(lastRow)("LastName").ToString()
Chapter 21 - Messaging
Dt.Rows(Dt.Rows.Count - 1).Delete()
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
adapter.Update(ds, "Employees")
Appendix A - Relational Databases: Some Basic Concepts
Appendix B - Commonly Used SQL Statements
Appendix C - ADO.NET Frequently Asked Questions
Index
Listing 4-30 shows the code that calls the Update method to delete a row from a DataSet and updates it
List
backof Figures
to the database using DataApdater'sUpdate method.
List of Tables
Listing
List 4-30: Calling a DataAdapter's Update Method
of Listings
List of Sidebars
Dim ConnectionString As String = "Integrated Security=SSPI;" & _
"Initial Catalog=Northwind;Data Source=MCB;"
Dim conn As SqlConnection = New SqlConnection(ConnectionString)
Dim adapter As SqlDataAdapter = New SqlDataAdapter()
Dim workParam As SqlParameter = Nothing
adapter.DeleteCommand = New SqlCommand(_
"DELETE from Employees where EmployeeID = 10", conn)
workParam = adapter.DeleteCommand.Parameters.Add(_
"@EmployeeID", OleDbType.Integer)
workParam.SourceColumn = "EmployeeID"
workParam.SourceVersion = DataRowVersion.Original
adapter.SelectCommand = New SqlCommand("SELECT * FROM Employees", conn)
Dim ds As Applied
DataSet ADO.NET:
= New Building Data-Driven Solutions
DataSet("EmployeeSet")
by Mahesh Chand
adapter.Fill(ds, "Employees") and David Talbot ISBN:1590590732
Apress 2003 (928 pages)
Dim Dt As DataTable = ds.Tables("Employees")
Dim lastRowThisAs
textInteger
provides extensive coverage of ADO.NET
= Dt.Rows.Count - 1 technology
including ADO.NET internals, namespaces, classes, and
Dim firstName As String = Dt.Rows(lastRow)("FirstName").ToString()
interfaces, and takes a comprehensive look at XML
Dim lastName As String
namespaces = Dt.Rows(lastRow)("LastName").ToString()
and classes, and how to integrate both with
Dt.Rows(Dt.Rows.Count
ADO.NET. - 1).Delete()
adapter.Update(ds, "Employees")
DataGrid1.DataSource = ds.DefaultViewManager
Table 'of release
Contents objects
Applied ADO.NETBuilding
conn.Close() Data-Driven Solutions
Introduction
conn.Dispose()
Chapter 1 - ADO.NET Basics
Chapter 2 - Data Components in Visual Studio .NET
Chapter 3 - ADO.NET in Disconnected Environments
Chapter 4
- ADO.NET in Connected Environments
Table and
Chapter 5
Column Mapping
- Handling ADO.NET Events
Chapter
One of 6the- important
Integratingproperties
XML with of
ADO.NET
the DataAdapter is the TableMappings property. This property
Chapter 7 - Data Binding and Windows
contains a collection of DataTableMappingForms Data-Bound Controls
objects (from the System.Data.Common namespace). The
Chapter uses theand
8 - Constraints
DataAdapter Data Relations
DataTableMapping object to map the table name of the data source to the
DataTable
Chapter name ofException
9 - ADO.NET the DataSet. In general, the names for both sources can be the same.
Handling
Chapter 10 - Working with the ODBC .NET Data Provider
For example, Listing 4-31 constructs the Northwind database's Order Table Mapping and adds it to the
Chapter 11 - Stored Procedures and Views
DataAdapter.
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Chapter
Listing13 - Developing
4-31: a Custom Data Provider
UsingDataTableMapping to Map the Orders Table of Northwind
Chapter 14 - Developing Database Web Applications using ASP.NET
Chapter 15 - Using ADO.NET in Xml Web Services
' Create a Connection Object
Chapter 16 - ASP.NET Server Controls and Data Binding
Dim ConnectionString As String = "Integrated Security=SSPI;" & _
Chapter 17 - Building Real-World Web Applications
"Initial Catalog=Northwind; Data Source=MCB;"
Chapter 18 - Object-Relational Mapping in .NET
Dim conn As SqlConnection = New SqlConnection(ConnectionString)
Chapter'19 - Mapped
Open the Objects: Performance Considerations and Data Binding
connection
Chapterconn.Open()
20 - COM Interoperability and ADO.NET
Chapter'21 - Messaging
Create a DataTableMapping object
ChapterDim22 -dtMapping
SQL Server and AsADO.NET: Notes on Performance
DataTableMapping =
Appendix A New- Relational Databases: Some
DataTableMapping("Orders",Basic Concepts"mapOrders")
AppendixDimB -adapter
Commonly As Used SQL Statements
SqlDataAdapter =
Appendix C -New SqlDataAdapter("Select
ADO.NET Frequently Asked Questions * From Orders", conn)
Index ' Call DataAdapter's TableMappings.Add method
adapter.TableMappings.Add(dtMapping)
List of Figures
' Create a DataSet Object and call DataAdapter's Fill method
List of Tables
' Make sure you use new name od DataTableMapping i.e., MayOrders
List of Listings
Dim ds As DataSet = New DataSet()
List of Sidebars
adapter.Fill(ds, "mapOrders")
DataGrid1.DataSource = ds.DefaultViewManager
'Dispose
conn.Close()
conn.Dispose()
The default mapping for a DataTable is the Table alias. If you use this mapping name, then you don't
need to mention the table in the Fill method. Listing 4-32 shows an example using DataTableMapping
with the Table option.
Listing 4-32: UsingDataTableMapping with the Table Option
Applied ADO.NET: Building Data-Driven Solutions
by Mahesh Chand and David Talbot ISBN:1590590732
' Create a Connection Object
Apress 2003 (928 pages)
Dim ConnectionString As String = "Integrated Security=SSPI;" & _
This text provides extensive coverage of ADO.NET technology
"Initial including
Catalog=Northwind;
ADO.NET internals,Data Source=MCB;"
namespaces, classes, and
Dim conn interfaces,
As SqlConnection = New SqlConnection(ConnectionString)
and takes a comprehensive look at XML
' Open the namespaces and classes, and how to integrate both with
connection
conn.Open() ADO.NET.
' Create a DataTableMapping object
Dim dtMapping
Table of Contents As DataTableMapping =
New DataTableMapping("Table",
Applied ADO.NETBuilding Data-Driven Solutions
"mapOrders")
Dim adapter As SqlDataAdapter =
Introduction
New SqlDataAdapter("Select * From Orders", conn)
Chapter 1 - ADO.NET Basics
' Call DataAdapter's TableMappings.Add method
Chapter 2 - Data Components in Visual Studio .NET
adapter.TableMappings.Add(dtMapping)
Chapter 3 - ADO.NET in Disconnected Environments
' Create a DataSet Object and call DataAdapter's Fill method
Chapter'4 Make
- ADO.NET
sure inyou
Connected
use newEnvironments
name od DataTableMapping i.e., MayOrders
ChapterDim
5 -ds Handling ADO.NET Events
As DataSet = New DataSet()
Chapteradapter.Fill(ds)
6 - Integrating XML with ADO.NET
ChapterDataGrid1.DataSource
7 - Data Binding and Windows Forms Data-Bound Controls
= ds.DefaultViewManager
Chapter'Dispose
8 - Constraints and Data Relations
Chapterconn.Close()
9 - ADO.NET Exception Handling
Chapterconn.Dispose()
10 - Working with the ODBC .NET Data Provider
Chapter 11 - Stored Procedures and Views
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Chapter 13 - Developing a Custom Data Provider
DataTables are not the only things aliased in ADO.NET. You can also alias the DataColumns using
Chapter 14 - Developing Database Web Applications using ASP.NET
DataColumnMapping objects. Why do you want column mapping? Let's say you have a table that has
Chapter 15 - Using ADO.NET in Xml Web Services
column names such as a1, a2, and so on, but when a user views the data in data-bound controls, you want
Chapter 16 - ASP.NET Server Controls and Data Binding
to display some meaningful names such as CustomerName and so on.
Chapter 17 - Building Real-World Web Applications
Chapter 18 - Object-Relational
Data column mapping allowsMapping in .NET
you to customize a DataSet's column names, which internally are mapped
Chapter 19 - Mapped
with a table columns.Objects:
You can Performance Considerations
achieve this by using and Data Binding
DataAdapter.DataTableMapping.ColumnMapping.
Chapter 20 - COM Interoperability and ADO.NET The DataColumnMapping property of
21 - Messaging is a collection of column mappings. You use the Add method of
DataTableMapping
Chapter
DataColumnCollection,
Chapter which adds
22 - SQL Server and ADO.NET: a column
Notes mapping. The Add method takes a column name of the
on Performance
source table
Appendix and a DataSet
A - Relational column
Databases: Somename. Listing 4-33 maps the OrderId,ShipName,ShipCity, and
Basic Concepts
OrderDate
Appendix columns of
B - Commonly theSQL
Used Orders table to mapID,mapName,mapCity, and mapDate, respectively.
Statements
Appendix C - ADO.NET Frequently Asked Questions
Listing 4-33: UsingDataColumnMapping
Index
List of Figures
' of
List Create
Tables a Connection Object
Dim ConnectionString As String = "Integrated Security=SSPI;" & _
List of Listings
"Initial Catalog=Northwind; Data Source=MCB;"
List of Sidebars
Dim conn As SqlConnection = New SqlConnection(ConnectionString)
' Open the connection
conn.Open()
' Create a DataTableMapping object
Dim dtMapping As DataTableMapping = New DataTableMapping("Table", "Orders")
Dim adapter As SqlDataAdapter = New SqlDataAdapter _
("SELECT OrderID, ShipName, ShipCity, OrderDate FROM Orders", conn)
' Call DataAdapter's TableMappings.Add method
adapter.TableMappings.Add(dtMapping)
dtMapping.ColumnMappings.Add(New DataColumnMapping("OrderID", "mapID"))
dtMapping.ColumnMappings.Add(New DataColumnMapping("ShipName", "mapName"))
dtMapping.ColumnMappings.Add(New DataColumnMapping("ShipCity", "mapCity"))
dtMapping.ColumnMappings.Add(New DataColumnMapping("OrderDate", "mapDate"))
' Create Applied
a DataSetADO.NET:
ObjectBuilding
and Data-Driven Solutions
call DataAdapter's Fill method
by Mahesh Chand and David Talbot
' Make sure you use new name od DataTableMapping ISBN:1590590732
i.e., MayOrders
Dim ds AsApress 2003 (928
DataSet pages)DataSet()
= New
This text provides extensive coverage of ADO.NET technology
adapter.Fill(ds)
including ADO.NET=internals,
DataGrid1.DataSource namespaces, classes, and
ds.DefaultViewManager
interfaces, and takes a comprehensive look at XML
'Dispose namespaces and classes, and how to integrate both with
conn.Close()
ADO.NET.
conn.Dispose()
Table of Contents
Applied ADO.NETBuilding Data-Driven Solutions
Introduction
Figure 4-6 displays the results of Listing 4-33.
Chapter 1 - ADO.NET Basics
Chapter 2 - Data Components in Visual Studio .NET
Chapter 3 - ADO.NET in Disconnected Environments
Chapter 4 - ADO.NET in Connected Environments
Chapter 5 - Handling ADO.NET Events
Chapter 6 - Integrating XML with ADO.NET
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
Chapter 8 - Constraints and Data Relations
Chapter 9 - ADO.NET Exception Handling
Chapter 10 - Working with the ODBC .NET Data Provider
Chapter 11 - Stored Procedures and Views
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Chapter 13 - Developing a Custom Data Provider
Chapter 14 - Developing Database Web Applications using ASP.NET
Figure 4-6: Column mapping
Chapter 15 - Using ADO.NET in Xml Web Services
Chapter
The IDE16automatically
- ASP.NET Server Controls
generates and of
much Data
theBinding
mappings, so you don't have to worry about them. But,
Chapter 17 - Building Real-World Web Applications
occasionally, you may want to choose your own schema names for your DataSet that map back to the data
Chapter
source.18 - Object-Relational Mapping in .NET
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
Chapter 20 - COM Interoperability and ADO.NET
Chapter 21 - Messaging
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Appendix A - Relational Databases: Some Basic Concepts
Appendix B - Commonly Used SQL Statements
Appendix C - ADO.NET Frequently Asked Questions
Index
List of Figures
List of Tables
List of Listings
List of Sidebars
CommandBuilder: Easing
Applied ADO.NET: the Data-Driven
Building Work of Solutions
Programmers
by Mahesh Chand and David Talbot ISBN:1590590732
Sometimes creating SQL
Apress statements
2003 can be a lengthy job when dealing with many columns in a table. A
(928 pages)
CommandBuilder object reduces the burden
This text provides extensive of creating
coverage SQL statement
of ADO.NET for you. In other words, the
technology
CommandBuilder object helps you generate UPDATE, DELETE,
including ADO.NET internals, namespaces, classes, and and INSERT commands on a single
interfaces,
database table for and takes The
a DataAdapter. a comprehensive look at XML
OleDbCommandBuilder, SqlCommandBuilder, and
namespaces
OdbcCommandBuilder and classes,
classes representand how
the to integrate both with
CommandBuilder object in the OleDb, Sql, and Odbc
ADO.NET.
data providers (respectively).
Using SqlCommandBuilder
- Data Binding and Windows FormsMembers
Chapter 7 Data-Bound Controls
Chapter 8 - Constraints and Data Relations
TheDataAdapter
Chapter 9 - ADO.NETproperty of Handling
Exception a CommandBuilder represents the DataProvider attached to a
10 - Working object
CommandBuilder
Chapter forODBC
with the which.NET
automatic SQL statements are generated. The GetDeleteCommand,
Data Provider
GetUpdateCommand,
Chapter and GetInsertCommand
11 - Stored Procedures and Views methods return the Delete,Update, and Insert
commands
Chapter in the form
12 - Oracle, of a Command
SQLXML, and Other object. TheProviders
.NET Data RefreshSchema method refreshes the database
schema.
Chapter 13 - Developing a Custom Data Provider
Chapter 14 - Developing Database Web Applications using ASP.NET
Using SqlCommandBuilder
Chapter 15 - Using ADO.NET in Xml Web Services
Chapter 16 - ASP.NET Server Controls and Data Binding
Now you'll
Chapter 17 -see how to
Building use the SqlCommandBuilder
Real-World Web Applications in an application. You can use the
OleDbCommandBuilder and OdbcCommandBuilder classes in the same way.
Chapter 18 - Object-Relational Mapping in .NET
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
As usual, you create a connection to the database and use it to create the adapter object. The adapter is
Chapter 20 - COM
constructed with Interoperability
the initial queryand ADO.NET
for the Employees table as well as with the database connection.
Chapter 21 - Messaging
Next, you
Chapter 22 construct the and
- SQL Server CommandBuilder by passing
ADO.NET: Notes on the DataAdapter into its constructor. The act of
Performance
creating Athe
Appendix Databases: automatically
CommandBuilder
- Relational causes the UPDATE,INSERT, and DELETE commands to
Some Basic Concepts
be generated
Appendix for the adapter.
B - Commonly Used SQLThe following code creates two SqlCommandBuilder objects:
Statements
Appendix C - ADO.NET Frequently Asked Questions
Dim adapter As SqlDataAdapter = New SqlDataAdapter(SQL, conn)
Index
Dim builder1 As SqlCommandBuilder = New SqlCommandBuilder()
List of Figures
builder1.DataAdapter = adapter
List of Tables
Dim builder2 As SqlCommandBuilder = _
List of Listings
New SqlCommandBuilder(adapter)
List of Sidebars
Next, fill the DataSet using the adapter and create an instance of the Employees DataTable from the
DataSet:
Now, insert a new DataRow into the DataTable in memory and populate a row with your desired values
using the DataTable'sAddNew method. After that you call the DataRowCollection.Add method to
add the row to the DataTable:
Applied ADO.NET: Building Data-Driven Solutions
by Mahesh Chand and David Talbot ISBN:1590590732
' Create a data table object and add a new row
Apress 2003 (928 pages)
Dim EmployeeTable As DataTable = ds.Tables("Employees")
This text provides extensive coverage of ADO.NET technology
Dim row As DataRow = EmployeeTable.NewRow()
including ADO.NET internals, namespaces, classes, and
row("FirstName") = takes
interfaces, and "Rodney"
a comprehensive look at XML
namespaces= and
row("LastName") classes, and how to integrate both with
"DangerField"
ADO.NET.
row("Title") = "Manager "
EmployeeTable.Rows.Add(row)
Table of Contents
Applied
Finally,ADO.NETBuilding Data-Driven
you call DataAdapter's Solutions
Update method to update the DataTable changes to the data source:
Introduction
Chapter 1 - ADO.NET Basics
// Update data adapter
Chapter 2 - Data Components in Visual Studio .NET
adapter.Update(ds, "Employees");
Chapter 3 - ADO.NET in Disconnected Environments
Chapter 4 - ADO.NET in Connected Environments
Listing 54-34
Chapter shows the
- Handling full source
ADO.NET code for creating and using a CommandBuilder object.
Events
Chapter 6 - Integrating XML with ADO.NET
Listing 4-34:
Chapter 7
Creating and Using the SqlCommandBuilder Class
- Data Binding and Windows Forms Data-Bound Controls
Chapter 8 - Constraints and Data Relations
ChapterDim
9 -ConnectionString As String = "Integrated Security=SSPI;" & _
ADO.NET Exception Handling
"Initial
Chapter 10 - Working with Catalog=Northwind;Data
the ODBC .NET Data Provider Source=MCB;"
Dim conn
Chapter As SqlConnection
11 - Stored = New SqlConnection(ConnectionString)
Procedures and Views
ChapterDim
12 -SQL AsSQLXML,
Oracle, Stringand
= Other
"SELECT * FROM
.NET Data Employees"
Providers
Chapter'13
open a connection
- Developing a Custom Data Provider
conn.Open()
Chapter 14 - Developing Database Web Applications using ASP.NET
Dim adapter As SqlDataAdapter = New SqlDataAdapter(SQL, conn)
Chapter 15 - Using ADO.NET in Xml Web Services
Dim builder1 As SqlCommandBuilder = New SqlCommandBuilder()
Chapter 16 - ASP.NET Server Controls and Data Binding
builder1.DataAdapter = adapter
Chapter 17 - Building Real-World Web Applications
Dim builder2 As SqlCommandBuilder = _
Chapter 18 - Object-Relational Mapping in .NET
New SqlCommandBuilder(adapter)
Chapter'19 - Mapped
Create a Objects:
command Performance
builderConsiderations
object and Data Binding
ChapterDim20 -builder
COM Interoperability and ADO.NET
As SqlCommandBuilder = New SqlCommandBuilder(adapter)
Chapter'21 - Messaging
Create a dataset object
ChapterDim22 -dsSQLAsServer and ADO.NET:
DataSet = NewNotes on Performance
DataSet("EmployeeSet")
Appendix A - Relational Databases:
adapter.Fill(ds, "Employees") Some Basic Concepts
Appendix' BCreate
- Commonly Used table
a data SQL Statements
object and add a new row
AppendixDim C -EmployeeTable
ADO.NET FrequentlyAs DataTable
Asked Questions = ds.Tables("Employees")
Index Dim row As DataRow = EmployeeTable.NewRow()
row("FirstName") = "Bill"
List of Figures
row("LastName") = "Harvey"
List of Tables
row("Title") = "President"
List of Listings
EmployeeTable.Rows.Add(row)
List of Sidebars
' Update data adapter
adapter.Update(ds, "Employees")
' Dispose
conn.Close()
conn.Dispose()
As you can see from Listing 4-34, you didn't have to figure out how to create InsertCommand for the
Employees table because the CommandBuilder did it for you. All you had to do was add a row to the
DataSet and invoke an Update on the DataAdapter. You may argue that the InsertCommand is
automatically generated by VS .NET with the DataAdapter configurer, but the CommandBuilder works
with the SelectCommand you choose for the adapter, so you can change the SelectCommand on the fly
Applied ADO.NET:
and reuse the CommandBuilder atBuilding
runtime. Data-Driven Solutions
by Mahesh Chand and David Talbot ISBN:1590590732
Note that you should call the
Apress 2003RefreshSchema
(928 pages) method of the CommandBuilder if the SelectCommand
of the associatedThis text provideschanges.
DataAdapter extensiveThe RefreshSchema
coverage rebuilds the other command structures
of ADO.NET technology
(InsertCommand, including ADO.NET internals,
DeleteCommand, namespaces, of
UpdateCommand) classes, and
the DataAdapter.
interfaces, and takes a comprehensive look at XML
namespaces and classes, and how to integrate both with
ADO.NET.
Table of Contents
Applied ADO.NETBuilding Data-Driven Solutions
Introduction
Chapter 1 - ADO.NET Basics
Chapter 2 - Data Components in Visual Studio .NET
Chapter 3 - ADO.NET in Disconnected Environments
Chapter 4 - ADO.NET in Connected Environments
Chapter 5 - Handling ADO.NET Events
Chapter 6 - Integrating XML with ADO.NET
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
Chapter 8 - Constraints and Data Relations
Chapter 9 - ADO.NET Exception Handling
Chapter 10 - Working with the ODBC .NET Data Provider
Chapter 11 - Stored Procedures and Views
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Chapter 13 - Developing a Custom Data Provider
Chapter 14 - Developing Database Web Applications using ASP.NET
Chapter 15 - Using ADO.NET in Xml Web Services
Chapter 16 - ASP.NET Server Controls and Data Binding
Chapter 17 - Building Real-World Web Applications
Chapter 18 - Object-Relational Mapping in .NET
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
Chapter 20 - COM Interoperability and ADO.NET
Chapter 21 - Messaging
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Appendix A - Relational Databases: Some Basic Concepts
Appendix B - Commonly Used SQL Statements
Appendix C - ADO.NET Frequently Asked Questions
Index
List of Figures
List of Tables
List of Listings
List of Sidebars
Staying within the
Applied Parameters
ADO.NET: Building Data-Driven Solutions
by Mahesh Chand and David Talbot ISBN:1590590732
ADO.NET wraps Apress
a classaround
2003 (928the parameters used for each column of the database. You can use the
pages)
parameters in conjunction with SelectCommand
This text provides extensive coverageto help you to select
of ADO.NET data for the DataSet. You also
technology
use it in conjunction with the other commands of the CommandDataSet
including ADO.NET internals, namespaces, classes, and (InsertCommand,
UpdateCommand, interfaces, and takes atocomprehensive
DeleteCommand) place data intolook
theatDataSet.
XML These are generated automatically
when you insert anamespaces and classes, component
OleDbDataAdapter and how to integrate
from the both with
Toolbox.
ADO.NET.
TheOleDbType describes the type information for the parameter. It consists of everything from strings to
Global Unique Identifiers (GUIDs).
Table of Contents
Applied
The SqlADO.NETBuilding
data provider hasData-Driven Solutions
a SqlDbType, and the Odbc data provider has an OdbcType. These type
Introduction
names and definitions differ, depending upon the provider you're using; for example, the Money type is the
Chapter
same in1 Odbc
- ADO.NET Basics
and Sql data providers, but it's called Currency in OleDb data providers.
Chapter 2 - Data Components in Visual Studio .NET
Not only
Chapter 3 does a parameter
- ADO.NET have a DbType
in Disconnected property, but a parameter has a Direction (input, output),
Environments
Size, and
Chapter 4 - even a Value.
ADO.NET Table 4-14
in Connected describes the SqlParameter properties.
Environments
Chapter 5 - Handling ADO.NET Events
Table 4-14:
Chapter 6
The SqlParameter Class Properties
- Integrating XML with ADO.NET
Chapter 7 - Data BindingDESCRIPTION
PROPERTY and Windows Forms Data-Bound Controls
Chapter 8 - Constraints and Data Relations
DbType
Chapter Represents
9 - ADO.NET Exception the DbType of the parameter.
Handling
Chapter 10 - Working with
Direction the ODBC .NET
Represents Data Provider
the direction of a parameter. A parameter can be input-only,
Chapter 11 - Stored Procedures and Views
output-only, bi-directional, or a stored procedure.
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
IsNullable Represents whether a parameter accepts null values.
Chapter 13 - Developing a Custom Data Provider
Chapter 14 - Developing Database
OleDbType Web
Represents Applications
the OleDbType using ASP.NET
of the parameter.
Chapter 15 - Using ADO.NET in Xml Web Services
Offset Represents the offset to the Value property.
Chapter 16 - ASP.NET Server Controls and Data Binding
Chapter 17 - Building Real-World
ParameterName Web the
Represents Applications
name of the parameter.
Chapter 18 - Object-Relational Mapping in .NET
Precision Represents the maximum number of digits used to represent the Value
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
property.
Chapter 20 - COM Interoperability and ADO.NET
Scale
Chapter 21 - Messaging Represents the decimal places to which Value is resolved.
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Size Represents the maximum size in bytes a column can store.
Appendix A - Relational Databases: Some Basic Concepts
SourceColumn
Appendix Represents
B - Commonly Used the source column mapped to the DataSet.
SQL Statements
Appendix C - ADO.NET Frequently
SourceVersion Asked
Represents theQuestions
DataRow version.
Index
ListSqlDbType
of Figures Represents the SqlDbType of the parameter
ListValue
of Tables Represents the value of the parameter.
List of Listings
List of Sidebars
Now you're going to see the construction of parameters using the Integrated Development Environment
(IDE) as well as manually. Listing 4-35 shows the construction of an OleDbParameter generated by the
IDE for the Northwind database. All commands have a collection of parameters; in this example, the
parameter ContactName is being added to a command used for deleting from the database.
Me.oleDbDeleteCommand2.Parameters.Add(New
System.Data.OleDb.OleDbParameter("ContactName",
System.Data.OleDb.OleDbType.Char, 30,
System.Data.ParameterDirection.Input, False,
((System.Byte)(0)), ((System.Byte)(0)),
Applied
"ContactName", ADO.NET: Building Data-Driven Solutions
System.Data.DataRowVersion.Original,
Nothing)) by Mahesh Chand and David Talbot ISBN:1590590732
Apress 2003 (928 pages)
This text provides extensive coverage of ADO.NET technology
including ADO.NET internals, namespaces, classes, and
interfaces, and takes a comprehensive look at XML
Luckily, the IDE automatically generates the parameters for you; as you can see, this is a lot of code to
namespaces and classes, and how to integrate both with
write for just one ADO.NET.
parameter. Imagine if you had to manually deal with a database table of 50 parameters!
You need to create and add parameters to the command for each parameter reference that appears in
the SQL
Table command. If the SQL command only describes a single row insert or update, then you don't have
of Contents
parameters.
Applied But, more often
ADO.NETBuilding than not,Solutions
Data-Driven when you're using DataSets, DataTables, and DataRows, you'll
need parameters because these in-memory structures operate on several rows.
Introduction
Chapter 1 - ADO.NET Basics
Parameters appear in a SQL Server INSERT command proceeded by an @ sign, as shown in the
Chapter 2 - Data Components in Visual Studio .NET
following code:
Chapter 3 - ADO.NET in Disconnected Environments
Chapter 4 - ADO.NET in Connected Environments
sqlInsertCommand1.CommandText =
Chapter 5 - Handling ADO.NET Events
@"INSERT INTO Customers(CustomerID, CompanyName, ContactName)"+
Chapter 6 - Integrating XML with ADO.NET
" VALUES (@CustomerID, @CompanyName, @ContactName)"
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
In OleDb, parameters appear as question marks such as:
Chapter 8 - Constraints and Data Relations
oleDbInsertCommand2.CommandText =
Chapter
"INSERT9 -INTO
ADO.NET Exception Handling
Customers(Address, City, CompanyName, ContactName)"+
Chapter 10 - Working
" VALUES (?, ?,with
?,the
?)"ODBC .NET Data Provider
Chapter 11 - Stored Procedures and Views
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
To add13
Chapter the- parameter
Developing @CustomerID to the InsertCommand of the SqlDataAdapter, simply call Add
a Custom Data Provider
on the command's
Chapter ParameterCollection.
14 - Developing This
Database Web Applications willASP.NET
using return a parameter in which you can further assign
properties,
Chapter 15 - such
Usingas:
ADO.NET in Xml Web Services
Chapter 16 - ASP.NET Server Controls and Data Binding
SqlParameter
Chapter 17 - BuildingworkParam = Applications
Real-World Web theSqlServerAdapter.InsertCommand.
Parameters.Add("@CustomerID",
Chapter 18 - Object-Relational Mapping in .NET SqlDbType.Int)
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
Chapter 20 - COM Interoperability and ADO.NET
Two other crucial properties are the name of the column that the parameter is mapping to and the
Chapter 21 - Messaging
RowVersion. Typically, it's good to give the parameter the same name as the column of the database to
Chapter 22 confusion:
avoid the - SQL Server and ADO.NET: Notes on Performance
Appendix A - Relational Databases: Some Basic Concepts
Appendix B - Commonly Used SQL Statements
workParam.SourceColumn = "CustomerID"
Appendix C - ADO.NET Frequently Asked Questions
workParam.SourceVersion = DataRowVersion.Original
Index
List of Figures
The
List ofSourceVersion
Tables can be either Current or Original. The SourceVersionproperty helps the
DataAdapter's
List of Listings Update command decide which value version to load when executing the SQL
UpdateCommand
List of Sidebars on the database. (InsertCommand and DeleteCommand ignore the
SourceVersion.) The SourceVersion property comes in handy when you're updating a row whose
primary key you may want to change. If the value is DataRowVersion.Original, then the primary key
will retain its original value.
You just saw an example of a parameter generated by the VS .NET IDE. It's always a better idea to write
your own code if you really want to know what goes under the hood. So, let's create parameters and use
them in a SqlCommand. The following code creates a parameter by reading a value from a TextBox
control and deletes the record from the Categories table that matches the CategoryID as
TextBox1.Text:
Nowof
Table let's construct a SqlCommand with an UPDATE SQL statement using three parameters. The following
Contents
code creates
Applied and adds three
ADO.NETBuilding parameters
Data-Driven to the collection. The code also constructs an UPDATE SQL
Solutions
statement with parameters and calls the ExecuteNonQuery method to execute the command:
Introduction
Chapter 1 - ADO.NET Basics
dim strId
Chapter as Components
2 - Data string = inTextBox1.Text
Visual Studio .NET
dim strCatName as stringEnvironments
Chapter 3 - ADO.NET in Disconnected = TextBox2.Text
dim strDesc as string = TextBox3.Text
Chapter 4 - ADO.NET in Connected Environments
dim sql = "UPDATE Categories SET CategoryName=@catName, " & _
Chapter 5 - Handling ADO.NET Events
" Description=@desc WHERE CategoryID=@catID"
Chapter 6 - Integrating XML with ADO.NET
dim cmd as SqlCommand = new SqlCommand(sql, conn)
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
cmd.Parameters.Add("@catID", strId)
Chapter 8 - Constraints and Data Relations
cmd.Parameters.Add("@catName", strCatName)
Chapter 9 - ADO.NET Exception Handling
cmd.Parameters.Add("@desc", strDesc)
Chapter 10 - Working with the ODBC .NET Data Provider
cmd.ExecuteNonQuery()
Chapter 11 - Stored Procedures and Views
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
You can
Chapter 13even directly assign
- Developing parameter
a Custom values by using the Value property. For example, the following
Data Provider
code adds
Chapter 14 -two parameters
Developing to theWeb
Database command with the
Applications values
using NewCategory and New Description:
ASP.NET
Chapter 15 - Using ADO.NET in Xml Web Services
Chapter 16 - ASP.NET Server Controls and Data Binding
cmd.Parameters.Add("@CategoryName", SqlDbType.VarChar, 80).Value = _
"NewCategory"
Chapter 17 - Building Real-World Web Applications
cmd.Parameters.Add("@Description",
Chapter 18 - Object-Relational Mapping in .NET SqlDbType.Int).Value = _
"New Description"
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
Chapter 20 - COM Interoperability and ADO.NET
Chapter 21 - Messaging
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Appendix A - Relational Databases: Some Basic Concepts
Appendix B - Commonly Used SQL Statements
Appendix C - ADO.NET Frequently Asked Questions
Index
List of Figures
List of Tables
List of Listings
List of Sidebars
The DataSet in Connected
Applied Environments
ADO.NET: Building Data-Driven Solutions
by Mahesh Chand and David Talbot ISBN:1590590732
In Chapter 3, you Apress
saw how to create
2003 and use DataSet objects in disconnected environments. You saw
(928 pages)
how to use a DataSet's properties and howcoverage
This text provides extensive to fill, delete, and update
of ADO.NET data using DataTable objects. In
technology
the following sections, you'll see how to work with DataSets in
including ADO.NET internals, namespaces, classes, and connected environments. Instead of using
aDataTable, you'llinterfaces, and takes a comprehensive
use a DataAdapter lookdata
to fill and save at XML
from a DataSet to a data source.
namespaces and classes, and how to integrate both with
As mentioned, theADO.NET.
Fill method of a DataAdapter fills data from a data source to a DataSet. Once the
DataSet is filled with data, you can do any operation on this data. This data is disconnected data, and
there's no connection between a DataSet and a data source until you finally call the Update method of a
Table of Contents
DataAdapter. The Update method of a DataAdapter saves the DataSet changes to the data
Applied ADO.NETBuilding Data-Driven Solutions
source. You saw these Fill and Update methods in "The DataAdapter: Adapting to Your Environment."
Introduction
Chapter 1 - ADO.NET Basics
Filling
Chapter 2 -aData
DataSet from
Components Multiple
in Visual Tables
Studio .NET
Chapter 3 - ADO.NET in Disconnected Environments
You saw how to fill a DataSet from a table in many of the previous samples. Now, there may be times
Chapter 4 - ADO.NET in Connected Environments
when you'll want to view data from multiple tables in data-bound controls. If you remember ADO, you used
Chapter 5 - Handling ADO.NET Events
SQLJOIN statements to fill a recordset from multiple tables.
Chapter 6 - Integrating XML with ADO.NET
Chapter 7 - Data
In ADO.NET, Binding
there and Windows
are different ways Forms Data-Bound
you can Controls
fill data from multiple tables depending on your
requirements.
Chapter If you want
8 - Constraints andtoData
viewRelations
data from multiple tables in multiple data-bound controls, the simplest
way is create
Chapter a DataAdapter
9 - ADO.NET for each table and fill a DataSet from a DataAdapter and use the
Exception Handling
DataSet
Chapter 10 -toWorking
bind data to the
with the ODBC
controls.
.NETListing 4-36 simply creates two SqlDataAdapter objects using
Data Provider
two different
Chapter SqlCommand
11 - Stored objects
Procedures and then fills two different DataSet objects (which you later bind to
and Views
two separate
Chapter DataGrid
12 - Oracle, controls).
SQLXML, and Other .NET Data Providers
Chapter 13 - Developing a Custom Data Provider
Listing 4-36: Filling Data from Multiple Tables
Chapter 14 - Developing Database Web Applications using ASP.NET
Chapter 15 - Using ADO.NET in Xml Web Services
Dim ConnectionString
Chapter As String
16 - ASP.NET Server Controls = Binding
and Data "Integrated Security=SSPI;" & _
"Initial Catalog=Northwind;Data Source=MCB;"
Chapter 17 - Building Real-World Web Applications
Dim conn As SqlConnection = New SqlConnection(ConnectionString)
Chapter 18 - Object-Relational Mapping in .NET
conn.Open()
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
Dim adapter1 As SqlDataAdapter = New SqlDataAdapter()
Chapter 20 - COM Interoperability and ADO.NET
Dim adapter2 As SqlDataAdapter = New SqlDataAdapter()
Chapter 21 - Messaging
adapter1.SelectCommand = New SqlCommand("SELECT * FROM Customers")
Chapter 22 - SQL Server and ADO.NET:
adapter2.SelectCommand = NewNotes on Performance
SqlCommand("SELECT * FROM Orders")
Appendix A - Relational Databases:
adapter1.SelectCommand.Connection Some Basic Concepts
= conn
Appendix B - Commonly Used SQL Statements
adapter2.SelectCommand.Connection = conn
Appendix
Dim ds1 C -As
ADO.NET
DataSet Frequently
= New Asked Questions
DataSet()
Index
Dim ds2 As DataSet = New DataSet()
List of Figures
adapter1.Fill(ds1)
adapter2.Fill(ds2)
List of Tables
DataGrid1.DataSource
List of Listings = ds1.DefaultViewManager
DataGrid2.DataSource
List of Sidebars = ds2.DefaultViewManager
' Dispose
conn.Close()
conn.Dispose()
Now what if you want to fill a DataSet with data from multiple tables? Actually, that's pretty easy, too. If
you remember the Merge method of the DataSet from Chapter 3, you'll learned how to merge two
DataSet objects. You can use the same method to fill data from two different tables in two different
DataSet objects and later call the Merge method, which merges one DataSet into another. Listing 4-37
fills two DataSet objects from two different tablesCustomers and Ordersand later one DataSet
merges into another. After that you just bind the final DataSet to a DataGrid control, which displays
data from both tables.
Applied ADO.NET: Building Data-Driven Solutions
by Mahesh
Listing 4-37: Merging TwoChand and David
DataSet Talbot
Objects ISBN:1590590732
Apress 2003 (928 pages)
This text provides extensive coverage of ADO.NET technology
Dim adapter As SqlDataAdapter = New SqlDataAdapter()
including ADO.NET internals, namespaces, classes, and
adapter.SelectCommand
interfaces, and takes= a New SqlCommand("SELECT
comprehensive look at XML * FROM Customers")
adapter.SelectCommand.Connection
namespaces and classes, and how to= integrate
conn both with
Dim ds1 AsADO.NET.
DataSet = New DataSet()
adapter.Fill(ds1)
adapter.SelectCommand = New SqlCommand("SELECT * FROM Orders")
Table of Contents
adapter.SelectCommand.Connection = conn
Applied ADO.NETBuilding Data-Driven Solutions
Dim ds2 As DataSet = New DataSet()
Introduction
adapter.Fill(ds2)
Chapterds1.Merge(ds2,
1 - ADO.NET BasicsFalse, MissingSchemaAction.Add)
Chapter 2 - Data Components =
DataGrid1.DataSource in ds1.DefaultViewManager
Visual Studio .NET
Chapter 3 - ADO.NET in Disconnected Environments
Chapter 4 - ADO.NET in Connected Environments
Chapter 5 - Handling ADO.NET Events
Note
Chapter 6 The Merge method
- Integrating hasADO.NET
XML with seven overloaded forms. Using this method, you can even merge
Chapter 7 DataRow and DataTable
- Data Binding and Windows objects with a DataSet.
Forms Data-Bound Controls
Chapter 8 - Constraints and Data Relations
Using a
Chapter 9 SQL Statement
- ADO.NET to Read Data from Two or More Tables
Exception Handling
Chapter 10 - Working with the ODBC .NET Data Provider
Using a11SQL
Chapter statement
- Stored is the and
Procedures simplest
Viewsway to put data from multiple tables into a DataSet. The following
code selects
Chapter data from
12 - Oracle, the Customers
SQLXML, and Data
and Other .NET Orders tables and fills it to a single DataSet:
Providers
Chapter 13 - Developing a Custom Data Provider
Chapter 14 - Developing
Dim conn Database Web=Applications
As SqlConnection using ASP.NET
New SqlConnection(ConnectionString)
Chapter
SQL =15"SELECT
- Using ADO.NET
* FROMin Customers;
Xml Web Services
SELECT * FROM Orders"
conn.Open()
Chapter 16 - ASP.NET Server Controls and Data Binding
Dim adapter
Chapter As Real-World
17 - Building SqlDataAdapter = New SqlDataAdapter(SQL, conn)
Web Applications
Dim ds
Chapter 18 As DataSet = New
- Object-Relational DataSet("CustOrdersDataSet")
Mapping in .NET
adapter.Fill(ds)
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
Chapter 20 - COM Interoperability and ADO.NET
Chapter 21 - Messaging
Adding, Updating, and Deleting Data through the DataSet
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Appendix A - Relational Databases: Some Basic Concepts
You add,B edit,
Appendix and delete
- Commonly Useddata
SQLinStatements
a DataSet through DataSet objects. As you know, a DataSet is a
collection of DataSet objects. The DataSet'sRows and Columns properties represent the collection of
Appendix C - ADO.NET Frequently Asked Questions
aDataSet's rows and columns, which are represented by the DataRowCollection and
Index
DataColumnCollection objects. The DataRowCollection and DataColumnCollection classes
List of Figures
provide methods to add and delete rows and columns, respectively (see Chapter 3 for more details). You
List of Tables
can add a new row to a DataTable using its NewRow method, which takes a DataRow as an argument.
List of Listings
To update a DataRow's data (through DataTable), you first get a DataRow based on the index of the
List
rowofand
Sidebars
edit its values. The Delete method of a DataRow deletes a row. Listing 4-38 adds, updates, and
deletes data of a DataSet through a DataTable and a DataRow.
Data-bound connectivity: A DataReader doesn't provide any direct data-bound connectivity, which
makes it less flexible than a DataSet. A DataSet is a versatile and flexible control, which allows
both data read and write options and provides way to add, edit, delete, and view data in data-bound
controls with little effort.
Connected state: A DataReader is always in a connected state. This means if you're using a
DataReader, there's always a connection established between the reader and the database, until
you close theApplied ADO.NET:
DataReader. Building stores
A DataSet Data-Driven
data in Solutions
a disconnected state in Extensible Markup
by Mahesh Chand and David Talbot
Language (XML) format. Once you fill data from a data source ISBN:1590590732
to a DataSet, there's no connection
Apress 2003 (928 pages)
between a DataSet and the database. A connection is established when you read or updated data
again. This text provides extensive coverage of ADO.NET technology
including ADO.NET internals, namespaces, classes, and
interfaces,
You should now have andoftakes
an idea whena to
comprehensive look at XML
use a DataReader and when to use a DataSet.
namespaces and classes, and how to integrate both with
ADO.NET.
Fetching Data Based on Wildcard Characters
Table of Contents
TheSELECT...LIKE SQL statement is useful when you want to select rows based on a wildcard string.
Applied ADO.NETBuilding
For example, Data-Driven
say you want Solutions
to get all rows of the Employees table where an employee's first name starts
Introduction
with C and ends with a. You build a SQL statement like so:
Chapter 1 - ADO.NET Basics
Chapter
Dim sql2 -as
Data Components
string in Visual*Studio
= SELECT FROM.NET
Employees WHERE FirstName LIKE 'C%a'
Chapter 3 - ADO.NET in Disconnected Environments
Chapter 4 - ADO.NET in Connected Environments
Another5 useful
Chapter example
- Handling of LIKE
ADO.NET is when you want to select all the employees whose first name contains
Events
the string
Chapter 6 gar. You can XML
- Integrating buildwith
a SELECT statement as follows:
ADO.NET
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
Chapter
Dim sql8 -as
Constraints
stringand= Data Relations
SELECT * FROM Employees WHERE FirstName LIKE '%gar%'
Chapter 9 - ADO.NET Exception Handling
Chapter 10 - Working with the ODBC .NET Data Provider
Now you can use this SELECT statement in a DataReader or DataAdapter to retrieve the data from a
Chapter 11 - Stored Procedures and Views
database.
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Chapter 13 - Developing a Custom Data Provider
Chapter 14 - Developing Database Web Applications using ASP.NET
Chapter 15 - Using ADO.NET in Xml Web Services
Chapter 16 - ASP.NET Server Controls and Data Binding
Chapter 17 - Building Real-World Web Applications
Chapter 18 - Object-Relational Mapping in .NET
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
Chapter 20 - COM Interoperability and ADO.NET
Chapter 21 - Messaging
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Appendix A - Relational Databases: Some Basic Concepts
Appendix B - Commonly Used SQL Statements
Appendix C - ADO.NET Frequently Asked Questions
Index
List of Figures
List of Tables
List of Listings
List of Sidebars
The DataView in ADO.NET:
Applied Connected Environments
Building Data-Driven Solutions
by Mahesh Chand and David Talbot ISBN:1590590732
In Chapter 3, you Apress
learned 2003
how (928
a DataView
pages) is useful to sort, filter, and view data based on different selection
criteria. You also This
saw text
howprovides
to add, edit, and delete
extensive coveragedata
of from a DataView.
ADO.NET technologyIn Chapter 3, you saw all of this in
disconnected data. Also, you created DataView objects from
including ADO.NET internals, namespaces, classes, and DataTable objects. In the following sections,
you'll see how to interfaces, and takes a objects
work with DataView comprehensive look at XML
in a connected environment. You'll also learn how to search and
sort data based on namespaces
criteria andand
howclasses, and different
to create how to integrate
views ofboth with data.
the same
ADO.NET.
You simply create a DataView from a DataTable, which can be retrieved using the Tables property of a
DataSet. The following code creates a DataView from the first table of a DataSet and binds a DataView to
Table of Contents
theDataGrid control:
Applied ADO.NETBuilding Data-Driven Solutions
Introduction
Dim dtView1
Chapter As DataView
1 - ADO.NET Basics = New DataView(ds.Tables(0))
DataGrid1.DataSource
Chapter 2
= dtView1
- Data Components in Visual Studio .NET
Chapter 3 - ADO.NET in Disconnected Environments
Chapter 4 - ADO.NET in Connected Environments
Chapter 5 - Handling ADO.NET Events
Creating
Chapter 6 Multiple
- Integrating XML Views
with ADO.NET
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
The main features of a DataView is that it's easily bound to controls, and it provides filter and sort properties,
Chapter 8 - Constraints and Data Relations
which allow you to create different views of the same data. To see how to use DataViews, let's create a
Chapter 9 - ADO.NET Exception Handling
Windows application. After creating a Windows application, you'll add two DataGrid controls, four TextBox
Chapter 10 - Working with the ODBC .NET Data Provider
controls, two CheckBox controls, and a Button control and arrange them as shown in Figure 4-7. The Load
Chapter 11 - Stored Procedures and Views
Data button loads data from the Northwind SQL Server database's Orders table.
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Chapter 13 - Developing a Custom Data Provider
Chapter 14 - Developing Database Web Applications using ASP.NET
Chapter 15 - Using ADO.NET in Xml Web Services
Chapter 16 - ASP.NET Server Controls and Data Binding
Chapter 17 - Building Real-World Web Applications
Chapter 18 - Object-Relational Mapping in .NET
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
Chapter 20 - COM Interoperability and ADO.NET
Chapter 21 - Messaging
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Appendix A - Relational Databases: Some Basic Concepts
Appendix B - Commonly Used SQL Statements
Appendix C - ADO.NET Frequently Asked Questions
IndexFigure 4-7: Default multiple views application
List of Figures
Now,
List if you enter the filter and sort criteria from both DataGrid controls, the data is filtered and sorted based
of Tables
on of
List theListings
criteria. For example, Figure 4-8 shows the criteria and the result of clicking the Load Data button.
List of Sidebars
Applied ADO.NET: Building Data-Driven Solutions
by Mahesh Chand and David Talbot ISBN:1590590732
Apress 2003 (928 pages)
This text provides extensive coverage of ADO.NET technology
including ADO.NET internals, namespaces, classes, and
interfaces, and takes a comprehensive look at XML
namespaces and classes, and how to integrate both with
ADO.NET.
Table of Contents
Applied ADO.NETBuilding Data-Driven Solutions
Introduction
Chapter 1 - 4-8:
Figure ADO.NET Basics
Multiple views with different filter and sorting criteria
Chapter 2 - Data Components in Visual Studio .NET
Chapter 3 - ADO.NET in Disconnected Environments
Now let's examine the code. Listing 4-41 shows the private members.
Chapter 4 - ADO.NET in Connected Environments
Chapter
Listing54-41:
- Handling
PrivateADO.NET
MembersEvents
Chapter 6 - Integrating XML with ADO.NET
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
Private ConnectionString As String = "Integrated Security=SSPI;" & _
Chapter 8 - Constraints and Data Relations
"Initial Catalog=Northwind;Data Source=MCB;"
Chapter 9 - ADO.NET Exception Handling
Private conn As SqlConnection
Chapter 10 - Working with the ODBC .NET Data Provider
Private SQL As String = _
Chapter 11 - Stored
"SELECT Procedures and
EmployeeID, Views
CustomerID, ShipCity, ShipName FROM Orders"
Chapter 12 - Oracle, SQLXML, and Other
Private adapter As SqlDataAdapter .NET Data Providers
Chapter
Dim13ds- Developing
As DataSet a Custom
= NewData Provider
DataSet()
Chapter 14 - Developing Database Web Applications using ASP.NET
Chapter 15 - Using ADO.NET in Xml Web Services
Chapter 16 - ASP.NET Server Controls and Data Binding
Listing 17
Chapter 4-42 shows the
- Building code of Web
Real-World the Load Data button's click event handler. As you can see, the code creates two
Applications
different
Chapter 18 DataView objects from
- Object-Relational the DataSet
Mapping in .NET and sets their RowFilter and Sort properties based on the
data entered
Chapter on theObjects:
19 - Mapped form. In Performance
the end, youConsiderations
bind each DataView
and Dataobject to a separate DataGrid control.
Binding
Chapter 20 - COM Interoperability and ADO.NET
Listing 4-42: The Load Data Button's Click Event Handler
Chapter 21 - Messaging
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Private
Appendix A -Sub LoadDataBtn_Click(ByVal
Relational sender As System.Object, _
Databases: Some Basic Concepts
ByVal e As System.EventArgs) Handles LoadDataBtn.Click
Appendix B - Commonly Used SQL Statements
conn = New SqlConnection(ConnectionString)
Appendix C - ADO.NET Frequently Asked Questions
Try
Index
conn.Open()
List of Figures
adapter = New SqlDataAdapter(SQL, conn)
List of Tables
adapter.Fill(ds)
List of Listings
Catch exp As SqlException
List of Sidebars
exp.Message.ToString()
End Try
Nested transactions are transactions within the scope an existing transaction. The changes made within the
nested transactions are invisible to the top-level transactions until the nested transactions are committed.
To create nested transactions, you call BeginTransaction with CommitTransaction and Rollback-
Transaction within the existing transactions. For example:
Begin Transaction A
Begin Transaction B
Do something
Applied
Commit ADO.NET: Building
Transaction B Data-Driven Solutions
by Mahesh Chand
Commit Transaction A and David Talbot ISBN:1590590732
Apress 2003 (928 pages)
This text provides extensive coverage of ADO.NET technology
Savepoints areincluding
useful ADO.NET internals,
when you're workingnamespaces,
with nestedclasses, and
transactions. There are occasions when you want to
interfaces,
abort a portion and takes
of transaction, but anot
comprehensive look at XML
all of it. For example, say you're processing four commands as nested
namespaces and classes, and how to integrate both with
transactions, ADO.NET.
but you want to commit only two commands and abort two of them. A savepoint is a
temporary point in the transaction that you want to save (or back up) without aborting the entire transaction.
In transaction processing, you set the savepoint call and come back later when you think it's safe to process
Table the
of Contents
transaction. A unique number represents the savepoint. For example:
Applied ADO.NETBuilding Data-Driven Solutions
Introduction
Begin Transaction A
Chapter 1 -DoADO.NET Basics
something
Chapter 2 - Data SetSavePoint
Components in Visual Studio .NET
Chapter 3 - ADO.NET in Disconnected Environments
Do something
Commit
Chapter or Rollback
4 - ADO.NET Transaction
in Connected EnvironmentsA
Chapter 5 - Handling ADO.NET Events
Chapter 6 - Integrating XML with ADO.NET
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
Managing and writing reliable and scalable multitier distributed applications is one of the most challenging
Chapter 8 - Constraints and Data Relations
jobs for database developers. Think about multiple clients accessing same server database
Chapter 9 - ADO.NET Exception Handling
simultaneously-some of them are accessing data, some of them are updating the same data, and some of
Chapter 10 - Working with the ODBC .NET Data Provider
them are trying to delete the same data that other clients are using in their operations.
Chapter 11 - Stored Procedures and Views
To 12
Chapter prevent dataSQLXML,
- Oracle, inconsistency, it's .NET
and Other important to provide some kind of mechanism so other users can't
Data Providers
update
Chapter 13 - data when a user
Developing is already
Custom using that data. The mechanism to deal with this situation is called
Data Provider
concurrency
Chapter control.
14 - Developing Concurrency
Database is the method
Web Applications usingbyASP.NET
which multiple clients can access and update the same
data
Chapter 15simultaneously without
- Using ADO.NET in Xmlbeing concerned that they're forcing data redundancy and inconsistency.
Web Services
Chapter 16 - ASP.NET Server Controls and Data Binding
There are three common ways to manage concurrency:
Chapter 17 - Building Real-World Web Applications
Chapter 18 - Object-Relational Mapping in .NET
Pessimistic concurrency control: In pessimistic concurrency, the data is unavailable to other users
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
from the time the record is fetched by a user until it's updated in the database. This is useful when
Chapter 20users
- COM Interoperability
accessing andgoing
a row are ADO.NET
to play a major role based on the data they're accessing. Another
Chapter 21advantage
- Messagingof pessimistic concurrency is less locking overhead. Once a row is locked, it's locked until
Chapter 22the
- SQL
first Server
user is and ADO.NET:
done. Notes
The main on Performance
drawback of this type of concurrency is that data is not available to
Appendix Aother
- Relational Databases: Some Basic Concepts data left his terminal, other users have to wait for him to
users. For example, if a user accessing
Appendix Brelease
- Commonly Used SQL Statements
the connection.
Appendix C - ADO.NET Frequently Asked Questions
Index
Optimistic concurrency control: In optimistic concurrency, data is available all the time except when
List of Figures
a user is updating the data. The update examines the row in the database and determines whether any
List of Tables
changes have been made. In this type of concurrency, the locks are set and held only while the
List of Listings
database is being accessed. The locks prevent other users from attempting to update records at the
List of Sidebars
same instant. If other users try to update the data that is locked by first user, the update fails.
Last in wins concurrency control: In this case of concurrency control, a row is unavailable to other
users only while the data is being updated. This is only useful when the last user's update counts. For
example, it's useful if you're keeping track of the last winner of a race. In other words, many users are
updating the same data, and the person who updates it last is the latest data. The data updated by
other users will be lost. In this case, data could easily lead to inconsistencies because of network
slowness when data previously posted arrives last.
Even though the ADO.NET model supports optimistic concurrency by default, that doesn't mean you can't
implement pessimistic concurrency in ADO.NET. The following two examples show you how to handle both
cases.
Listing 4-43 shows you how to implement optimistic concurrency. You can handle the optimistic concurrency by
creating an Update command that checks the database to make sure the original data of the database row
hasn't changed when an immediate Update is about to be performed. It does this by creating two sets of
parameters for the Update command: a current set of parameters and an original set of parameters. The
original parameters maintain the data that was originally read in from the DataSet. If the data has changed in
Applied
the data source, when youADO.NET: Building
run the Update Data-Driven
command Solutions
with the WHERE clause filter, the filter won't find the row
by Mahesh Chand and David Talbot
and an Update won't occur. If the data has not changed in theISBN:1590590732
data source, then the WHERE clause will find the
Apress
original row you're 2003and
updating, (928the
pages)
row will be updated with the new data. Listing 4-43 has a built-in WHERE
This text
clause on the original provides
data. The IDE extensive coverage
generates of ADO.NET
parameters technology
such as @ShipCity and @ShipDate. The
including ADO.NET internals, namespaces,
framework even generates the Update command (which has been classes, and
shortened in the example).
interfaces, and takes a comprehensive look at XML
namespaces and classes, and how to integrate both with
Listing 4-43: Optimistic
ADO.NET.Concurrency
Try
conn.Open()
tran = conn.BeginTransaction("Transaction1")
Dim cmd As SqlCommand = New SqlCommand(_
"INSERT INTO Customers (CustomerID, ContactName, CompanyName)" & _
"VALUES (516, 'Tim Howard', 'FireCon')", conn, tran)
' Call Save method
tran.Save("save1")
cmd.ExecuteNonQuery()
MessageBox.Show("Tim is in the Database")
cmd.CommandText = _
"INSERT INTO Customers (CustomerID, ContactName, CompanyName)" & _
"VALUESApplied
(517,ADO.NET:
'Bob Hope',Building Data-Driven Solutions
'Hollywood')"
by Mahesh
' Call Save again Chand and David Talbot ISBN:1590590732
Apress
tran.Save("save2") 2003 (928 pages)
This text provides extensive coverage of ADO.NET technology
cmd.ExecuteNonQuery()
including ADO.NET internals,
MessageBox.Show("Bob is in namespaces, classes, and
the Database")
interfaces, and takes a comprehensive look at XML
cmd.CommandText
namespaces and = _ classes, and how to integrate both with
"INSERTADO.NET.
INTO Customers(CustomerID, ContactName, CompanyName)" & _
"VALUES (518, 'Fred Astaire', 'Hollywood')"
MessageBox.Show("Fred is in the Database")
Table of Contents
' Save
Applied ADO.NETBuilding
tran.Save("save3")Data-Driven Solutions
Introduction
cmd.ExecuteNonQuery()
Chapter 1 ' -rollback
ADO.NET Basics
Chapter 2 tran.Rollback("save2")
- Data Components in Visual Studio .NET
Chapter 3 ' -Commit
ADO.NET the transaction
in Disconnected Environments
Chapter 4 tran.Commit()
- ADO.NET in Connected Environments
Chapter 5 MessageBox.Show("Transaction
- Handling ADO.NET Events Rolledback, only Tim Made it.")
Chapter 6 conn.Close()
- Integrating XML with ADO.NET
Chapter 7 conn.Dispose()
- Data Binding and Windows Forms Data-Bound Controls
Catch exp As Exception
Chapter 8 - Constraints and Data Relations
If tran Is Nothing Then
Chapter 9 - ADO.NET Exception Handling
tran.Rollback()
Chapter 10 - Working with the ODBC .NET Data Provider
End If
Chapter 11 - Stored Procedures and Views
MessageBox.Show(exp.Message.ToString() & _
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
"Transaction Rolledback, Tim didn't make it.")
ChapterFinally
13 - Developing a Custom Data Provider
Chapter 14 - Developing Database Web Applications using ASP.NET
conn.Close()
Chapter 15 - Using ADO.NET in Xml Web Services
conn.Dispose()
ChapterEnd
16 -Try
ASP.NET Server Controls and Data Binding
Chapter 17 - Building Real-World Web Applications
Chapter 18 - Object-Relational Mapping in .NET
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
Now that
Chapter 20 the transaction
- COM is tied to
Interoperability theADO.NET
and Command object, you'll save the initial savepoint to the transaction and
then execute
Chapter the first insertion into the database. After that you assign a new SQL Insert to the Command text
21 - Messaging
and save the current transaction savepoint before executing the query. This Insert puts Bob Hope into the
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
database.
Appendix A - Relational Databases: Some Basic Concepts
Appendix B - Commonly
Finally, you Used
assign a new SQLInsert
SQL Statements
to the Command text and save the current transaction savepoint before
Appendix
executingC -the
ADO.NET Frequently
query. This InsertAsked
putsQuestions
Fred into the database.
Index
By of
List rolling back to the second savepoint, it's as if the second and third ExecuteNonQuery calls never
Figures
happened,
List of Tables so the first ExecuteNonQuery that puts Tim in the database is the only one that actually gets
committed.
List of ListingsIf there's an exception, then you can roll back the whole transaction.
List of Sidebars
Executing Batches
Another common concern for developers is the question of how to execute multiple INSERT statements in a
batch. Again, using transactions, you can execute multiple queries in a batch and save or roll back changes
based on some condition. For example, Listing 4-46 shows you how to execute multiple SQL queries.
Table of Contents
Applied ADO.NETBuilding Data-Driven Solutions
Introduction
Chapter 1 - ADO.NET Basics
Chapter 2 - Data Components in Visual Studio .NET
Chapter 3 - ADO.NET in Disconnected Environments
Chapter 4 - ADO.NET in Connected Environments
Chapter 5 - Handling ADO.NET Events
Chapter 6 - Integrating XML with ADO.NET
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
Chapter 8 - Constraints and Data Relations
Chapter 9 - ADO.NET Exception Handling
Chapter 10 - Working with the ODBC .NET Data Provider
Chapter 11 - Stored Procedures and Views
Chapter 12 - 5-1:
Figure Oracle, SQLXML,
Event andand
handler Other .NET
event Data Providers
argument classes defined in the System.Data namespace
Chapter 13 - Developing a Custom Data Provider
Chapter 14 - Developing Database Web Applications using ASP.NET
Note
Chapter 15 ADO.NET data providers
- Using ADO.NET areServices
in Xml Web derived from a common hierarchy, so all data providers support
the same set of events.
Chapter 16 - ASP.NET Server Controls and Data Binding
Chapter 17 - Building Real-World Web Applications
DataColumnChangeEventHandler is an event handler for DataColumn when a value is being
Chapter
changed18for
- Object-Relational Mapping in
a column in a DataRow. .NET
DataRowChangeEventHandler is an event handler that handles
Chapter 19 - MappedRowChanged,
theRowChanging, Objects: Performance Considerations
RowDeleting, and Data Binding
and RowDeleted events of a DataTable. The
Chapter 20 - COM Interoperability
FillErrorEventHandler andevent
is an ADO.NET
handler that handles a DataAdapter'sFill event. If an error
occurred
Chapter 21 during the fill operation, the FillError fires, which executes FillErrorEventHandler.
- Messaging
MergeFailedEventHandler
Chapter handles
22 - SQL Server and ADO.NET: theonDataSet's
Notes MergeFailed event that occurs when a
Performance
DataSet
Appendix A -merge operation
Relational fails. Whenever
Databases: Some BasicaConcepts
connection's state changes, the StateChange event
occurs.StateChangeEventHandler
Appendix handles this event.
B - Commonly Used SQL Statements
Appendix C - ADO.NET Frequently Asked Questions
Besides the event handler and event argument classes defined in the System.Data namespace, the
Index
data provider event handler and event argument classes are defined in the data provider-specific
List of Figures
namespace.Figure 5-2 shows the OleDb data provider event handlers and event argument classes.
List of Tables
List of Listings
List of Sidebars
Figure 5-2: OleDb data provider event handler and event arguments
Applied ADO.NET: Building Data-Driven Solutions
by Mahesh Chand and David
OleDbInfoMessageEventHandler Talbot
handles the InfoMessage event of the OleDbConnection. An
ISBN:1590590732
Apress
InfoMessage event occurs
2003when a provider sends a warning or an informational message to the
(928 pages)
application. This text provides extensive coverage of ADO.NET technology
including ADO.NET internals, namespaces, classes, and
TheRowUpdatedinterfaces, and takes
event occurs when aan
comprehensive
Update method look is
atcalled
XML on a DataAdapter.
namespaces and classes,
OleDbRowUpdatedEventHandler and how
handles the to integrate both
RowUpdated with of the OleDbDataAdapter. Apart
event
ADO.NET.
from the RowUpdated event, there's one more update-related event: RowUpdating. As you can guess
from its name, this event occurs when a row is being updated, which means before the command is
executed
Table against a data source. OleDbRowUpdatingEventHandler is responsible for handling this
of Contents
event.
Applied ADO.NETBuilding Data-Driven Solutions
Introduction
In this chapter, you'll use the Sql data provider.
Chapter 1 - ADO.NET Basics
Chapter 2 - Data Components in Visual Studio .NET
Chapter 3 - ADO.NET in Disconnected Environments
Chapter 4 - ADO.NET in Connected Environments
Chapter 5 - Handling ADO.NET Events
Chapter 6 - Integrating XML with ADO.NET
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
Chapter 8 - Constraints and Data Relations
Chapter 9 - ADO.NET Exception Handling
Chapter 10 - Working with the ODBC .NET Data Provider
Chapter 11 - Stored Procedures and Views
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Chapter 13 - Developing a Custom Data Provider
Chapter 14 - Developing Database Web Applications using ASP.NET
Chapter 15 - Using ADO.NET in Xml Web Services
Chapter 16 - ASP.NET Server Controls and Data Binding
Chapter 17 - Building Real-World Web Applications
Chapter 18 - Object-Relational Mapping in .NET
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
Chapter 20 - COM Interoperability and ADO.NET
Chapter 21 - Messaging
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Appendix A - Relational Databases: Some Basic Concepts
Appendix B - Commonly Used SQL Statements
Appendix C - ADO.NET Frequently Asked Questions
Index
List of Figures
List of Tables
List of Listings
List of Sidebars
Working with Connection
Applied Events
ADO.NET: Building Data-Driven Solutions
by Mahesh Chand and David Talbot ISBN:1590590732
TheConnectionApressobject has
2003 two
(928 events
pages) that notify the application if a connection state changes. You can
use these eventsThis
to retrieve informational
text provides extensive messages
coverage from a data source
of ADO.NET or to determine if the state of a
technology
Connection has changed. These two events are InfoMessage
including ADO.NET internals, namespaces, classes, and and StateChange. The
InfoMessage eventinterfaces,
occursand
whentakesanainformational
comprehensive look at XML
message is returned from a data source. The
namespaces
exception handling and these
doesn't catch classes, and how toThe
messages. integrate both with event occurs only when the state
StateChange
ADO.NET.
of a connection changes.
As you can see from the definition of StateChangeEventHandler, this handler has a second argument
calledStateChangeEventArgs. You can use StateChangeEventArgs to determine the change in
state of the Connection using the OriginalState and CurrentState properties. The
OriginalState property represents the original state of the Connection, and the CurrentState
property represents the current state of the connection. The ConnectionState enumeration defines
members for connection states (see Table 5-2).
Similarly to the RowUpdated event, the RowUpdating event handler receives an argument of type
SqlRowUpdatedEventArgs that defines the same properties as the SqlRowUpdated with the same
Applied ADO.NET: Building Data-Driven Solutions
meaning.
by Mahesh Chand and David Talbot ISBN:1590590732
To test the DataAdapter events
Apress 2003 and event handlers, create a Windows application, add a Button
(928 pages)
control to the form, and
This textchange itsextensive
provides name to DataAdapterEventsTestBtn.
coverage of ADO.NET technology Also add a
SqlDataAdapter including ADO.NET
by dragging theinternals, namespaces,
SqlDataAdapter classes,
from and
the Toolbox Data tab to the form and
interfaces, and
configure the DataAdapter takes
using a comprehensive
the look at XML Wizard. Select the CompanyName,
Data Adapter Configuration
namespaces and classes, and how to integrate both with
ContactName, and CustomerID columns from the Customers table. The final SELECT statement looks
ADO.NET.
like the following:
Table of Contents
SELECT CustomerID, CompanyName, ContactName FROM Customers
Applied ADO.NETBuilding Data-Driven Solutions
Introduction
Chapter 1 - ADO.NET Basics
Note
Chapter 2 See Chapter
- Data 2 for more
Components details
in Visual about
Studio the Data Adapter Configuration Wizard.
.NET
Chapter 3 - ADO.NET in Disconnected Environments
Now add all three FillError,RowUpdating, and RowUpdated event handlers manually. Listing 5-3
Chapter 4 - ADO.NET in Connected Environments
defines the event handler bodies for these three methods.
Chapter 5 - Handling ADO.NET Events
Chapter
Listing65-3:
- Integrating XML with ADO.NET
SqlDataAdapter Event Handler Bodies
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
Chapter 8 - Constraints and Data Relations
'FillError event handler
Chapter 9 - ADO.NET Exception Handling
Private Shared Sub FillError(ByVal sender As Object, _
Chapter
ByVal -args
10 Working
Aswith the ODBC .NET Data Provider
FillErrorEventArgs)
Chapter 11 - Stored Procedures and Views
Chapter
End12Sub
- Oracle, SQLXML, and Other .NET Data Providers
Chapter 13 - Developing a Custom Data Provider
Chapter 14 - Developing
'RowUpdating Database
event Web Applications using ASP.NET
handler
Chapter 15 - UsingShared
Protected ADO.NETSub
in Xml Web Services
OnRowUpdating(ByVal sender As Object, _
ByVal
Chapter 16 -eASP.NET
As SqlRowUpdatingEventArgs)
Server Controls and Data Binding
Chapter 17 - Building Real-World Web Applications
End18Sub
Chapter - Object-Relational Mapping in .NET
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
'RowUpdated
Chapter event handler
20 - COM Interoperability and ADO.NET
Protected Shared Sub OnRowUpdated(ByVal sender As Object, _
Chapter 21 - Messaging
ByVal e As SqlRowUpdatedEventArgs)
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Appendix A - Relational Databases: Some Basic Concepts
End Sub
Appendix B - Commonly Used SQL Statements
Appendix C - ADO.NET Frequently Asked Questions
Index
List
Now of you
Figures
need to write code on these event handlers. Listing 5-4 shows the source code for the
List of Tables
FillError event. You can also use other members of EventArgs to get more details. This event
handler
List will execute when an error occurs during the Fill method.
of Listings
List of Sidebars
Listing 5-4: DataAdapter FillError Event Handler Code
As you can see from Listing 5-6, you can compare the StatementType member of
OleDbRowUpdatingEventArgs to the StatementType enumeration to find out the statement type.
TheStatementType enumeration defines Select,Insert,Update, and Delete members.
To test these events you can write code that fills a DataSet and calls the Update method of the
DataAdapter. You add an event handler for the button by double-clicking it and writing the code in
Applied
Listing 5-7. As you ADO.NET:
can see, you call Building Data-Driven
AddHandler Solutions
and RemoveHandler.
by Mahesh Chand and David Talbot ISBN:1590590732
Apress
Listing 5-7: Calling theDataAdapter's
2003 (928 pages) Fill and Update Methods
This text provides extensive coverage of ADO.NET technology
including ADO.NET internals, namespaces, classes, and
Private Sub DataAdapterEventsTestBtn_Click(ByVal
interfaces, and takes a comprehensive look at XML sender As System.Object, _
ByVal e As namespaces
System.EventArgs) Handles
and classes, and DataAdapterEventsTestBtn.Click
how to integrate both with
' Create ADO.NET.
InsertCommand
SqlDataAdapter1.InsertCommand = New SqlCommand _
("INSERT INTO Customers (CustomerID, CompanyName)" & _
Table of Contents
"VALUES(@CustomerID, @CompanyName)", SqlConnection1)
Applied ADO.NETBuilding Data-Driven Solutions
SqlDataAdapter1.InsertCommand.Parameters.Add("@CustomerID", _
Introduction
SqlDbType.VarChar, 5, "CustomerID")
ChapterSqlDataAdapter1.InsertCommand.Parameters.Add("@CompanyName",
1 - ADO.NET Basics _
ChapterSqlDbType.VarChar,
2 - Data Components in Visual Studio .NET
30, "CompanyName")
Chapter'3 Opening
- ADO.NET in Disconnected Environments
Connection
ChapterSqlConnection1.Open()
4 - ADO.NET in Connected Environments
Chapter'5 Create
- Handling
andADO.NET
Fill Events
DataSet
ChapterDim
6 -custDS
Integrating
AsXML with ADO.NET
DataSet = New DataSet()
ChapterSqlDataAdapter1.Fill(custDS, "Customers")
7 - Data Binding and Windows Forms Data-Bound Controls
' add handlers
Chapter 8 - Constraints and Data Relations
ChapterAddHandler
9 - ADO.NET SqlDataAdapter1.RowUpdating,
Exception Handling AddressOf OnRowUpdating
AddHandler SqlDataAdapter1.RowUpdated,
Chapter 10 - Working with the ODBC .NET Data Provider AddressOf OnRowUpdated
' Add a new data row and
Chapter 11 - Stored Procedures and Views call Update method
' of data adapter
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Dim custRow As DataRow = custDS.Tables("Customers").NewRow()
Chapter 13 - Developing a Custom Data Provider
custRow("CustomerID") = "NEWCO"
Chapter 14 - Developing Database Web Applications using ASP.NET
custRow("CompanyName") = "New Company"
Chapter 15 - Using ADO.NET in Xml Web Services
custDS.Tables("Customers").Rows.Add(custRow)
Chapter 16 - ASP.NET Server Controls and Data Binding
SqlDataAdapter1.Update(custDS, "Customers")
ChapterRemoveHandler
17 - Building Real-World Web Applications
SqlDataAdapter1.RowUpdating, AddressOf OnRowUpdating
ChapterRemoveHandler
18 - Object-Relational Mapping in .NET
SqlDataAdapter1.RowUpdated, AddressOf OnRowUpdated
Chapter'19 - Mapped
Close theObjects: Performance Considerations and Data Binding
connection
ChapterSqlConnection1.Close()
20 - COM Interoperability and ADO.NET
ChapterSqlConnection1.Dispose()
21 - Messaging
Chapter
End22Sub- SQL Server and ADO.NET: Notes on Performance
Appendix A - Relational Databases: Some Basic Concepts
Appendix B - Commonly Used SQL Statements
Appendix C - ADO.NET Frequently Asked Questions
You can also use SelectCommand,UpdateCommand, and DeleteCommand objects to select, update,
Index
and delete data from the table. See the "The Command: Executing SQL Statements" section of Chapter 4
List of Figures
for more on using commands.
List of Tables
List
Now of if
Listings
you run the application, you'll see the insert message; if you click the button more than once, you'll
List
getofthe
Sidebars
following error message: "Violation of PRIMARY KEY constraint 'PK_Customers.' Cannot insert
duplicate key in object 'Customers.'"
Working with DataSet
Applied Events
ADO.NET: Building Data-Driven Solutions
by Mahesh Chand and David Talbot ISBN:1590590732
ADataSet has aApress
MergeFailed event that occurs when merging two DataSets fails.
2003 (928 pages)
MergeFailedEventHandler handles
This text provides extensivethecoverage
MergeFailed event,
of ADO.NET which receives an argument of type
technology
including ADO.NET internals, namespaces, classes, and MergeFailedEventHandler is
MergeFailedEventArgs containing data related to this event. The
interfaces, and takes a comprehensive look at XML
defined as follows:
namespaces and classes, and how to integrate both with
ADO.NET.
Public Delegate Sub MergeFailedEventHandler(_
ByVal sender As Object, _
Table ByVal
of Contents
e As MergeFailedEventArgs _
Applied
) ADO.NETBuilding Data-Driven Solutions
Introduction
Chapter 1 - ADO.NET Basics
In this example, sender is the source of the event, and e is the MergeFailedEventArgs object that
Chapter 2 - Data Components in Visual Studio .NET
contains the event data.
Chapter 3 - ADO.NET in Disconnected Environments
Chapter 4 - ADO.NET in Connected
MergeFailedEventArgs Environments
has Conflict and Table properties. The Conflict property returns a
Chapter 5 - Handling ADO.NET Events
description of the merge conflict, and the Table property returns the name of the data table. Listing 5-8
Chapter 6 example
shows an - Integrating XML
of the with ADO.NET event handler.
MergeFailed
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
Listing85-8:
Chapter Writing Code
- Constraints to Call
and Data MergeFailed Event Handler
Relations
Chapter 9 - ADO.NET Exception Handling
Chapter
ByVal10e -As
Working with the ODBC .NET Data
System.EventArgs) Provider
Handles MergetFailedEventBtn.Click
ChapterDim
11 -ConnectionString
Stored Procedures and Views
As String = "Integrated Security=SSPI;" & _
Chapter"Initial
12 - Oracle,Catalog=Northwind;Data
SQLXML, and Other .NET Data Providers
Source=MCB;"
ChapterDim
13 -conn As SqlConnection
Developing = New SqlConnection()
a Custom Data Provider
Chapterconn.ConnectionString
14 - Developing Database Web=Applications
ConnectionString
using ASP.NET
ChapterDim
15 -sql
UsingAs String
ADO.NET = "SELECT
in Xml * FROM Employees"
Web Services
ChapterDim
16 -da As SqlDataAdapter
ASP.NET Server Controls and = New
Data SqlDataAdapter(sql, conn)
Binding
ChapterDim
17 -ds1 As Real-World
Building DataSet Web
= New DataSet()
Applications
da.Fill(ds1)
Chapter 18 - Object-Relational Mapping in .NET
sql = "SELECT * FROM Customers"
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
da = New SqlDataAdapter(sql, conn)
Chapter 20 - COM Interoperability and ADO.NET
Dim ds2 As DataSet = New DataSet()
Chapter 21 - Messaging
da.Fill(ds2)
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
' Add MergeFailed Event handler
Appendix A - Relationalds1.MergeFailed,
AddHandler Databases: Some Basic New
Concepts
MergeFailedEventHandler _
Appendix B - Commonly
(AddressOf Used SQL Statements
DataSetMergeFailed)
Appendix C - ADO.NET Frequently Asked Questions
ds1.Merge(ds2)
Index 'Remove the MergeFailed handler
List of Figures
RemoveHandler ds1.MergeFailed, AddressOf DataSetMergeFailed
List of Tables
conn.Close()
conn.Dispose()
List of Listings
End
List of Sub
Sidebars
' MergeFailed event handler
Private Shared Sub DataSetMergeFailed(ByVal sender As Object, _
ByVal args As MergeFailedEventArgs)
MessageBox.Show("Merge failed for table " & args.Table.TableName & _
"Conflict = " & args.Conflict)
End Sub
As you can see from Listing 5-8, you write an event handler that will be called when a Merge method on a
DataSet fails.
Applied ADO.NET: Building Data-Driven Solutions
by Mahesh Chand and David Talbot ISBN:1590590732
Apress 2003 (928 pages)
This text provides extensive coverage of ADO.NET technology
including ADO.NET internals, namespaces, classes, and
interfaces, and takes a comprehensive look at XML
namespaces and classes, and how to integrate both with
ADO.NET.
Table of Contents
Applied ADO.NETBuilding Data-Driven Solutions
Introduction
Chapter 1 - ADO.NET Basics
Chapter 2 - Data Components in Visual Studio .NET
Chapter 3 - ADO.NET in Disconnected Environments
Chapter 4 - ADO.NET in Connected Environments
Chapter 5 - Handling ADO.NET Events
Chapter 6 - Integrating XML with ADO.NET
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
Chapter 8 - Constraints and Data Relations
Chapter 9 - ADO.NET Exception Handling
Chapter 10 - Working with the ODBC .NET Data Provider
Chapter 11 - Stored Procedures and Views
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Chapter 13 - Developing a Custom Data Provider
Chapter 14 - Developing Database Web Applications using ASP.NET
Chapter 15 - Using ADO.NET in Xml Web Services
Chapter 16 - ASP.NET Server Controls and Data Binding
Chapter 17 - Building Real-World Web Applications
Chapter 18 - Object-Relational Mapping in .NET
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
Chapter 20 - COM Interoperability and ADO.NET
Chapter 21 - Messaging
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Appendix A - Relational Databases: Some Basic Concepts
Appendix B - Commonly Used SQL Statements
Appendix C - ADO.NET Frequently Asked Questions
Index
List of Figures
List of Tables
List of Listings
List of Sidebars
Working with DataTable
Applied Events
ADO.NET: Building Data-Driven Solutions
by Mahesh Chand and David Talbot ISBN:1590590732
ADataTable represents a table
Apress 2003 (928 of a DataSet. A DataTable provides many events that can be tracked
pages)
down by an application (see Table 5-5).
This text provides extensive coverage of ADO.NET technology
including ADO.NET internals, namespaces, classes, and
interfaces, and
Table 5-5: The DataTable takes a comprehensive look at XML
Events
namespaces and classes, and how to integrate both with
EVENT ADO.NET.
DESCRIPTION
ColumnChanged This event occurs when a value of a column has been changed.
Table of Contents
ColumnChanging
Applied This
ADO.NETBuilding event occurs
Data-Driven when a new value is being added to a column.
Solutions
Introduction
RowChanged This event occurs when value of a row in the table is changed.
Chapter 1 - ADO.NET Basics
RowChanging
Chapter 2
This event occurs when a row in a table is changing.
- Data Components in Visual Studio .NET
Chapter 3 - ADO.NET in This
RowDeleted Disconnected Environments
event occurs when a row in a table is deleted.
Chapter 4 - ADO.NET in Connected Environments
RowDeleting This event occurs when a row is being deleted.
Chapter 5 - Handling ADO.NET Events
Chapter 6 - Integrating XML with ADO.NET
Chapter 7 - Data Binding and Windows Forms
TheColumnChangedEventHandler Data-Bound
handles Controls
the ColumnChanged event and is defined as follows:
Chapter 8 - Constraints and Data Relations
Chapter 9
- ADO.NET Exception Handling
Public Delegate Sub DataColumnChangeEventHandler(_
Chapter 10 - Working
ByVal senderwith
Asthe ODBC .NET
Object, _ Data Provider
Chapter 11 - Stored
ByVal e As Procedures and Views
DataColumnChangeEventArgs _
Chapter
) 12 - Oracle, SQLXML, and Other .NET Data Providers
Chapter 13 - Developing a Custom Data Provider
Chapter 14 - Developing Database Web Applications using ASP.NET
In this example,
Chapter 15 - Usingsender is in
ADO.NET theXml
source of the event and e is DataColumnChangedEventArgs that
Web Services
contains
Chapter 16the event data.
- ASP.NET Server Controls and Data Binding
Chapter 17 - Building Real-World Web Applications
ColumnChangingEventHandler handles the ColumnChanging event and is defined as follows:
Chapter 18 - Object-Relational Mapping in .NET
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
Public Delegate Sub DataColumnChangeEventHandler(_
Chapter 20 - COM Interoperability and ADO.NET
ByVal sender As Object, _
Chapter 21 - Messaging
ByVal e As DataColumnChangeEventArgs _
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
)
Appendix A - Relational Databases: Some Basic Concepts
Appendix B - Commonly Used SQL Statements
In this example,
Appendix sender
C - ADO.NET is the source
Frequently of the event and e is DataColumnChangingEventArgs that
Asked Questions
contains the event data.
Index
List of Figures
Similar to these two event handlers, RowChangedEventHandler,RowChangingEventHandler,
List of Tables
RowDeletedEventHandler, and RowDeletedEventHandler handle the RowChanged,
List of Listings
RowChanging,RowDeleted, and RowDeleting events, respectively. Definitions of these event
List of Sidebars
handlers are similar to DataColumnChangingEventHandler and
DataColumnChangedEventHandlerexcept the EventArgs class is different.
To test these events you'll create a DataTable, add DataRows to it, and then update and delete rows
from the table.
Listing 5-9 creates a DataTable, adds three columnsid, name, and addressadds data to the table
and changes the column of the table. It also calls the ColumnChanged and ColumnChanging event
handlers. You write the code for the ColumnChanged and ColumnChanging event handlers in the
Column_changed and Column_Changing methods. You can write this code on a button click event
handler.
Listing 5-10 creates a DataTable, adds three columnsid, name, and addressadds data to the table,
and changes the column of the table. It also calls the RowChanging and RowChanged event handlers.
Listing 5-12 handles the XmlDataDocument events. The XmlDocumentBtn_Click method creates event
handlers for NodeChanged,NodeInserted, and NodeRemoved events. MyNodeChangedEvent,
MyNodeInsertedEvent, and MyNodeRemoved event handlers are executed when these events are fired.
You use LoadXml to load an XML fragment and then use the ReplaceChild and RemoveChild methods
to replace and remove document nodes.
Listing 5-12: TheApplied
XmlDataDocument Event Data-Driven
ADO.NET: Building Handling Example
Solutions
by Mahesh Chand and David Talbot ISBN:1590590732
Apress 2003 (928 pages)
Private Sub XmlDataDocumentBtn_Click(ByVal sender As System.Object, _
ByVal e As This text provides extensiveHandles
System.EventArgs) coverage of ADO.NET technology
XmlDataDocumentBtn.Click
Dim xmlDoc including ADO.NET internals,
As XmlDocument namespaces,
= New classes, and
XmlDocument()
interfaces, and takes a comprehensive look at XML
xmlDoc.LoadXml("<Record> Some Value </Record>")
namespaces and classes, and how to integrate both with
' Add event handlers
ADO.NET.
AddHandler xmlDoc.NodeChanged, AddressOf NodeChangedEvent_Handler
AddHandler xmlDoc.NodeInserted, AddressOf NodeInsertedEvent_Handler
Table of Contents
AddHandler xmlDoc.NodeRemoved, AddressOf NodeRemovedEvent_Handler
AppliedDim
ADO.NETBuilding Data-Driven Solutions
root As XmlElement = xmlDoc.DocumentElement
Introduction
Dim str As String = root.ToString()
ChapterDim
1 -xmlDocFragment
ADO.NET Basics As XmlDocumentFragment = xmlDoc.CreateDocumentFragment()
xmlDocFragment.InnerXml
Chapter 2 - Data Components in Visual Studio= _ .NET
"<Fragment><SomeData>Fragment
Chapter 3 - ADO.NET in Disconnected Environments Data</SomeData></Fragment>"
' Replace Node
Chapter 4 - ADO.NET in Connected Environments
ChapterDim
5 -rootNode As XmlElement
Handling ADO.NET Events = xmlDoc.DocumentElement
rootNode.ReplaceChild(xmlDocFragment,
Chapter 6 - Integrating XML with ADO.NET
rootNode.LastChild)
' Remove Node
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
Dim node As XmlNode = xmlDoc.LastChild
Chapter 8 - Constraints and Data Relations
xmlDoc.RemoveChild(node)
Chapter 9 - ADO.NET Exception Handling
' Remove event handlers
Chapter 10 - Working with the ODBC .NET Data Provider
RemoveHandler xmlDoc.NodeChanged, AddressOf NodeChangedEvent_Handler
ChapterRemoveHandler
11 - Stored Procedures and Views
xmlDoc.NodeInserted, AddressOf NodeInsertedEvent_Handler
ChapterRemoveHandler
12 - Oracle, SQLXML, and Other .NET Data Providers
xmlDoc.NodeRemoved, AddressOf NodeRemovedEvent_Handler
Chapter
End13Sub- Developing a Custom Data Provider
Chapter 14 - Developing Database Web Applications using ASP.NET
Chapter 15 - Using ADO.NET in Xml Web Services
Chapter 16 - ASP.NET Server Controls and Data Binding
Listing 17
Chapter 5-13 shows the
- Building NodeChangedEvent
Real-World handler. The Node property of XmlNodeChangedEventArgs
Web Applications
returns18
Chapter an-XmlNode object. Using
Object-Relational theinNode
Mapping .NET property you can get more information about a node such as its
parent 19
Chapter node, value, Objects:
- Mapped name, namespace,
Performanceand so on. (Seeand
Considerations theData
"Using the XmlNode Class" section of Chapter 6
Binding
to learn more about XmlNode.)
Chapter 20 - COM Interoperability and ADO.NET
Chapter 21 - Messaging
Listing 5-13: The NodeChanged Event Handler
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Appendix A - Relational Databases: Some Basic Concepts
' NodeChanged event handler
Appendix B - Commonly Used SQL Statements
Public Sub NodeChangedEvent_Handler(ByVal src As Object, _
Appendix C - ADO.NET Frequently Asked Questions
ByVal args As XmlNodeChangedEventArgs)
Index
MessageBox.Show("Node Changed Event Fired for node " + args.Node.Name)
List of Figures
If args.Node.Value <> Nothing Then
List of Tables
MessageBox.Show(args.Node.Value)
List of
EndListings
If
List
End of Sidebars
Sub
Similar to Listing 5-13,Listing 5-14 and Listing 5-15 show event handlers for the NodeInserted and
NodeRemoved events.
Table of Contents
' Node Removed event handler
Applied ADO.NETBuilding Data-Driven Solutions
Public Sub NodeRemovedEvent_Handler(ByVal src As Object, _
Introduction
ByVal args As XmlNodeChangedEventArgs)
Chapter 1 - ADO.NET Basics
MessageBox.Show("Node Removed Event Fired for node " + args.Node.Name)
Chapter 2 - Data Components in Visual Studio .NET
If args.Node.Value <> Nothing Then
Chapter 3 MessageBox.Show(args.Node.Value)
- ADO.NET in Disconnected Environments
ChapterEnd
4 -If ADO.NET in Connected Environments
Chapter
End SubHandling ADO.NET Events
5 -
Chapter 6 - Integrating XML with ADO.NET
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
Chapter 8 - Constraints and Data Relations
Chapter 9 - ADO.NET Exception Handling
Chapter 10 - Working with the ODBC .NET Data Provider
Chapter 11 - Stored Procedures and Views
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Chapter 13 - Developing a Custom Data Provider
Chapter 14 - Developing Database Web Applications using ASP.NET
Chapter 15 - Using ADO.NET in Xml Web Services
Chapter 16 - ASP.NET Server Controls and Data Binding
Chapter 17 - Building Real-World Web Applications
Chapter 18 - Object-Relational Mapping in .NET
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
Chapter 20 - COM Interoperability and ADO.NET
Chapter 21 - Messaging
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Appendix A - Relational Databases: Some Basic Concepts
Appendix B - Commonly Used SQL Statements
Appendix C - ADO.NET Frequently Asked Questions
Index
List of Figures
List of Tables
List of Listings
List of Sidebars
Working with DataView
Applied and DataViewManager
ADO.NET: Building Data-Driven Solutions Events
by Mahesh Chand and David Talbot ISBN:1590590732
TheDataView and DataViewManager
Apress 2003 (928 pages) objects both define a ListChanged event. The ListChanged event
occurs when a row is added to or deleted
This text provides extensivefrom a DataView
coverage or DataViewManager
of ADO.NET technology object. The
ListChangedEventHandler method handles the ListChanged
including ADO.NET internals, namespaces, classes, and event and is defined as follows:
interfaces, and takes a comprehensive look at XML
namespaces and classes, and how to integrate both with
Public Delegate Sub ListChangedEventHandler(_
ADO.NET.
ByVal sender As Object, _
ByVal e As ListChangedEventArgs _
Table
) of Contents
Applied ADO.NETBuilding Data-Driven Solutions
Introduction
In this example,
Chapter sender
1 - ADO.NET is the source of the event and e is the ListChangedEventArgs containing the event
Basics
data. 2
Chapter - Data Components in Visual Studio .NET
Chapter 3 - ADO.NET in Disconnected
TheListChangedEventArgs Environments
has the members defined in Table 5-8.
Chapter 4 - ADO.NET in Connected Environments
Chapter 5 - The
Table 5-8: Handling ADO.NET Events
ListChangedEventArgs Members
Chapter 6 - Integrating XML with ADO.NET
MEMBER
Chapter DESCRIPTION
7 - Data Binding and Windows Forms Data-Bound Controls
Chapter 8 - Constraints and Data Relations
ListChangedType Returns the way that list changed
Chapter 9 - ADO.NET Exception Handling
NewIndex
Chapter Returns
10 - Working with the ODBC the new
.NET index
Data of the item in the list
Provider
Chapter 11 - Stored Procedures
OldIndex and Views
Returns the old index of the item in the list
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Chapter
Listing 13 - Developing
5-16 shows the aOnListChanged_Handler.
Custom Data Provider
Chapter 14 - Developing Database Web Applications using ASP.NET
Listing15
Chapter 5-16: DataView
- Using ADO.NET OnListChanged Event Handler
in Xml Web Services
Chapter 16 - ASP.NET Server Controls and Data Binding
Chapter
Public 17 Sub
- Building Real-World Web Applications
OnListChanged_Handler(ByVal src As Object, _
Chapter 18 - Object-Relational
ByVal Mapping in .NET
args As System.ComponentModel.ListChangedEventArgs)
Chapter 19 - Mapped Objects: Performance Considerations
MessageBox.Show("ListChanged: Type = "and
+ Data Binding
args.ListChangedType & _
Chapter
",20OldIndex
- COM Interoperability and ADO.NET
= " + args.OldIndex & _
",21NewIndex
Chapter - Messaging= " + args.NewIndex)
End Sub
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Appendix A - Relational Databases: Some Basic Concepts
Appendix B - Commonly Used SQL Statements
Appendix C - ADO.NET Frequently Asked Questions
To test this application, you can create a Windows application and add the code in Listing 5-17 to the form load
Index
event or a button click event handler. As you can see from Listing 5-17, the code creates a DataView object,
List of Figures
adds a new row to the DataView, and then removes the first row from the DataView. The adding and
List of Tables
removing of rows is responsible for firing the OnListChanged event handler.
List of Listings
List of Sidebars
Listing 5-17: The DataView Event Handler Caller
TheXmlDataDocument class allows you to work with relational data using the DataSet object. It
provides functionality to store, retrieve, and manipulate data. The XmlDocumentType class represents
the type of document.
TheXmlDocument and XmlDataDocument classes come from XmlNode. Besides the methods
contained in XmlNode, this class implements a series of CreateXXX methods to create a document's
contents such as comments, elements, text, and so on. You can even load an XML document by using its
Load and LoadXmlApplied ADO.NET: Building Data-Driven Solutions
methods.
by Mahesh Chand and David Talbot ISBN:1590590732
Each content typeApress
of an XML
2003 document
(928 pages) has a corresponding class defined in this namespace. The
classes are XmlAttribute, XmlCDataSection,
This text provides XmlComment,
extensive coverage XmlDeclaration,XmlEntity,
of ADO.NET technology
including XmlProcessingInstruction,
XmlEntityReference, ADO.NET internals, namespaces, classes, and and XmlWhitespace. All of these
XmlText,
interfaces, and
classes are self-explanatory. Fortakes a comprehensive
example, look at XMLand XmlComment classes represent an
the XmlAttribute
namespaces and classes, and how to integrate both with
attribute and comment of a document. You'll see these classes throughout the examples in this chapter.
ADO.NET.
Note Serialization is the process of reading and writing an object to or from a persistent storage
medium such as a hard drive.
You can use the main class, XmlSerializer, with TextWriter or XmlWriter to write the data to a
document. Again, this namespace also defines many classes. The discussion of these classes is beyond
the scope of this chapter.
Using the System.Xml.XPath
Applied ADO.NET: BuildingNamespace
Data-Driven Solutions
by Mahesh Chand and David Talbot ISBN:1590590732
This namespace is pretty small in comparison to the previous three namespaces. This namespace
Apress 2003 (928 pages)
contains only four classes: XPathDocument,XPathExression,XPathNavigator, and
This text provides extensive coverage of ADO.NET technology
XPathNodeIterator.
including ADO.NET internals, namespaces, classes, and
interfaces, and takes a comprehensive look at XML
TheXPathDocument class provides fast XML document processing using the stylesheet language of
namespaces and classes, and how to integrate both with
XML: XSLT. ThisADO.NET.
class is optimized for XSLT processing and the XPath data model. The
CreateNavigator method of this class creates an instance of XPathNavigator.
TheXPathNavigator
Table of Contents class treats an XML document as a tree and provides methods to traverse
through
Applied a document as tree.
ADO.NETBuilding Its MoveXXX
Data-Driven methods let you traverse through a document.
Solutions
Introduction
Two other classes of this namespace are XPathExpression and XPathIterator.
Chapter 1 - ADO.NET Basics
XPathExpression encapsulates an XPath expression, and XPathIterator provides an iterator over
Chapter 2 - Data Components in Visual Studio .NET
the set of selected nodes.
Chapter 3 - ADO.NET in Disconnected Environments
Chapter 4 - ADO.NET in Connected Environments
Using the
Chapter 5 System.Xml.Xsl
- Handling ADO.NET Events Namespace
Chapter 6 - Integrating XML with ADO.NET
The last namespace, System.Xml.Xsl, defines functionality for XSLT transformations. It supports XSLT
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
1.0. The XsltTransform class defines functionality to transform data using an XSLT stylesheet.
Chapter 8 - Constraints and Data Relations
Chapter 9 - ADO.NET Exception Handling
Using the Document Object Model Interfaces
Chapter 10 - Working with the ODBC .NET Data Provider
Chapter 11 - Stored Procedures and Views
You can represent an XML document in a tree structure using DOM interfaces and objects.
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Chapter 13 .NET
Microsoft - Developing
providesa aCustom Data Provider
nice wrapper around these interfaces: the DOM Application Programming
Interface
Chapter 14 (API). This wrapper
- Developing Database hasWeb
a class for almost
Applications every
using interface. These classes hide all the complexity
ASP.NET
of interface
Chapter programming
15 - Using ADO.NETand provide
in Xml a high-level programming model for developers. For example, the
Web Services
.NET class
Chapter 16 - XmlDocument provides and
ASP.NET Server Controls a wrapper for the Document interface.
Data Binding
Chapter 17 - Building Real-World Web Applications
Besides the DOM, the Microsoft .NET XML API also provides corresponding classes for the XPath, XSD,
Chapter 18 - Object-Relational Mapping in .NET
and XSLT industry standards. These classes are well coupled with the .NET database models (ADO.NET)
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
to interact with databases.
Chapter 20 - COM Interoperability and ADO.NET
Chapter 21 - Messaging
Looking at the XML .NET Architecture
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Appendix A - Relational Databases: Some Basic Concepts
The XML .NET API is a nice wrapper around the XML DOM interfaces and provides a higher-level of
Appendix B - Commonly Used SQL Statements
programming over XML documents. The heart of the XML .NET architecture consists of three classes:
Appendix C - ADO.NET
XmlDocument, Frequently
XmlReader, andAsked Questions The XmlReader and XmlWriter classes are abstract
XmlWriter.
Index
base classes that provide fast, non-cached, forward-only cursors to read and write XML data.
List of Figures
XmlTextReader, XmlValidatingReader, and XmlNodeReader are concrete implementations of the
List of Tables class. The XmlWriter and XmlNodeWriter classes come from the XmlWriter class.
XmlReader
List of Listings
XmlDocument represents an XML document in a tree structure with the help of the XmlNode,
of Sidebars and XmlAttribute classes.
XmlElement,
List
Figure 6-1 shows a relationship between these classes and the XML .NET architecture.
Applied ADO.NET: Building Data-Driven Solutions
by Mahesh Chand and David Talbot ISBN:1590590732
Apress 2003 (928 pages)
This text provides extensive coverage of ADO.NET technology
including ADO.NET internals, namespaces, classes, and
interfaces, and takes a comprehensive look at XML
namespaces and classes, and how to integrate both with
ADO.NET.
Table of Contents
Applied ADO.NETBuilding Data-Driven Solutions
Figure 6-1: XML .NET architecture
Introduction
Chapter 1 - ADO.NET Basics
TheSystem.Xml.Xsl
Chapter interface
2 - Data Components provides
in Visual classes
Studio .NET that implement XSLT. The XmlTransform class
implements XSLT. This class reads and writes
Chapter 3 - ADO.NET in Disconnected Environments
XML data with the help of the XmlReader and
XmlWriter classes.
Chapter 4 - ADO.NET in Connected Environments
Chapter 5 - Handling ADO.NET
TheXPathDocument and theEvents
XPathNavigator classes provide read/write and navigation access to the
Chapter 6 - Integrating
XML documents. XML with ADO.NET
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
Associated
Chapter 8 - with these classes
Constraints are
and Data some more powerful classes for working with XML. We discuss these
Relations
classes in "Navigating in XML" and
Chapter 9 - ADO.NET Exception Handlingother sections of this chapter.
Chapter 10 - Working with the ODBC .NET Data Provider
Adding a System.Xml Namespace Reference
Chapter 11 - Stored Procedures and Views
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Before 13
Chapter using the System.Xml
- Developing a Customclasses in your application, you may need to add a reference to the
Data Provider
System.Xml.dll
Chapter assembly
14 - Developing and
Database include
Web the System.Xml
Applications namespace in your application. You can add
using ASP.NET
a reference to the System.Xml.dll assembly by selecting Project Add Reference, choosing the .NET
Chapter 15 - Using ADO.NET in Xml Web Services
tab, and selecting System.Xml.dll from the component name listing. After adding the reference, you need
Chapter 16 - ASP.NET Server Controls and Data Binding
to import the namespace by adding the following line:
Chapter 17 - Building Real-World Web Applications
Chapter 18 - Object-Relational Mapping in .NET
Imports
Chapter 19 -System.Xml
Mapped Objects: Performance Considerations and Data Binding
Chapter 20 - COM Interoperability and ADO.NET
Chapter 21 - Messaging
The abstract base classes XmlReader and XmlWriter support reading and writing XML documents in
Chapter 22 Framework.
the .NET - SQL Server and ADO.NET: Notes on Performance
Appendix A - Relational Databases: Some Basic Concepts
Appendix B - Commonly Used SQL Statements
Appendix C - ADO.NET Frequently Asked Questions
Index
List of Figures
List of Tables
List of Listings
List of Sidebars
Reading XML
Applied ADO.NET: Building Data-Driven Solutions
by Mahesh Chand and David Talbot ISBN:1590590732
As mentioned previously, (928 pages) is an abstract base class for XML reader classes. This class
XmlReader
Apress 2003
provides fast, non-cached, forward-only
This text provides extensivecursors to read
coverage XML documents.
of ADO.NET technology
including ADO.NET internals, namespaces, classes, and
TheXmlTextReader, XmlNodeReader,
interfaces, and XmlValidatingReader
and takes a comprehensive look at XML classes are defined from the
XmlReader class. Figure 6-2and
namespaces shows
classes, and
and how to
XmlReader its derived
integrate bothclasses.
with
ADO.NET.
Table of Contents
Applied ADO.NETBuilding Data-Driven Solutions
Introduction
Chapter 1 - ADO.NET Basics
Figure
Chapter 2 - 6-2:
Data XmlReader and
Components in its derived
Visual Studio classes
.NET
Chapter 3 - ADO.NET in Disconnected Environments
Chapter
You use4 the
- ADO.NET in Connected
XmlTextReader, Environments
XmlNodeReader, and XmlValidatingReader classes to read XML
Chapter 5 - Handling ADO.NET Events
documents. These classes define overloaded constructors to read XML files, strings, streams,
Chapter 6 - Integrating
TextReader XML with ADO.NETand combinations of these. After creating an instance, you simply
objects, XmlNameTable,
call the7Read
Chapter method
- Data of and
Binding the class to read
Windows theData-Bound
Forms document.Controls
The Read method starts reading the document
from the
Chapter 8 root node and and
- Constraints continues until Read returns False, which indicates there's no node left to read in
Data Relations
the document.
Chapter ListingException
9 - ADO.NET 6-1 readsHandling
an XML file and displays some information about the file. In this example,
we use10
Chapter the- books.xml
Working with file. You can
the ODBC use
.NET anyProvider
Data XML by replacing the string name.
Chapter 11 - Stored Procedures and Views
Listing 6-1: Reading an XML File
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Chapter 13 - Developing a Custom Data Provider
Dim reader
Chapter As XmlTextReader
14 - Developing = New XmlTextReader("C:\\books.xml")
Database Web Applications using ASP.NET
Console.WriteLine("General
Chapter 15 - Using ADO.NET in Xml WebInformation")
Services
Console.WriteLine("===================")
Chapter 16 - ASP.NET Server Controls and Data Binding
Console.WriteLine(reader.Name)
Chapter 17 - Building Real-World Web Applications
Console.WriteLine(reader.BaseURI)
Chapter 18 - Object-Relational Mapping in .NET
Console.WriteLine(reader.LocalName)
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
Chapter 20 - COM Interoperability and ADO.NET
Chapter 21 - Messaging
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Getting Node Information
Appendix A - Relational Databases: Some Basic Concepts
Appendix B - Commonly Used SQL Statements
TheName property returns the name of the node with the namespace prefix, and the LocalName property
Appendix C - ADO.NET Frequently Asked Questions
returns the name of the node without the prefix.
Index
List
The ofItem
Figures
property works as an indexer and returns the value of the attribute at the specified index. The
List of Tables
Value property returns the value of current node. You can even get the level of the node by using the
List property, as shown in Listing 6-2.
of Listings
Depth
List of Sidebars
Listing 6-2: Getting XML Node Information
Dim ofreader
Table As XmlTextReader = New XmlTextReader("C:\\books.xml")
Contents
AppliedWhile reader.Read()
ADO.NETBuilding Data-Driven Solutions
Console.WriteLine(reader.Name)
Introduction
reader.MoveToContent()
Chapter 1 - ADO.NET Basics
Console.WriteLine(reader.Name)
Chapter 2 - Data Components in Visual Studio .NET
End While
Chapter 3 - ADO.NET in Disconnected Environments
Chapter 4 - ADO.NET in Connected Environments
Chapter 5 - Handling ADO.NET Events
Chapter 6 - Integrating XML with ADO.NET
Using the
- DataGetAttributes
Chapter 7 Binding and Windows of a Data-Bound
Forms Node Controls
Chapter 8 - Constraints and Data Relations
TheGetAttribute method is an overloaded method. You can use this method to return attributes with
Chapter 9 - ADO.NET Exception Handling
the specified name, index, local name, or namespace Uniform Resource Indicator (URI). You use the
Chapter 10 - Working with the ODBC .NET Data Provider
HasAttributes property to check if a node has attributes, and AttributeCount returns the number
Chapter 11 - Stored Procedures and Views
of attributes on the node. The local name is the name of the current node without prefixes. For example, if
Chapter
<bk:book>12 - Oracle, SQLXML,
represents and Other
a name .NET where
of a node, Data Providers
bk is a namespace and : refers to the namespace, the
Chapter 13 - for
local name Developing a Custom element
the <bk:book> Data Provider
is book.MoveToFirstAttribute moves to the first attribute.
Chapter 14 - Developing method
TheMoveToElement Databasemoves
Web Applications usingthat
to the element ASP.NET
contains the current attribute node (see Listing
Chapter
6-5). 15 - Using ADO.NET in Xml Web Services
Chapter 16 - ASP.NET Server Controls and Data Binding
Listing17
Chapter 6-5: Using the
- Building GetAttribute
Real-World of a Node
Web Applications
Chapter 18 - Object-Relational Mapping in .NET
Chapter
Imports19 -System.Xml
Mapped Objects: Performance Considerations and Data Binding
Chapter
Module 20 Module1
- COM Interoperability and ADO.NET
Sub21Main()
Chapter - Messaging
ChapterDim
22 -reader Asand
SQL Server XmlTextReader = Performance
ADO.NET: Notes on _
New
Appendix A -XmlTextReader("C:\\books.xml")
Relational Databases: Some Basic Concepts
reader.MoveToContent()
Appendix B - Commonly Used SQL Statements
reader.MoveToFirstAttribute()
Appendix C - ADO.NET Frequently Asked Questions
Index
Console.WriteLine("First Attribute Value" + reader.Value)
Console.WriteLine("First Attribute Name" + reader.Name)
List of Figures
While reader.Read()
List of Tables
If reader.HasAttributes Then
List of Listings
Console.WriteLine(reader.Name + " Attribute")
List of Sidebars
Dim i As Integer
Dim counter As Integer = reader.AttributeCount - 1
For i = 0 To counter
reader.MoveToAttribute(i)
Console.WriteLine("Name: " + reader.Name)
Next i
reader.MoveToElement()
End If
End While
End Sub
End Module
Applied ADO.NET: Building Data-Driven Solutions
You can move toby attributes
Mahesh by using
Chand and David Talbot
MoveToAttribute, ISBN:1590590732
MoveToFirstAttribute, and
Apress 2003
MoveToNextAttribute. MoveToFirstAttribute
(928 pages) and MoveToNextAttribute move to the first
and next attributes, respectively.
This After
text provides callingcoverage
extensive MoveToAttribute, the Name,Namespace, and Prefix
of ADO.NET technology
including
properties will reflect ADO.NET internals,
the properties namespaces,
of the specified classes, and
attribute.
interfaces, and takes a comprehensive look at XML
namespaces and classes, and how to integrate both with
Searching for a Node
ADO.NET.
TheSkip method skips the current node. It's useful when you're looking for a particular node and want to
Table
skip of Contents
other nodes. In Listing 6-6, you read the books.xml document and compare its XmlReader.name
Applied ADO.NETBuilding
(throughXmlTextReader) Data-Driven
to look forSolutions
a node with the name bookstore and display the name, level, and
Introduction
value of that node using XmlReader'sName,Depth, and Value properties.
Chapter 1 - ADO.NET Basics
Listing26-6:
Chapter Using
- Data the Skip in
Components Method
Visual Studio .NET
Chapter 3 - ADO.NET in Disconnected Environments
Chapter 4 - ADO.NET in Connected Environments
New XmlTextReader("C:\\books.xml")
ChapterWhile
5 - Handling ADO.NET Events
reader.Read()
Chapter 6 ' -Look
Integrating
for XML with ADO.NET
a node with name bookstore
Chapter 7 If- Data
reader.Name <> "bookstore"
Binding and Windows Then Controls
Forms Data-Bound
Chapter 8 -reader.Skip()
Constraints and Data Relations
Else
Chapter 9 - ADO.NET Exception Handling
Chapter 10 -Console.WriteLine("Name: " + reader.Name)
Working with the ODBC .NET Data Provider
Console.WriteLine("Level
Chapter 11 - Stored Procedures and Views of the node: " + reader.Depth.ToString())
Console.WriteLine("Value: " + reader.Value)
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
End If
Chapter 13 - Developing a Custom Data Provider
End While
Chapter 14 - Developing Database Web Applications using ASP.NET
reader.Close()
Chapter 15 - Using ADO.NET in Xml Web Services
Chapter 16 - ASP.NET Server Controls and Data Binding
Chapter 17 - Building Real-World Web Applications
Chapter 18 - Object-Relational Mapping in .NET
Closing the Document
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
Chapter 20 - COM Interoperability and ADO.NET
Finally, you use Close to close the opened XML document.
Chapter 21 - Messaging
Chapter
Tables226-2- and
SQL 6-3
Server and ADO.NET:
describe Notes onclass
the XmlReader Performance
properties and methods. We already discussed some
Appendix A - Relational Databases:
of them in the previous discussion.Some Basic Concepts
Appendix B - Commonly Used SQL Statements
Table 6-2:
Appendix C - The
ADO.NET Class
Frequently
XmlReader Properties
Asked Questions
Index
List of Figures
List of Tables
List of Listings
List of Sidebars
PUBLIC INSTANCE DESCRIPTION
Applied ADO.NET: Building Data-Driven Solutions
PROPERTY by Mahesh Chand and David Talbot ISBN:1590590732
Apress 2003 (928 pages)
AttributeCount Returns the number of attributes on the current node
This text provides extensive coverage of ADO.NET technology
BaseURI including ADO.NET internals,
Returns namespaces,
the base URI of theclasses, and
current node
interfaces, and takes a comprehensive look at XML
Depth namespaces andReturns
classes,the
andlevel
howof
to the
integrate
currentboth
nodewith
ADO.NET.
EOF Indicates whether its pointer is at the end of the stream
HasAttributes
Table of Contents Indicates if a node has attributes
Applied ADO.NETBuilding Data-Driven
HasValue Solutions
Indicates if a node has a value
Introduction
IsDefault
Chapter 1 - ADO.NET Basics Indicates whether the current node is an attribute generated from
the default
Chapter 2 - Data Components in Visual Studiovalue
.NETdefined in the DTD or schema
Chapter 3 - ADO.NET in Disconnected
IsEmptyTag Environments
Returns if the current node is empty or not
Chapter 4 - ADO.NET in Connected Environments
Item
Chapter 5 - Handling ADO.NET Events
Returns the value of the attribute
Chapter 6 - Integrating XML with Name
LocalName ADO.NET
of the current node without the namespace prefix
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
Name Name of the current node with the namespace prefix
Chapter 8 - Constraints and Data Relations
Chapter 9 - ADO.NET Exception Handling
NamespaceURI Namespace Uniform Resource Name (URN) of the current
namespace
Chapter 10 - Working with the ODBC .NET Datascope
Provider
Chapter 11 - Stored Procedures and Views
NameTable Returns the XmlNameTable associated with this implementation
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
13 - Developing a CustomReturns
NodeType
Chapter the type of node
Data Provider
Chapter 14 - Developing Database Web Applications using ASP.NET
Prefix Returns the namespace associated with a node
Chapter 15 - Using ADO.NET in Xml Web Services
ReadState
Chapter Read
16 - ASP.NET Server Controls state
and Data Binding
Chapter 17 - Building Real-World Web Applications
Value Returns the text value of a node
Chapter 18 - Object-Relational Mapping in .NET
XmlLang
Chapter Returns the
19 - Mapped Objects: Performance current xml:lang
Considerations and Datascope
Binding
Chapter 20 - COM Interoperability Returns
XmlSpace and ADO.NET
the current xml:space scope
Chapter 21 - Messaging
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Appendix A - The
Table 6-3: Relational Databases:
XmlReader ClassSome Basic Concepts
Methods
Appendix B - Commonly Used SQL Statements
PUBLIC
Appendix C - INSTANCE METHODAsked Questions DESCRIPTION
ADO.NET Frequently
Index
Close Closes the stream and changes ReadState to
List of Figures Closed
List of Tables
GetAttribute
List of Listings Returns the value of an attribute
ListIsStartElement
of Sidebars Checks if a node has start tag
LookupNamespace Resolves a namespace prefix in the current
element's scope
MoveToAttribute,MoveToContent, Moves to specified attribute, content, and element
MoveToElement
MoveToFirstAttribute, Moves to the first and next attributes
MoveToNextAttribute
Read Reads a node
ReadAttributeValue Parses theSolutions
Applied ADO.NET: Building Data-Driven attribute value into one or more Text
and/or
by Mahesh Chand and David Talbot ISBN:1590590732 node types
EntityReference
Apress ReadBoolean,
ReadXXX (ReadChar, 2003 (928 pages) Reads the contents of an element into the
ReadDate,ReadInt32,provides
This text and so on)extensive coverage of ADO.NET
specified technology
type including char, integer, double,
including ADO.NET internals, namespaces, classes, and
string, date, and so on
interfaces, and takes a comprehensive look at XML
ReadInnerXmlnamespaces and classes, and howReads
to integrate
all theboth with as a string
content
ADO.NET.
Skip Skips the current element
Table of Contents
Applied ADO.NETBuilding Data-Driven Solutions
Introduction
Chapter 1 - ADO.NET Basics
Chapter 2 - Data Components in Visual Studio .NET
Chapter 3 - ADO.NET in Disconnected Environments
Chapter 4 - ADO.NET in Connected Environments
Chapter 5 - Handling ADO.NET Events
Chapter 6 - Integrating XML with ADO.NET
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
Chapter 8 - Constraints and Data Relations
Chapter 9 - ADO.NET Exception Handling
Chapter 10 - Working with the ODBC .NET Data Provider
Chapter 11 - Stored Procedures and Views
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Chapter 13 - Developing a Custom Data Provider
Chapter 14 - Developing Database Web Applications using ASP.NET
Chapter 15 - Using ADO.NET in Xml Web Services
Chapter 16 - ASP.NET Server Controls and Data Binding
Chapter 17 - Building Real-World Web Applications
Chapter 18 - Object-Relational Mapping in .NET
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
Chapter 20 - COM Interoperability and ADO.NET
Chapter 21 - Messaging
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Appendix A - Relational Databases: Some Basic Concepts
Appendix B - Commonly Used SQL Statements
Appendix C - ADO.NET Frequently Asked Questions
Index
List of Figures
List of Tables
List of Listings
List of Sidebars
Understanding
Appliedthe XmlWriter
ADO.NET: Classes Solutions
Building Data-Driven
by Mahesh Chand and David Talbot ISBN:1590590732
As you saw in theApress
"Understanding Microsoft .NET and XML" section, the XmlWriter class contains
2003 (928 pages)
methods and properties to write to XML documents,
This text provides extensive coverageand technology and XmlNodeWriter come
XmlTextWriter
of ADO.NET
from the XmlWriter class. Figure 6-3 shows XmlWriter and its
including ADO.NET internals, namespaces, classes, and derived classes.
interfaces, and takes a comprehensive look at XML
namespaces and classes, and how to integrate both with
ADO.NET.
Table of Contents
Applied ADO.NETBuilding Data-Driven Solutions
Introduction
Figure 6-3: TheXmlWriter class and its derived classes
Chapter 1 - ADO.NET Basics
Chapter 2 - Data Components in Visual Studio .NET
Besides3 providing
Chapter - ADO.NETa constructor and three
in Disconnected properties (WriteState,XmlLang, and XmlSpace), the
Environments
XmlWriter
Chapter classes in
4 - ADO.NET have many WriteXXX
Connected methods to write to XML documents. The following sections
Environments
discuss5some
Chapter of these
- Handling class methods
ADO.NET Events and properties and use them in examples of the XmlTextWriter
andXmlNodeWriter
Chapter 6 - Integrating classes.
XML withXmlTextWriter
ADO.NET creates a write object and writes to the documents. The
XmlTextWriter
Chapter constructor
7 - Data Binding can take
and Windows threeData-Bound
Forms types of inputs: a string, stream, or TextWriter.
Controls
Chapter 8 - Constraints and Data Relations
Setting- ADO.NET
Chapter 9 XmlWriter Properties
Exception Handling
Chapter 10 - Working with the ODBC .NET Data Provider
TheXmlWriter
Chapter 11 - Storedclass contains
Procedures three
and properties: WriteState,XmlLang, and XmlSpace. The
Views
WriteState
Chapter property
12 - Oracle, gets the
SQLXML, and current state
Other .NET of the
Data XmlWriter class. The values could be Attribute,
Providers
Start,Element,Content,Closed, or Prolog. The return value WriteState.Start means the
Chapter 13 - Developing a Custom Data Provider
Write method has not been called yet. In other cases, it represents what's being written. For example, the
Chapter 14 - Developing Database Web Applications using ASP.NET
return value WriteState.Attribute means the Attribute value has been written.
Chapter 15 - Using ADO.NET in Xml Web Services
WriteState.Close represents that the stream has been closed by calling Close method.
Chapter 16 - ASP.NET Server Controls and Data Binding
Chapter 17 - Building Real-World Web Applications
Writing XML Items
Chapter 18 - Object-Relational Mapping in .NET
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
As discussed earlier, an XML document can have many types of items including elements, comments,
Chapter 20 - COM Interoperability and ADO.NET
attributes, and whitespaces. Although it's not possible to describe all the WriteXXX methods here, we
Chapter 21 - Messaging
cover the most important ones.
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
TheWriteStartDocument
Appendix andSome
A - Relational Databases: Basic Concepts
WriteEndDocument methods open and close a document for writing,
respectively.
Appendix You mustUsed
B - Commonly openSQL
a document before you start writing to it. The WriteComment method writes
Statements
comments
Appendix C - to a document.
ADO.NET It takes
Frequently onlyQuestions
Asked one string type: argument. The WriteString method writes a
string to a document. With the help of WriteString, you can use the WriteStartElement and
Index
WriteEndElement
List of Figures method pair to write an element to a document. The WriteStartAttribute and
WriteEndAttribute
List of Tables pair writes an attribute. WriteNode is another write method, which writes
XmlReader to a document as a node of the document.
List of Listings
List of Sidebars
The following example summarizes these methods and creates a new XML document with some items in it
such as elements, attributes, strings, comments, and so on. (See Listing 6-7 in the next section.)
Imports System.Xml
Module Module1
Sub Main()
' Create a new file c:\xmlWriterTest.xml
Dim writer As XmlTextWriter = _
New XmlTextWriter("C:\\xmlWriterTest.xml", Nothing)
' Opens the document
writer.WriteStartDocument()
Applied ADO.NET: Building Data-Driven Solutions
' Write comments
by Mahesh Chand and David
writer.WriteComment("This Talbot uses XmlTextWriter.")
program ISBN:1590590732
Apress 2003 (928 pages)
writer.WriteComment("Developed By: Mahesh Chand.")
This text provides extensive coverage of ADO.NET technology
writer.WriteComment("================================")
includingelement
' Write first ADO.NET internals, namespaces, classes, and
interfaces, and takes a comprehensive look at XML
writer.WriteStartElement("root")
namespaces and classes, and how to integrate both with
writer.WriteStartElement("r",
ADO.NET. "RECORD", "urn:record")
' Write next element
writer.WriteStartElement("FirstName", "")
Table ofwriter.WriteString("Mahesh")
Contents
Appliedwriter.WriteEndElement()
ADO.NETBuilding Data-Driven Solutions
Introduction
' Write one more element
Chapterwriter.WriteStartElement("LastName",
1 - ADO.NET Basics "")
Chapterwriter.WriteString("Chand")
2 - Data Components in Visual Studio .NET
Chapterwriter.WriteEndElement()
3 - ADO.NET in Disconnected Environments
Chapter'4 Create an inXmlTextReader
- ADO.NET to read books.xml
Connected Environments
ChapterDim
5 -reader
Handling As XmlTextReader
ADO.NET Events = New XmlTextReader("c:\\books.xml")
ChapterWhile reader.Read()
6 - Integrating XML with ADO.NET
Chapter 7 If- Data
reader.NodeType
Binding and Windows = XmlNodeType.Element
Forms Data-Bound Controls Then
' Add node.xml to xmlWriterTest.xml
Chapter 8 - Constraints and Data Relations
usign WriteNode
writer.WriteNode(reader, True)
Chapter 9 - ADO.NET Exception Handling
End If
Chapter 10 - Working with the ODBC .NET Data Provider
End While
Chapter 11 - Stored Procedures and Views
' Ends the document.
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
writer.WriteEndDocument()
Chapterwriter.Close()
13 - Developing a Custom Data Provider
Chapter
End14Sub- Developing Database Web Applications using ASP.NET
Chapter 15
End Module - Using ADO.NET in Xml Web Services
Chapter 16 - ASP.NET Server Controls and Data Binding
Chapter 17 - Building Real-World Web Applications
Chapter 18 - Object-Relational Mapping in .NET
In this example,
Chapter youObjects:
19 - Mapped create aPerformance
new XML file,
Considerations and Data Binding using XmlTextWriter:
c:\xmlWriterText.xml,
Chapter 20 - COM Interoperability and ADO.NET
Chapter 21 - Messaging
' Create a new file c:\xmlWriterTest.xml
ChapterDim
22 -writer Asand
SQL Server XmlTextWriter = Performance
ADO.NET: Notes on _
New
Appendix A -XmlTextWriter("C:\\xmlWriterTest.xml",
Relational Databases: Some Basic Concepts Nothing)
Appendix B - Commonly Used SQL Statements
Appendix C - ADO.NET Frequently Asked Questions
After that, add comments and elements to the document using WriteXXX methods. After that you can
Index
read the books.xml file using XmlTextReader and add its elements to xmlWriterTest.xml using
List of Figures
XmlTextWriter:
List of Tables
List of Listings
' Create an XmlTextReader to read books.xml
List of Sidebars
Dim reader As XmlTextReader = New XmlTextReader("c:\\books.xml")
While reader.Read()
If reader.NodeType = XmlNodeType.Element Then
' Add node.xml to xmlWriterTest.xml usign WriteNode
writer.WriteNode(reader, True)
End If
End While
Table
<?xmlof Contents
version="1.0" ?>
Applied ADO.NETBuilding
- <!-- ThisData-Driven
programSolutions
uses XmlTextWriter.
Introduction -->
Chapter-1 <!-- Developed
- ADO.NET Basics By: Mahesh Chand.
Chapter 2 --> .NET
- Data Components in Visual Studio
- <!-- ================================
Chapter 3 - ADO.NET in Disconnected Environments
Chapter-->4 - ADO.NET in Connected Environments
Chapter-5 <root>
- Handling ADO.NET Events
- <r:RECORD xmlns:r="urn:record">
Chapter 6 - Integrating XML with ADO.NET
<FirstName>Mahesh</FirstName>
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
<LastName>Chand</LastName>
Chapter 8 - Constraints and Data Relations
- <bookstore>
Chapter 9 - ADO.NET Exception Handling
- <book genre="autobiography" publicationdate="1981" ISBN="1-861003-11-0">
Chapter 10 - Working with the ODBC .NET Data Provider
<title>The Autobiography of Benjamin Franklin</title>
Chapter-11 - Stored Procedures and Views
<author>
Chapter<first-name>Benjamin</first-name>
12 - Oracle, SQLXML, and Other .NET Data Providers
Chapter<last-name>Franklin</last-name>
13 - Developing a Custom Data Provider
Chapter</author>
14 - Developing Database Web Applications using ASP.NET
Chapter<price>8.99</price>
15 - Using ADO.NET in Xml Web Services
Chapter</book>
16 - ASP.NET Server Controls and Data Binding
Chapter-17 <book genre="novel"
- Building publicationdate="1967" ISBN="0-201-63361-2">
Real-World Web Applications
Chapter 18 - Object-Relational MappingMan</title>
<title>The Confidence in .NET
Chapter-19 <author>
- Mapped Objects: Performance Considerations and Data Binding
Chapter<first-name>Herman</first-name>
20 - COM Interoperability and ADO.NET
Chapter<last-name>Melville</last-name>
21 - Messaging
</author>
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
<price>11.99</price>
Appendix A - Relational Databases: Some Basic Concepts
</book>
Appendix B - Commonly Used SQL Statements
- <book genre="philosophy" publicationdate="1991" ISBN="1-861001-56-6">
Appendix C - ADO.NET Frequently Asked Questions
<title>The Gorgias</title>
Index
- <author>
List of Figures
<name>Plato</name>
List of Tables
</author>
List of Listings
<price>9.99</price>
List of Sidebars
</book>
</bookstore>
</r:RECORD>
</root>
Besides these three methods, the XmlConvert class has many methods to convert from a string object
Table of Contents
to Boolean, byte, integer, and so on. Listing 6-9 shows the conversion from a Boolean and DateTime
Applied ADO.NETBuilding Data-Driven Solutions
object to XML values.
Introduction
Chapter
Listing16-9:
- ADO.NET Basics
Using the XmlConvert Class
Chapter 2 - Data Components in Visual Studio .NET
Chapter 3 - ADO.NET in Disconnected Environments
Dim writer As XmlTextWriter = _
Chapter 4 - ADO.NET in Connected Environments
New XmlTextWriter("c:\\test.xml", Nothing)
Chapter 5 - Handling ADO.NET Events
writer.WriteStartElement("MyTestElements")
ChapterDim
6 -blIntegrating XML with
As Boolean = ADO.NET
True
Chapterwriter.WriteElementString("TestBoolean",
7 - Data Binding and Windows Forms Data-Bound Controls_
ChapterXmlConvert.ToString(bl))
8 - Constraints and Data Relations
ChapterDim
9 -dtADO.NET Exception Handling
As DateTime = New DateTime(2000, 1, 1)
Chapterwriter.WriteElementString("TestDate",
10 - Working with the ODBC .NET Data Provider _
ChapterXmlConvert.ToString(dt))
11 - Stored Procedures and Views
Chapterwriter.WriteEndElement()
12 - Oracle, SQLXML, and Other .NET Data Providers
writer.Flush()
Chapter 13 - Developing a Custom Data Provider
Chapterwriter.Close()
14 - Developing Database Web Applications using ASP.NET
Chapter 15 - Using ADO.NET in Xml Web Services
Chapter 16 - ASP.NET Server Controls and Data Binding
Chapter 17 - Building Real-World Web Applications
Chapter 18 - Object-Relational Mapping in .NET
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
Chapter 20 - COM Interoperability and ADO.NET
Chapter 21 - Messaging
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Appendix A - Relational Databases: Some Basic Concepts
Appendix B - Commonly Used SQL Statements
Appendix C - ADO.NET Frequently Asked Questions
Index
List of Figures
List of Tables
List of Listings
List of Sidebars
Understanding
Appliedthe DOMBuilding
ADO.NET: Implementation
Data-Driven Solutions
by Mahesh Chand and David Talbot ISBN:1590590732
Microsoft .NET supports
Apress the
2003W3C DOM Level 1 and DOM Level 2 Core specifications. The .NET
(928 pages)
Framework providesThis text provides extensivethrough
DOM implementation coverage many classes;technology
of ADO.NET XmlNode and XmlDocument are two of
them. Using these including ADO.NET internals, namespaces, classes, anddocuments in the same manner as
two classes, you can easily traverse through XML
you do in a tree. interfaces, and takes a comprehensive look at XML
namespaces and classes, and how to integrate both with
ADO.NET.
Using the XmlNode Class
Table of Contents
TheXmlNode class is an abstract base class; it represents a node of an XML document. Because an XML
document
Applied starts with a root
ADO.NETBuilding node, theSolutions
Data-Driven XmlNode class that corresponds to the root node represents the
entire XML document's nodes. An XmlNode object can represent a node at any level. This class defines
Introduction
enough1 methods
Chapter andBasics
- ADO.NET properties to represent a document node as a tree node and traverse though it. It also
provides
Chapter 2 methods to insert, replace,
- Data Components in Visualand remove
Studio .NETdocument nodes.
Chapter 3 - ADO.NET in Disconnected Environments
TheChildNodes property returns all the child nodes of the current node. You can treat an entire
Chapter 4 - ADO.NET in Connected Environments
document as a node and use ChildNodes to get all the nodes in a document. Also, you can use the
Chapter 5 - Handling ADO.NET Events
FirstChild,LastChild, and HasChildNodes triplet to traverse from a document's first node to the
Chapter 6 -The
last node. Integrating XML with
ParentNode, ADO.NET
PreviousSibling, and NextSibling properties return the parent and
Chapter 7 - Data Binding and Windows Forms
previous/next sibling nodes of the current Data-Bound
node. Controlsproperties are Attributes, BaseURI,
Other common
Chapter 8 - Constraints
InnerXml, InnerText, and DataNodeType,
Item, Relations Name, Value, and so on.
Chapter 9 - ADO.NET Exception Handling
You can
Chapter 10use the CreateNavigator
- Working with the ODBC .NETmethod of this class to create an XPathNavigator object, which
Data Provider
provides
Chapter 11fast navigation
- Stored using and
Procedures XPath. The AppendChild,InsertAfter, and InsertBefore methods
Views
add nodes
Chapter 12 - to the document.
Oracle, TheOther
SQLXML, and RemoveAll, RemoveChild,
.NET Data Providers and ReplaceChild methods remove or
replace13
Chapter document nodes,
- Developing respectively.
a Custom You'll implement these methods and properties later in this chapter.
Data Provider
Chapter 14 - Developing Database Web Applications using ASP.NET
Using the XmlDocument Class
Chapter 15 - Using ADO.NET in Xml Web Services
Chapter 16 - ASP.NET Server Controls and Data Binding
TheXmlDocument class represents an XML document. Because it's derived from the XmlNode class, it
Chapter 17 - Building Real-World Web Applications
supports all tree traversal, insert, remove, and replace functionality. In spite of XmlNode functionality, this
Chapter 18 - Object-Relational Mapping in .NET
class contains many useful methods.
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
Chapter
The DOM20 -isCOM Interoperability
a cached and ADO.NET
tree representation of an XML document. The Load and LoadXml methods of this
Chapter 21 -XML
class load Messaging
data and documents, and the Save method saves a document.
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
TheLoad
Appendix A method canDatabases:
- Relational load a document fromConcepts
Some Basic a string, stream, TextReader, or XmlReader. The following
code loads
Appendix B - the document
Commonly Usedbooks.xml from a string:
SQL Statements
Appendix C - ADO.NET Frequently Asked Questions
Dim xmlDoc As XmlDocument = New XmlDocument()
Index
Dim filename As String = "C:\\books.xml"
List of Figures
xmlDoc.Load(filename)
List of Tables
xmlDoc.Save(Console.Out)
List of Listings
List of Sidebars
The following example uses the Load method to load a document from an XmlReader:
TheLoadXml method loads a document from the specified string. For example:
Applied ADO.NET:
xmlDoc.LoadXml("<Record> Building
write Data-Driven Solutions
something</Record>");
by Mahesh Chand and David Talbot ISBN:1590590732
Apress 2003 (928 pages)
This text provides extensive coverage of ADO.NET technology
Saving a Document
including ADO.NET internals, namespaces, classes, and
interfaces, and takes a comprehensive look at XML
TheSave methodnamespaces
saves a document to a and
and classes, specified
how tolocation.
integrateThe with method takes a parameter of
Save
both
ADO.NET.
XmlWriter,XmlTextWriter, or a string type:
Dim
Table of xmlDoc
Contents As XmlDocument = New XmlDocument()
Dim filename
Applied As String
ADO.NETBuilding = "C:\\books.xml"
Data-Driven Solutions
xmlDoc.Load(filename)
Introduction
Dim writer As XmlTextWriter = _
Chapter 1 - ADO.NET Basics
New XmlTextWriter("C:\\domtest.xml", Nothing)
Chapter 2 - Data Components in Visual Studio .NET
writer.Formatting = Formatting.Indented
Chapter 3 - ADO.NET in Disconnected Environments
xmlDoc.Save(writer)
Chapter 4 - ADO.NET in Connected Environments
Chapter 5 - Handling ADO.NET Events
You can
Chapter 6 also use a filename
- Integrating or Console.Out
XML with ADO.NET to save the output as a file or on the console:
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
Chapter 8 - Constraints and Data Relations
xmlDoc.Save("C:\\domtest.xml")
Chapter 9 - ADO.NET Exception Handling
xmlDoc.Save(Console.Out)
Chapter 10 - Working with the ODBC .NET Data Provider
Chapter 11 - Stored Procedures and Views
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Using the XmlDocumentFragment Class
Chapter 13 - Developing a Custom Data Provider
Chapter 14you
Usually, - Developing
would useDatabase Web Applications using class
the XmlDocumentFragment ASP.NET
when you need to insert a small fragment of an
XML document
Chapter orADO.NET
15 - Using node intoinaXml
document. This class also comes from the XMLNode class and has the same
Web Services
tree node
Chapter 16 traverse,
- ASP.NETinsert,
Serverremove,
Controlsand
and replace capabilities.
Data Binding
Chapter 17 - Building Real-World Web Applications
You usually create this class instance by calling XmlDocument'sCreateDocumentFragment method.
Chapter 18 - Object-Relational Mapping in .NET
TheInnerXml property represents the children of this node. Listing 6-10 shows an example of how to
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
create XmlDocumentFragment and load a small piece of XML data using its InnerXml property.
Chapter 20 - COM Interoperability and ADO.NET
Chapter
Listing21 - Messaging
6-10: The XmlDocumentFragment Sample
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Appendix A - Relational Databases: Some Basic Concepts
Dim xmlDoc As XmlDocument = New XmlDocument()
Appendix B - Commonly Used SQL Statements
Dim filename As String = "C:\\books.xml"
Appendix C - ADO.NET Frequently Asked Questions
xmlDoc.Load(filename)
Index 'Create a document fragment.
List of Figures
Dim docFrag As XmlDocumentFragment = xmlDoc.CreateDocumentFragment()
List of Tables
'Set the contents of the document fragment.
List of Listings
docFrag.InnerXml = "<Record> write something</Record>"
List of Sidebars
'Display the document fragment.
Console.WriteLine(docFrag.InnerXml)
You can use XmlNode methods to add, remove, and replace data. Listing 6-11 appends a node in the
document fragment.
Table of Contents
Applied ADO.NETBuilding Data-Driven Solutions
Introduction
Chapter 1 - ADO.NET Basics
Chapter 2 - Data Components in Visual Studio .NET
Chapter 3 - ADO.NET in Disconnected Environments
Chapter 4 - ADO.NET in Connected Environments
Chapter 5 - Handling ADO.NET Events
Chapter 6 - Integrating XML with ADO.NET
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
Chapter 8 - Constraints and Data Relations
Chapter 9 - ADO.NET Exception Handling
Chapter 10 - Working with the ODBC .NET Data Provider
Chapter 11 - Stored Procedures and Views
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Chapter 13 - Developing a Custom Data Provider
Chapter 14 - Developing Database Web Applications using ASP.NET
Chapter 15 - Using ADO.NET in Xml Web Services
Chapter 16 - ASP.NET Server Controls and Data Binding
Chapter 17 - Building Real-World Web Applications
Chapter 18 - Object-Relational Mapping in .NET
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
Chapter 20 - COM Interoperability and ADO.NET
Chapter 21 - Messaging
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Appendix A - Relational Databases: Some Basic Concepts
Appendix B - Commonly Used SQL Statements
Appendix C - ADO.NET Frequently Asked Questions
Index
List of Figures
List of Tables
List of Listings
List of Sidebars
Understanding
AppliedTransformation and XSLT
ADO.NET: Building Data-Driven Solutions
by Mahesh Chand and David Talbot ISBN:1590590732
Extensible Stylesheet
ApressLanguage
2003 (928(XSL)
pages) is a language for expressing stylesheets. Stylesheets format XML
documents in a way so that the XML data can
This text provides extensive be presented
coverage in a certain
of ADO.NET structure in a browser or other
technology
media such as catalogs, books, and so on.
including ADO.NET internals, namespaces, classes, and
interfaces, and takes a comprehensive look at XML
namespaces
The XML stylesheet processorand classes,
reads and how
an XML to integrate
document both
(called an with
XML sourcetree) and stylesheet, and it
ADO.NET.
presents the document data in an XML tree format. This processing is XSLT (see Figure 6-5).
Table of Contents
Applied ADO.NETBuilding Data-Driven Solutions
Introduction
Chapter 1 - ADO.NET Basics
Chapter 2 - Data Components in Visual Studio .NET
Chapter 3 - ADO.NET in Disconnected Environments
Chapter 4 - ADO.NET in Connected Environments
Chapter 5 - Handling ADO.NET Events
Chapter 6 - Integrating XML with ADO.NET
Chapter 7 - 6-5:
Figure Data The
Binding
XSLand Windows Forms Data-Bound Controls
transformation
Chapter 8 - Constraints and Data Relations
The result
Chapter 9 -tree generated
ADO.NET after Handling
Exception the XML transformation contains element and attribute nodes. In this tree,
an object
Chapter 10 is an XML with
- Working element, and properties
the ODBC .NET Data are attribute-value pairs.
Provider
Chapter 11 - Stored Procedures and Views
The XSL stylesheet plays a vital role in the XSLT process. A stylesheet contains a set of tree construction
Chapter 12 - Oracle,
rules, which SQLXML,
have two parts. and
TheOther .NET
first part is Data Providers
a pattern of elements in the source tree, and the second is a
Chapter 13 for
template - Developing a Custom
the result tree. Data parser
The XSL Provider reads the pattern and elements from the source tree and then
Chapter 14 -results
generates Developing Database
according Web
to the Applications
result using ASP.NET
tree template.
Chapter 15 - Using ADO.NET in Xml Web Services
Transformation
Chapter is required
16 - ASP.NET Server when youand
Controls need to Binding
Data convert an XML document into an XML schema-matching
document.
Chapter 17 - The XslTransform
Building class
Real-World Web provides the functionality to implement the XSLT specification. A
Applications
separate namespace called System.Xml.Xsl defines this class. Make sure you add a reference to this
Chapter 18 - Object-Relational Mapping in .NET
namespace before using the XslTransform class. You can use the XsltException class to handle
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
exceptions thrown by an XSLT transformation.
Chapter 20 - COM Interoperability and ADO.NET
Chapter 21 - Messaging
Using the Transform Method
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Appendix A - Relational Databases: Some Basic Concepts
TheTransform method of XslTransform transforms data using the loaded stylesheet and outputs the
Appendix B - Commonly Used SQL Statements
result depending on the argument. This method has eight overloaded forms. You can write output of
Appendix C - ADO.NET Frequently Asked Questions
Transform in the form of XmlWriter, a stream, TextWriter, or XPathNavigator. (We discuss
Index
XPathNavigator in the "Navigating in XML" section of this chapter.)
List of Figures
List of Tables
Follow these steps perform the transformation:
List of
1.Listings
First, you need to create an XslTransform object:
List of Sidebars
xslt.Load("stylesheetFrmt.xsl");
xslt.Transform("xmlfile.xml", "file.html")
3.
Looking at by
anMahesh Chand and David Talbot ISBN:1590590732
Example
Apress 2003 (928 pages)
This text providesinextensive
Before you use XslTransform coverageyou
your application, of ADO.NET technology
need to add three namespace references to your
including ADO.NET internals, namespaces, classes, and
application. These namespaces are System.Xml,System.Xml.XPath, and System.Xml.Xsl. (We
interfaces, and takes a comprehensive look at XML
discuss the XPath namespace
namespaces andinclasses,
more detail in the
and how to "Navigating in XML"
integrate both with section of this chapter.) Listing 6-
19 uses the books.xsl
ADO.NET.schema file that comes with the .NET Software Development Kit (SDK) samples.
Note SeeChapter 3 and Chapter 4 for more details about the DataSet object.
In the following example, create a new DataSet object and call the DataSet.ReadXml method to load
thebooks.xml file in a DataSet object:
- <DS xmlns="StdNamespace">
Table of Contents
- <Student>
Applied ADO.NETBuilding
<Name>Melanie Data-Driven Solutions
Talmadge</Name>
Introduction
<Address>Meadowlake Dr, Dtown</Address>
Chapter 1 - ADO.NET Basics
</Student>
Chapter 2 - Data Components in Visual Studio .NET
- <Student>
Chapter 3 - ADO.NET
<Name>Amy in Disconnected Environments
Talmadge</Name>
Chapter 4 - ADO.NET in Connected Environments
<Address>Herndon</Address>
</Student>
Chapter 5 - Handling ADO.NET Events
</DS>6 - Integrating XML with ADO.NET
Chapter
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
Chapter 8 - Constraints and Data Relations
Chapter 9 - ADO.NET Exception Handling
Using10the
Chapter WriteXmlSchema
- Working Method
with the ODBC .NET Data Provider
Chapter 11 - Stored Procedures and Views
TheWriteXmlSchema method writes a DataSet structure to an XML schema. WriteXmlSchema has
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
four overloaded methods. You can write the data to a stream, text, TextWriter, or XmlWriter.Listing
Chapter 13 -XmlWriter
6-22 uses Developing afor
Custom Data Provider
the output.
Chapter 14 - Developing Database Web Applications using ASP.NET
Listing15
Chapter 6-22: Using
- Using the WriteXmlSchema
ADO.NET Method
in Xml Web Services
Chapter 16 - ASP.NET Server Controls and Data Binding
Chapter
Dim ds 17 As
- Building
DataSetReal-World
= NewWeb Applications
DataSet("DS")
Chapter 18 - Object-Relational
ds.Namespace Mapping in .NET
= "StdNamespace"
Chapter 19 - Mapped
Dim stdTable AsObjects: Performance
DataTable = NewConsiderations and Data Binding
DataTable("Students")
Chapter 20 - COM
Dim col1 Interoperability =
As DataColumn and ADO.NET
New DataColumn("Name")
Chapter 21 - Messaging
Dim col2 As DataColumn = New DataColumn("Address")
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
stdTable.Columns.Add(col1)
stdTable.Columns.Add(col2)
Appendix A - Relational Databases: Some Basic Concepts
ds.Tables.Add(stdTable)
Appendix B - Commonly Used SQL Statements
' Add C
Appendix Student Data
- ADO.NET to the
Frequently table
Asked Questions
Dim NewRow As DataRow = stdTable.NewRow()
Index
NewRow("Name")
List of Figures = "Melnaie Talmadge"
NewRow("Address") = "Meadowlake Dr, Dtown"
List of Tables
stdTable.Rows.Add(NewRow)
List of Listings
NewRow = stdTable.NewRow()
List of Sidebars
NewRow("Name") = "Amy Talmadge"
NewRow("Address") = "Herndon, VA"
stdTable.Rows.Add(NewRow)
ds.AcceptChanges()
Dim writer As XmlTextWriter =
New XmlTextWriter(Console.Out)
ds.WriteXmlSchema(writer)
Table of Contents
Applied ADO.NETBuilding Data-Driven Solutions
Introduction
Chapter 1 - ADO.NET Basics
Chapter 2 - Data Components in Visual Studio .NET
Chapter 3 - ADO.NET in Disconnected Environments
Chapter 4 - ADO.NET in Connected Environments
Chapter 5 - Handling ADO.NET Events
Chapter 6
Figure- 6-6:
Integrating XML with ADO.NET
TheXmlDataDocument class inheritance
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
Chapter 8 - Constraints and Data Relations
Besides9 overriding
Chapter - ADO.NET theException
methodsHandling
of XmlNode and XmlDocument,XmlDataDocument also implements its
own methods.
Chapter The XmlDataDocument
10 - Working classProvider
with the ODBC .NET Data lets you load relational data using the DataSet object as
well as XML documents using the Load and LoadXml methods. As Figure 6-7 indicates, you can use a
Chapter 11 - Stored Procedures and Views
DataSet to load relational data to an XmlDataDocument object and use the Load or LoadXml
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
methods to load an XML document. Figure 6-7 shows the relationship between a Reader,Writer,
Chapter 13 - Developing a Custom Data Provider
DataSet, and XmlDataDocument.
Chapter 14 - Developing Database Web Applications using ASP.NET
Chapter 15 - Using ADO.NET in Xml Web Services
Chapter 16 - ASP.NET Server Controls and Data Binding
Chapter 17 - Building Real-World Web Applications
Chapter 18 - Object-Relational Mapping in .NET
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
Chapter 20 - COM Interoperability and ADO.NET
Chapter 21 - Messaging
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Appendix A - Relational Databases: Some Basic Concepts
Figure
Appendix B - 6-7: Reading
Commonly and
Used writing
SQL data using XmlDataDocument
Statements
Appendix C - ADO.NET Frequently Asked Questions
TheXmlDataDocument class extends the functionality of XmlDocument and synchronizes it with a
Index
DataSet. As you know, a DataSet is a powerful object in ADO.NET. As Figure 6-7 shows, you can take
List of Figures
data from two different sources. First, you can load data from an XML document with the help of
List of Tables
XmlReader, and second, you can load data from relational data sources with the help of database
List of Listings
providers and a DataSet. The neat thing is the data synchronization between these two objects. If you
List of Sidebars
update data in a DataSet object, you see the results in the XmlDataDocument object-and vice versa.
For example, if you add a record to a DataSet object, the action will add one node to the
XmlDataDocument object representing the newly added record.
Once the data is loaded, you're allowed to use any operations that you're able to use on XmlDocument
objects. You can also use XmlReader and XmlWriter objects to read and write the data.
TheXmlDataDocument class has a property called DataSet. It returns the attached DataSet object
with XmlDataDocument. The DataSet property provides you a relational representation of an XML
document. Once you have a DataSet object, you can do anything with it that you did in Chapters 3 and 4,
such as binding it to data-bound controls.
You can use all the XML read and write methods of the DataSet object (such as ReadXml,
ReadXmlSchema,WriteXml, and WriteXmlSchema) through the DataSet property. Refer to the
Applied
DataSet read and ADO.NET:
write methods in Building Data-Driven
the previous section toSolutions
see how these methods are used.
by Mahesh Chand and David Talbot ISBN:1590590732
Loading DataApress
Using Load
2003 and LoadXml
(928 pages) from the XmlDataDocument
This text provides extensive coverage of ADO.NET technology
including
You can use either ADO.NET
the Load method internals, namespaces,
or the LoadXml classes,
method and an XML document. The Load
to load
interfaces, of
method takes a parameter anda takes a comprehensive
filename look at XMLor an XmlReader. Similarly, you can use
string, a TextReader,
namespaces and classes, and how to integrate both with
theLoadXml method. This method passes an XML filename to load the XML file. For example:
ADO.NET.
Loading
Chapter 7 Data
- Data Using
Binding a DataSet
and Windows Forms Data-Bound Controls
Chapter 8 - Constraints and Data Relations
As you 9learned
Chapter in Chapter
- ADO.NET 3, a Handling
Exception DataSet object has methods to read XML documents. These methods
areReadXmlSchema
Chapter andthe
10 - Working with LoadXml. You
ODBC .NET useProvider
Data the Load or LoadXml methods to load an XML document
the same
Chapter 11 way you did
- Stored directly and
Procedures fromViews
XMLDataDocument. Again, the Load method takes a parameter of a
filename
Chapter 12string, SQLXML, andorOther
TextReader,
- Oracle, .NET DataSimilarly,
XmlReader. Providersuse the LoadXml method to pass an XML
filename
Chapter 13through the DataSet.
- Developing a Custom For
Dataexample:
Provider
Chapter 14 - Developing Database Web Applications using ASP.NET
Dim doc
Chapter 15 -As XmlDataDocument
Using ADO.NET in Xml Web=Services
New XmlDataDocument()
doc.DataSet.ReadXmlSchema("test.xsd")
Chapter 16 - ASP.NET Server Controls and Data Binding
Chapter 17 - Building Real-World Web Applications
Chapter 18 - Object-Relational Mapping in .NET
or as follows:
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
Chapter 20 - COM Interoperability and ADO.NET
doc.DataSet.ReadXml("<Record> write something</Record>")
Chapter 21 - Messaging
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Appendix A - Relational Databases: Some Basic Concepts
Appendix B - Commonly Used SQL Statements
Displaying XML Data in a DataSet Format
Appendix C - ADO.NET Frequently Asked Questions
Index
As mentioned previously, you can get a DataSet object from an XmlDataDocument object by using its
List of Figures
DataSet property. OK, now it's time to see how to do that. The next sample shows you how easy it is to
List of Tables
display an XML document data in a DataSet format.
List of Listings
You
List of can read an XML document using the ReadXml method of the DataSet object. The DataSet
Sidebars
property of XmlDataDocument represents the DataSet of XmlDataDocument. After reading a
document in a DataSet, you can create data views from the DataSet, or you can also use a DataSet's
DefaultViewManager property to bind to data-bound controls, as you can see in the following code:
As you can see from Listing 6-23, you create a new DataSet,Books, fill it from the books.xml file, and
bind it to a DataGrid control using its DataSource property. To make Listing 6-23 work, you need to
create a Windows application and drag a DataGrid control to the form. After doing that, write the Listing
6-23 code on theApplied ADO.NET: Building Data-Driven Solutions
form load event.
by Mahesh Chand and David Talbot ISBN:1590590732
Apress 2003 (928 pages)
Listing 6-23: XmlDataDocumentSample.vb
This text provides extensive coverage of ADO.NET technology
including ADO.NET internals, namespaces, classes, and
Private Sub Form1_Load(ByVal sender As System.Object,
interfaces, and takes a comprehensive look at XML _
ByVal e As namespaces
System.EventArgs) Handles
and classes, and MyBase.Load
how to integrate both with
' Create ADO.NET.
an XmlDataDocument object and read an XML
Dim xmlDatadoc As XmlDataDocument = New XmlDataDocument()
xmlDatadoc.DataSet.ReadXml("C:\\books.xml")
Table of Contents
' Create a DataSet object and fill it with the dataset
Applied ADO.NETBuilding Data-Driven Solutions
' of XmlDataDocument
Introduction
Dim ds As DataSet = New DataSet("Books DataSet")
Chapterds
1 =- ADO.NET Basics
xmlDatadoc.DataSet
Chapter'2 Attach
- Data Components in Visual
dataset view toStudio
the .NET
DataGrid control
ChapterDataGrid1.DataSource
3 - ADO.NET in Disconnected = Environments
ds.DefaultViewManager
Chapter
End Sub4 - ADO.NET in Connected Environments
Chapter 5 - Handling ADO.NET Events
Chapter 6 - Integrating XML with ADO.NET
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
If you run
Chapter 8 this program,and
- Constraints you'll
DataseeRelations
the DataGrid filled with the data.
Chapter 9 - ADO.NET Exception Handling
Saving Data from a DataSet to XML
Chapter 10 - Working with the ODBC .NET Data Provider
Chapter 11 - Stored Procedures and Views
You can
Chapter 12save a DataSet
- Oracle, asand
SQLXML, an Other
XML document
.NET Data using the Save method of the XmlDataDocument class.
Providers
Actually,
Chapter 13XmlDataDocument comes
- Developing a Custom Data from XmlDocument, and the XmlDocument class defines the Save
Provider
method. As you know, you can use Save method to save your data in a string, stream, TextWriter, and
Chapter 14 - Developing Database Web Applications using ASP.NET
XmlWriter.
Chapter 15 - Using ADO.NET in Xml Web Services
Chapter 16 create
First, you - ASP.NET Server Controls
a DataSet and Data
object and Binding
fill it using a DataAdapter. The following example reads the
Chapter 17 - Building Real-World Web Applications
Customers table from the Northwind Access database and fills data from the table to the DataSet:
Chapter 18 - Object-Relational Mapping in .NET
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
Dim sql As String = "SELECT * FROM Customers"
Chapter
Dim da 20 As
- COM Interoperability and
SqlDataAdapter = ADO.NET
New SqlDataAdapter(sql, conn)
Chapter 21 - Messaging
' Create and fill a DataSet
Chapter
Dim ds 22 As
- SQL Server and
DataSet = ADO.NET: Notes on Performance
New DataSet()
Appendix A - Relational Databases: Some Basic Concepts
da.Fill(ds)
Appendix B - Commonly Used SQL Statements
Appendix C - ADO.NET Frequently Asked Questions
Now, you create an instance of XmlDataDocument with the DataSet as an argument and call the Save
Index
method
List to save the data as an XML document:
of Figures
List of Tables
Dim
List doc As XmlDataDocument = New XmlDataDocument(ds)
of Listings
doc.Save("C:\\XmlDataDoc.xml")
List of Sidebars
Listing 6-24 shows a complete program. You create an XmlDataDocument object with a DataSet and
call the Save method to save the DataSet data in an XML file.
Imports System.Data
Imports System.Data.SqlClient
Imports System.Xml
Module Module1
Sub Main()
' Create Applied ADO.NET: Object
a Connection Building Data-Driven Solutions
Dim ConnectionString As David
by Mahesh Chand and String Talbot
= "IntegratedISBN:1590590732
Security=SSPI;" & _
Apress 2003 (928 pages)
"Initial Catalog=Northwind;Data Source=MCB;"
Dim conn ThisAs text provides extensive
SqlConnection = coverage of ADO.NET technology
New SqlConnection()
including ADO.NET internals,
conn.ConnectionString = ConnectionString namespaces, classes, and
interfaces, and takes a comprehensive look at XML
' Open the connection
namespaces and classes, and how to integrate both with
If conn.State
ADO.NET. <> ConnectionState.Open Then
conn.Open()
End If
Table of Contents
Dim sql As String = "SELECT * FROM Customers"
AppliedDim
ADO.NETBuilding Data-Driven Solutions
da As SqlDataAdapter = New SqlDataAdapter(sql, conn)
Introduction
' Create and fill a DataSet
ChapterDim
1 -ds ADO.NET Basics
As DataSet = New DataSet()
Chapterda.Fill(ds)
2 - Data Components in Visual Studio .NET
Chapter'3 Now use SxlDataDocument's
- ADO.NET Save method to save data as an XML file
in Disconnected Environments
ChapterDim
4 -doc As XmlDataDocument
ADO.NET in Connected Environments= New XmlDataDocument(ds)
Chapterdoc.Save("C:\\XmlDataDoc.xml")
5 - Handling ADO.NET Events
Chapter'6 Close and dispose
- Integrating the connection
XML with ADO.NET
ChapterIf
7 conn.State <> Windows
- Data Binding and ConnectionState.Open Then
Forms Data-Bound Controls
conn.Open()
Chapter 8 - Constraints and Data Relations
conn.Dispose()
Chapter 9 - ADO.NET Exception Handling
End If
Chapter 10 - Working with the ODBC .NET Data Provider
End Sub
Chapter 11 - Stored Procedures and Views
End Module
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Chapter 13 - Developing a Custom Data Provider
Chapter 14 - Developing Database Web Applications using ASP.NET
Chapter 15 - Using ADO.NET in Xml Web Services
XmlDataDocument: Looking under the Hood
Chapter 16 - ASP.NET Server Controls and Data Binding
Chapter 17 - Building Real-World Web Applications
After looking at Listing 6-23, which illustrates the reading of an XML document in a DataGrid control, you
Chapter 18 - Object-Relational Mapping in .NET
must be wondering how it happened. The DataSet object handles everything for you under the hood:
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
Chapter 20 - COM Interoperability and ADO.NET
doc.DataSet.ReadXml("C:\\outdata.xml")
Chapter 21 - Messaging
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Appendix A - Relational
As you see in this line,Databases: Some
you're calling theBasic Concepts
DataSet.ReadXml method to read an XML document. The
Appendix
DataSet B -extracts
Commonly the Used SQL Statements
document and defines tables and columns for you.
Appendix C - ADO.NET Frequently Asked Questions
Generally, the root node of the XML document becomes a table; the document's name, namespace,
Index
namespace URI, and prefix become the DataSet'sName,Namespace,NamespaceURI, and Prefix
List of Figures
properties, respectively. If an element's children have one or more children, they become another table
List of Tables
inside the main table in a nested format. Anything left from the tables becomes columns of the table. The
List of Listings
value of a node becomes a row in a table. The DataSet takes care of all of this for you.
List of Sidebars
Navigating Applied
in XML ADO.NET: Building Data-Driven Solutions
by Mahesh Chand and David Talbot ISBN:1590590732
As you saw, XmlNode
Apressprovides a pages)
2003 (928 way to navigate DOM trees with the help of its FirstChild,
ChildNodes,LastChild, PreviousNode, NextSibling,
This text provides extensive coverage andtechnology
of ADO.NET PreviousSibling methods.
including ADO.NET internals, namespaces, classes, and
BesidesXmlNode, the XML and
interfaces, .NET has atwo
takes more classes,
comprehensive which
look help you navigate XML documents. These
at XML
classes are XPathDocument
namespaces andandclasses, The System.Xml.XPath
and how to integrate
XPathNavigator. both with namespace defines
ADO.NET.
both of these classes.
TheXPath namespace contains classes to provide read-only, fast access to documents. Before using
Table
theseofclasses,
Contentsyou must add a reference to the System.Xml.XPath namespace in your application.
Applied ADO.NETBuilding Data-Driven Solutions
XPathNodeIterator,XPathExpression, and XPathException are other classes defined in this
Introduction
namespace.
Chapter The XPathNodeIterator
1 - ADO.NET Basics class provides iteration capabilities to a node.
XPathExpression
Chapter providesinselection
2 - Data Components criteria
Visual Studio to select a set of nodes from a document based on those
.NET
criteria,3and
Chapter the XPathException
- ADO.NET in Disconnectedclass is an exception class. TheXPathDocument class provides a
Environments
fast cache
Chapter 4 -for XML document
ADO.NET processing
in Connected using XSLT and XPath.
Environments
Chapter 5 - Handling ADO.NET Events
You use the XPathDocument constructor to create an instance of XmlPathDocument. It has many
Chapter 6 - Integrating
overloaded XML
constructors. with
You ADO.NET
can pass an XmlReader,TextReader, or even direct XML filenames.
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
Chapter 8 - Constraints and Data Relations
Using the
Chapter 9
XPathNavigator Class
- ADO.NET Exception Handling
Chapter 10 - Working withclass
TheXPathNavigator the ODBC .NET Data
implements theProvider
functionality to navigate through a document. It has easy-to-
Chapter 11 - Stored Procedures and Views
use and self-explanatory methods. You create an XPathNavigator instance by calling
Chapter 12 - Oracle, SQLXML,
XPathDocument's and Other .NET
CreateNavigator Data Providers
method.
Chapter 13 - Developing a Custom Data Provider
You can
Chapter 14also create a XPathNavigator
- Developing object using
Database Web Applications by calling XmlDocument'sCreateNavigator method.
ASP.NET
For example,
Chapter the following
15 - Using ADO.NET incode
Xmlcalls
Web XmlDocument's
Services CreateNavigator method to create a
Chapter 16 - ASP.NET object:
XPathNavigator Server Controls and Data Binding
Chapter 17 - Building Real-World Web Applications
' Load
Chapter 18 books.xml document
- Object-Relational Mapping in .NET
Dim xmlDoc
Chapter As XmlDocument
19 - Mapped = New
Objects: Performance XmlDocument()
Considerations and Data Binding
xmlDoc.Load("c:\\books.xml")
Chapter 20 - COM Interoperability and ADO.NET
' Create
Chapter XPathNavigator object by calling CreateNavigator of XmlDocument
21 - Messaging
Dim nav As XPathNavigator = xmlDoc.CreateNavigator()
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Appendix A - Relational Databases: Some Basic Concepts
Appendix B - Commonly Used SQL Statements
Appendix
NoteC Don't
- ADO.NET
forgetFrequently Asked Questions
to add a reference to the System.Xml.XPath namespace to your project before
Index using any of its classes.
List of Figures
The
List ofXPathNavigator
Tables class contains methods and properties to move to the first, next, child, parent, and
root
List ofnodes of the document.
Listings
List of Sidebars
Using XPathNavigator Move Methods
Table 6-7 describes XPathNavigator'sMove methods.
If nav.HasChildren Then
nav.MoveToFirstChild()
End If
Now, using the MoveToNext and MoveToParent methods, you can move through the entire document.
Listing 6-26 moves though an entire document and displays the data on the console. The GetNodeInfo
method displays a node's information, and you call it recursively.
Listing 6-26: Reading a Document Using XPathNavigator
Applied ADO.NET: Building Data-Driven Solutions
by Mahesh Chand and David Talbot ISBN:1590590732
Imports System.Data
Apress 2003 (928 pages)
Imports System.Data.SqlClient
This text provides extensive coverage of ADO.NET technology
Imports System.Xml
including ADO.NET internals, namespaces, classes, and
Imports System.Xml.XPath
interfaces, and takes a comprehensive look at XML
namespaces and classes, and how to integrate both with
ADO.NET.
Module Module1
Sub Main()
Table of' Contents
Load books.xml document
Dim xmlDoc As XmlDocument = New XmlDocument()
Applied ADO.NETBuilding Data-Driven Solutions
xmlDoc.Load("c:\\books.xml")
Introduction
' Create XPathNavigator object by calling CreateNavigator of XmlDocument
Chapter 1 - ADO.NET Basics
Dim nav As XPathNavigator = xmlDoc.CreateNavigator()
Chapter 2 - Data Components in Visual Studio .NET
Chapter 3 - ADO.NET in Disconnected Environments
' Moce to root node
Chapternav.MoveToRoot()
4 - ADO.NET in Connected Environments
ChapterDim
5 -name
Handling
AsADO.NET
StringEvents
= nav.Name
ChapterConsole.WriteLine("Root
6 - Integrating XML with ADO.NET
node info: ")
ChapterConsole.WriteLine("Base
7 - Data Binding and Windows Forms
URI" Data-Bound Controls
+ nav.BaseURI.ToString())
ChapterConsole.WriteLine("Name:
8 - Constraints and Data Relations
" + nav.Name.ToString())
ChapterConsole.WriteLine("Node
9 - ADO.NET Exception HandlingType: " + nav.NodeType.ToString())
ChapterConsole.WriteLine("Node
10 - Working with the ODBC .NETValue: " + nav.Value.ToString())
Data Provider
Chapter 11 - Stored Procedures and Views
ChapterIf
12 nav.HasChildren
- Oracle, SQLXML, and Then
Other .NET Data Providers
nav.MoveToFirstChild()
Chapter 13 - Developing a Custom Data Provider
GetNodeInfo(nav)
Chapter 14 - Developing Database Web Applications using ASP.NET
End If
Chapter 15 - Using ADO.NET in Xml Web Services
End Sub
Chapter 16 - ASP.NET Server Controls and Data Binding
' GetNodeInfo method
Chapter 17 - Building Real-World Web Applications
Public Sub GetNodeInfo(ByVal nav1 As XPathNavigator)
Chapter 18 - Object-Relational Mapping in .NET
Console.WriteLine("Name: " + nav1.Name.ToString())
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
Console.WriteLine("Node Type: " + nav1.NodeType.ToString())
ChapterConsole.WriteLine("Node
20 - COM Interoperability and ADO.NET
Value: " + nav1.Value.ToString())
Chapter 21 - Messaging
Chapter'22
If- SQL Server
node hasand ADO.NET: Notes
children, moveonto
Performance
fist child.
Appendix
IfA nav1.HasChildren
- Relational Databases: Some
Then Basic Concepts
Appendix B - Commonly Used SQL Statements
nav1.MoveToFirstChild()
Appendix C - ADO.NET Frequently Asked Questions
Index While nav1.MoveToNext()
GetNodeInfo(nav1)
List of Figures
List of Tablesnav1.MoveToParent()
End While
List of Listings
Else
List of Sidebars
nav1.MoveToNext()
GetNodeInfo(nav1)
End If
End Sub
End Module
Table of Contents
' Load books.xml document
AppliedDim
ADO.NETBuilding Data-Driven Solutions
xmlDoc As XmlDocument = New XmlDocument()
Introduction
xmlDoc.Load("c:\\books.xml")
Chapter'1 Create
- ADO.NET Basics
XPathNavigator object by calling CreateNavigator of XmlDocument
ChapterDim
2 -nav
Data As
Components in Visual Studio
XPathNavigator .NET
= xmlDoc.CreateNavigator()
Chapter'3 Look for author's
- ADO.NET first
in Disconnected name
Environments
ChapterConsole.WriteLine("Author First Name")
4 - ADO.NET in Connected Environments
ChapterDim
5 -itrator As XPathNodeIterator
Handling ADO.NET Events = _
Chapternav.Select("descendant::first-name")
6 - Integrating XML with ADO.NET
ChapterWhile itrator.MoveNext()
7 - Data Binding and Windows Forms Data-Bound Controls
Console.WriteLine(itrator.Current.Value.ToString())
Chapter 8 - Constraints and Data Relations
End While
Chapter 9 - ADO.NET Exception Handling
Chapter 10 - Working with the ODBC .NET Data Provider
Chapter 11 - Stored Procedures and Views
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Chapter 13 - Developing a Custom Data Provider
Chapter 14 - Developing Database Web Applications using ASP.NET
Chapter 15 - Using ADO.NET in Xml Web Services
Chapter 16 - ASP.NET Server Controls and Data Binding
Chapter 17 - Building Real-World Web Applications
Chapter 18 - Object-Relational Mapping in .NET
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
Chapter 20 - COM Interoperability and ADO.NET
Chapter 21 - Messaging
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Appendix A - Relational Databases: Some Basic Concepts
Appendix B - Commonly Used SQL Statements
Appendix C - ADO.NET Frequently Asked Questions
Index
List of Figures
List of Tables
List of Listings
List of Sidebars
Working with Schemas
Applied ADO.NET: Building Data-Driven Solutions
by Mahesh Chand and David Talbot ISBN:1590590732
XML schemas play a major
Apress 2003role
(928inpages)
the .NET Framework, and Visual Studio .NET (VS .NET) provides many
tools and utilities This
to work with XML. The .NETcoverage
text provides extensive Framework uses XML
of ADO.NET to transfer data from one application to
technology
other. XML schemas including ADO.NET internals, namespaces, classes, anddocuments. You use XML Schema
define the structure and validation rules of XML
interfaces,to
Definition (XSD) language and takesXML
define a comprehensive
schemas. look at XML
namespaces and classes, and how to integrate both with
VS .NET providesADO.NET.
an XML designer to work with schemas. In this section, you'll learn how to take
advantage of the VS .NET XML designer and wizards to work with XML documents and databases.
Table of Contents
Generating a New Schema
Applied ADO.NETBuilding Data-Driven Solutions
Introduction
To generate
Chapter Basics create a new Windows application using File New Project Visual Basic
a new schema,
1 - ADO.NET
Projects -Windows
Chapter 2
Application. Then just follow the steps outlined in the following sections.
Data Components in Visual Studio .NET
Chapter 3- ADO.NET in Disconnected Environments
Step 1: Adding an Empty Schema
Chapter 4 - ADO.NET in Connected Environments
Chapter
You can5 add
- Handling
an XMLADO.NET
schema Events
to a project by right-clicking a project and then selecting Add Add New
Chapter 6 - Integrating
Item. The Add New Item XML with opens
option ADO.NETthe Add New Item dialog box, where you can select different
Chapter 7 - To
templates. Data Binding
add an XMLandschema,
Windowsyou
Forms Data-Bound
need Controls
to select the XML Schema template on this page. This page
also allows you to specify the schema name.
Chapter 8 - Constraints and Data Relations The default schema name is XMLSchema1.xsd. Next, click
the Open
Chapter 9 button on the
- ADO.NET Add New
Exception Item page.
Handling
Chapter 10 - Working with the ODBC .NET Data Provider
This action launches the XML designer, which allows you to design XML schemas. The default XML
Chapter 11 - Stored Procedures and Views
designer page like Figure 6-8. As you can see, there are two links available: Server Explorer and Toolbox.
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Chapter 13 - Developing a Custom Data Provider
Chapter 14 - Developing Database Web Applications using ASP.NET
Chapter 15 - Using ADO.NET in Xml Web Services
Chapter 16 - ASP.NET Server Controls and Data Binding
Chapter 17 - Building Real-World Web Applications
Chapter 18 - Object-Relational Mapping in .NET
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
Chapter 20 - COM Interoperability and ADO.NET
Chapter 21 - Messaging
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Appendix A - Relational Databases: Some Basic Concepts
Appendix B - Commonly Used SQL Statements
Appendix C - ADO.NET Frequently Asked Questions
Index
List of Figures
List of Tables
List of Listings
Figure 6-8: The XML designer
List of Sidebars
As you might guess, the Server Explorer link launches the Server Explorer. (See Chapter 2 to learn more
about the Server Explorer.) The Toolbox link launches a Toolbox that contains the XML Schema items
rather than Windows or Web controls.
If you click the XML option at the bottom of screen, you'll see that your XML looks like the following:
Table of Contents
Applied ADO.NETBuilding Data-Driven Solutions
Introduction
Chapter 1 - ADO.NET Basics
Chapter 2 - Data Components in Visual Studio .NET
Chapter 3 - ADO.NET in Disconnected Environments
Chapter 4 - ADO.NET in Connected Environments
Chapter 5 - Handling ADO.NET Events
Chapter 6 - Integrating XML with ADO.NET
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
Chapter 8 - Constraints and Data Relations
Chapter 9 - ADO.NET Exception Handling
Chapter 10 - Working with the ODBC .NET Data Provider
Chapter 11 - Stored Procedures and Views
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Chapter 13 - Developing a Custom Data Provider
Chapter 14 - Developing Database Web Applications using ASP.NET
Chapter 15 - Using ADO.NET in Xml Web Services
Chapter 16 - ASP.NET Server Controls and Data Binding
Chapter 17 - Building Real-World Web Applications
Chapter 18 - Object-Relational Mapping in .NET
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
Chapter 20 - COM Interoperability and ADO.NET
Chapter 21 - Messaging
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Figure 6-9: The XML schema Toolbox
Appendix A - Relational Databases: Some Basic Concepts
Appendix
The XMLB designer
- Commonly Used
works in SQL Statements
pretty much same way as the form designer. You drag components from the
Appendix
ToolboxCto- the
ADO.NET Frequently
designer, and theAsked Questions
designer writes the code for you. As you can see in Figure 6-9, you can
add an element, attribute, complexType, and other schema items to the form.
Index
List of Figures
First, let's add an element to the schema, dragging it from the Toolbox. Second, set its name and type in
List of Tables
the designer. The default element looks like Figure 6-10. If you click the right-side column of the grid, you'll
List of Listings
see a drop-down list with element types. You can either select the type of an item from the list or define your
List of Sidebars
own type (which is a user-defined type).
Applied ADO.NET: Building Data-Driven Solutions
by Mahesh Chand and David Talbot ISBN:1590590732
Apress 2003 (928 pages)
This text provides extensive coverage of ADO.NET technology
including ADO.NET internals, namespaces, classes, and
interfaces, and takes a comprehensive look at XML
namespaces and classes, and how to integrate both with
ADO.NET.
Table Figure
of Contents
6-10: Adding a schema element and its type
Applied ADO.NETBuilding Data-Driven Solutions
Introduction
For this example, define your own custom type. Define the first element as bookstore with a custom type
Chapter 1 - ADO.NET Basics
ofbookstoretype.Figure 6-11 shows the bookstore element of bookstoretype.
Chapter 2 - Data Components in Visual Studio .NET
Chapter 3 - ADO.NET in Disconnected Environments
Chapter 4 - ADO.NET in Connected Environments
Chapter 5 - 6-11:
Figure Handling ADO.NET
Adding a newEvents
bookstore element
Chapter 6 - Integrating XML with ADO.NET
Chapter
Now add7 a- complexType
Data Binding and Windows
item Formsa Data-Bound
by dragging complexTypeControls
item to the XML designer (see Figure 6-12).
Chapter 8 - Constraints and Data Relations
Chapter 9 - ADO.NET Exception Handling
Chapter 10 - Working with the ODBC .NET Data Provider
Chapter 11 - Stored Procedures and Views
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Chapter 13 - Developing a Custom Data Provider
Chapter 14 - Developing Database Web Applications using ASP.NET
Chapter 15 - Using ADO.NET in Xml Web Services
Chapter 16 - ASP.NET Server Controls and Data Binding
Chapter 17 - Building Real-World Web Applications
Figure
Chapter 18 - 6-12: A complexType
Object-Relational itemin .NET
Mapping
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
Chapter 20 - COM item
A complexType Interoperability
can containand ADO.NET
other types, too. You can add items to a complexType in many ways. You
Chapter 21 -drag
can either Messaging
an item from the Toolbox to the complexType or right-click a complexType and use the Add
option and
Chapter 22 - its
SQLsuboptions toADO.NET:
Server and add an item. Figure
Notes 6-13 shows different items you can add to a complexType.
on Performance
Appendix A - Relational Databases: Some Basic Concepts
Appendix B - Commonly Used SQL Statements
Appendix C - ADO.NET Frequently Asked Questions
Index
List of Figures
List of Tables
List of Listings
List of Sidebars
You can delete items by right-clicking and selecting Delete. You can also delete the entire complexType or
other schema items by right-clicking the header of an item or right-clicking the left side of the item.
Now, rename the added complexType name to book and add four element types: title,author,
AppliedNow
price, and category. ADO.NET: Building Data-Driven
your complexType Solutions
book should now look like Figure 6-14.
by Mahesh Chand and David Talbot ISBN:1590590732
Apress 2003 (928 pages)
This text provides extensive coverage of ADO.NET technology
including ADO.NET internals, namespaces, classes, and
interfaces, and takes a comprehensive look at XML
namespaces and classes, and how to integrate both with
ADO.NET.
Table of Contents
Applied ADO.NETBuilding Data-Driven Solutions
Introduction
Figure 6-14: Thebook complexType and its elements
Chapter 1 - ADO.NET Basics
Chapter 2 - Data Components in Visual Studio .NET
Next, add
Chapter 3 -one more complexType
ADO.NET author
in Disconnected with two elements: first-name and last-name. Your final
Environments
schema4 should
Chapter now look
- ADO.NET like Figure
in Connected 6-15.
Environments
Chapter 5 - Handling ADO.NET Events
Chapter 6 - Integrating XML with ADO.NET
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
Chapter 8 - Constraints and Data Relations
Chapter 9 - ADO.NET Exception Handling
Chapter 10 - Working with the ODBC .NET Data Provider
Chapter 11 - Stored Procedures and Views
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Figure
Chapter 13 - 6-15: Theauthor
Developing and
a Custom book
Data complexTypes in an XML schema
Provider
Chapter 14 - Developing Database Web Applications using ASP.NET
You can now see the XML code for this schema by clicking the left-bottom XML button (see Figure 6-16).
Chapter 15 - Using ADO.NET in Xml Web Services
Chapter 16 - ASP.NET Server Controls and Data Binding
Chapter 17 - Building Real-World Web Applications
Chapter 18 - Object-Relational Mapping in .NET
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
Chapter 20 - COM Interoperability and ADO.NET
Chapter 21 - Messaging
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Appendix A - Relational Databases: Some Basic Concepts
Appendix B - Commonly Used SQL Statements
Appendix C - ADO.NET Frequently Asked Questions
Index
List of Figures
List of Tables
List of Listings
List of Sidebars
You just saw how the VS .NET Integrated Development Environment (IDE) provides a tool to design your
custom schema.
Table of Contents
Applied ADO.NETBuilding Data-Driven Solutions
Introduction
Chapter 1 - ADO.NET Basics
Chapter 2 - Data Components in Visual Studio .NET
Chapter 3 - ADO.NET in Disconnected Environments
Chapter 4 - ADO.NET in Connected Environments
Chapter 5 - Handling ADO.NET Events
Chapter 6 - Integrating XML with ADO.NET
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
Chapter 8 - Constraints and Data Relations
Chapter 9 - ADO.NET Exception Handling
Chapter 10 - Working with the ODBC .NET Data Provider
Chapter 11 - Stored Procedures and Views
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Chapter 13 - Developing a Custom Data Provider
Chapter 14 - Developing Database Web Applications using ASP.NET
Chapter 15 - Using ADO.NET in Xml Web Services
Chapter 16 - ASP.NET Server Controls and Data Binding
Chapter 17 - Building Real-World Web Applications
Chapter 18 - Object-Relational Mapping in .NET
Chapter 19 - 6-17:
Figure Mapped Objects:
XML Performance Considerations
designergenerated schema and Data Binding
Chapter 20 - COM Interoperability and ADO.NET
Chapter 21 - Messaging
Listing 6-28 shows the generated XML code.
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Appendix A - Relational
Listing 6-28: The XML Databases:
Schema Some Basic Concepts
Generated for a Database Table
Appendix B - Commonly Used SQL Statements
Appendix C - ADO.NET Frequently Asked Questions
<?xml version="1.0" encoding="utf-8" ?>
Index
<xs:schema id="XMLSchema1" targetNamespace=
List of Figures
"http://tempuri.org/XMLSchema1.xsd"
List of Tables
elementFormDefault="qualified"
List of Listings
xmlns="http://tempuri.org/XMLSchema1.xsd"
List of Sidebars
xmlns:mstns="http://tempuri.org/XMLSchema1.xsd"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xs:element name="Document">
<xs:complexType>
<xs:choice maxOccurs="unbounded">
<xs:element name="Employees">
<xs:complexType>
<xs:sequence>
<xs:element name="EmployeeID" msdata:ReadOnly="true"
msdata:AutoIncrement="true" type="xs:int" />
<xs:element name="LastName" type="xs:string" />
<xs:element name="FirstName" type="xs:string" />
Applied ADO.NET:
<xs:element name="Title" Building Data-DrivenminOccurs="0"
type="xs:string" Solutions />
by Mahesh Chand and David Talbot
<xs:element name="TitleOfCourtesy" type="xs:string" ISBN:1590590732
minOccurs="0" />
Apress 2003 (928 pages) type="xs:dateTime" minOccurs="0" />
<xs:element name="BirthDate"
This text provides extensive
<xs:element name="HireDate" coverage of ADO.NET minOccurs="0"
type="xs:dateTime" technology />
including ADO.NET internals, namespaces,
<xs:element name="Address" type="xs:string" minOccurs="0" classes, and />
interfaces, and takes a comprehensive look at XML
<xs:element name="City"
namespaces and type="xs:string" minOccurs="0"
classes, and how to integrate both with />
<xs:element name="Region"
ADO.NET. type="xs:string" minOccurs="0" />
<xs:element name="PostalCode" type="xs:string" minOccurs="0" />
<xs:element name="Country" type="xs:string" minOccurs="0" />
Table of Contents name="HomePhone" type="xs:string" minOccurs="0" />
<xs:element
Applied ADO.NETBuilding
<xs:element Data-Driven Solutions
name="Extension" type="xs:string" minOccurs="0" />
Introduction
<xs:element name="Photo" type="xs:base64Binary" minOccurs="0" />
Chapter 1 - ADO.NET
<xs:element Basics
name="Notes" type="xs:string" minOccurs="0" />
Chapter 2 - Data name="ReportsTo"
<xs:element Components in Visual Studio .NET
type="xs:int" minOccurs="0" />
<xs:element
Chapter name="PhotoPath"
3 - ADO.NET type="xs:string" minOccurs="0" />
in Disconnected Environments
</xs:sequence>
Chapter 4 - ADO.NET in Connected Environments
</xs:complexType>
Chapter 5 - Handling ADO.NET Events
</xs:element>
Chapter 6 - Integrating XML with ADO.NET
</xs:choice>
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
</xs:complexType>
Chapter 8 - Constraints and Data Relations
<xs:unique name="DocumentKey1" msdata:PrimaryKey="true">
Chapter 9 - ADO.NET Exception Handling
<xs:selector xpath=".//mstns:Employees" />
Chapter 10 - Working with the ODBC .NET Data Provider
<xs:field xpath="mstns:EmployeeID" />
Chapter 11 - Stored Procedures and Views
</xs:unique>
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
</xs:element>
Chapter 13 - Developing a Custom Data Provider
</xs:schema>
Chapter 14 - Developing Database Web Applications using ASP.NET
Chapter 15 - Using ADO.NET in Xml Web Services
Chapter 16 - ASP.NET Server Controls and Data Binding
Chapter 17 - Building Real-World Web Applications
Generating a Typed DataSet from a Schema
Chapter 18 - Object-Relational Mapping in .NET
Chapter 19 generate
Now let's - Mapped aObjects: Performance
typed DataSet Considerations
from and just
the schema you Dataadded
Binding
to the XML designer. The Generate
Chapter 20 - COM Interoperability and ADO.NET
Dataset option generates a typed DataSet for an XML schema. You can find the Generate Dataset option
Chapter 21 - Messaging
after right-clicking on the XML designer.
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
This action
Appendix A - generates a DataSetSome
Relational Databases: classBasic
and Concepts
adds it to your project. If you look in your Class View, you see
theDocument
Appendix class derives
B - Commonly fromStatements
Used SQL a DataSet and its members. The Document class looks like Figure 6-
18 in theCClass
Appendix Wizard.
- ADO.NET Frequently Asked Questions
Index
List of Figures
List of Tables
List of Listings
List of Sidebars
Applied ADO.NET: Building Data-Driven Solutions
by Mahesh Chand and David Talbot ISBN:1590590732
Apress 2003 (928 pages)
This text provides extensive coverage of ADO.NET technology
including ADO.NET internals, namespaces, classes, and
interfaces, and takes a comprehensive look at XML
namespaces and classes, and how to integrate both with
ADO.NET.
Table of Contents
Applied ADO.NETBuilding Data-Driven Solutions
Introduction
Chapter 1 - ADO.NET Basics
Chapter 2 - Data Components in Visual Studio .NET
Chapter 3 - ADO.NET in Disconnected Environments
Chapter 4 - ADO.NET in Connected Environments
Chapter 5 - Handling ADO.NET Events
Chapter 6 - Integrating XML with ADO.NET
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
Chapter 8 - Constraints and Data Relations
Chapter 9 - ADO.NET Exception Handling
Chapter 10 - Working with the ODBC .NET Data Provider
Chapter 11 - Stored Procedures and Views
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Chapter 13 - Developing a Custom Data Provider
Chapter 14 - Developing Database Web Applications using ASP.NET
Chapter 15 - Using ADO.NET in Xml Web Services
Figure
Chapter 16 - 6-18: TheServer
ASP.NET DataSet-derived class Binding
Controls and Data in the Class View
Chapter 17 - Building Real-World Web Applications
Chapter 18 - Object-Relational Mapping in .NET
Note The Generate Dataset option may not generate a DataSet if an XML schema isn't designed
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
properly.
Chapter 20 - COM Interoperability and ADO.NET
Once you
Chapter 21 -have a DataSet object, you can use it in any way you want.
Messaging
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Appendix A - Relational Databases: Some Basic Concepts
Appendix B - Commonly Used SQL Statements
Appendix C - ADO.NET Frequently Asked Questions
Index
List of Figures
List of Tables
List of Listings
List of Sidebars
Summary Applied ADO.NET: Building Data-Driven Solutions
by Mahesh Chand and David Talbot ISBN:1590590732
In this chapter, you learned
Apress the(928
2003 basics
pages)of System.Xml and it related namespaces and how XML is
represented in .NET through classes such ascoverage
This text provides extensive XmlNode, XmlAttribute,
of ADO.NET technology
including ADO.NET internals, namespaces, classes, and
XmlElement, and and takesYou
XmlDocument.
interfaces, also learned how
a comprehensive look to
at read
XML and write to these structures using the
XmlReader and namespaces
XmlWriterand classes. Also
classes, anddiscussed was theboth
how to integrate navigation
with in an XML node structure using
ADO.NET.
XmlPathNavigator. Most importantly, you learned how XML applies to ADO.NET and how to use a
DataSet to read and write data with XML. VS .NET provides the XML designer to work with XML. Using
the XML designer, you can generate XML schemas, which later can be used to generate typed DataSets.
Table of Contents
Applied
VS .NET ADO.NETBuilding Data-Driven
provides a rich set Solutions
of data-bound controls, which are very flexible and useful. In the next chapter,
Introduction
you'll see how to take advantage of VS .NET databound controls to write database applications.
Chapter 1 - ADO.NET Basics
Chapter 2 - Data Components in Visual Studio .NET
Chapter 3 - ADO.NET in Disconnected Environments
Chapter 4 - ADO.NET in Connected Environments
Chapter 5 - Handling ADO.NET Events
Chapter 6 - Integrating XML with ADO.NET
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
Chapter 8 - Constraints and Data Relations
Chapter 9 - ADO.NET Exception Handling
Chapter 10 - Working with the ODBC .NET Data Provider
Chapter 11 - Stored Procedures and Views
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Chapter 13 - Developing a Custom Data Provider
Chapter 14 - Developing Database Web Applications using ASP.NET
Chapter 15 - Using ADO.NET in Xml Web Services
Chapter 16 - ASP.NET Server Controls and Data Binding
Chapter 17 - Building Real-World Web Applications
Chapter 18 - Object-Relational Mapping in .NET
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
Chapter 20 - COM Interoperability and ADO.NET
Chapter 21 - Messaging
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Appendix A - Relational Databases: Some Basic Concepts
Appendix B - Commonly Used SQL Statements
Appendix C - ADO.NET Frequently Asked Questions
Index
List of Figures
List of Tables
List of Listings
List of Sidebars
Chapter Applied
7: Data Binding and Windows
ADO.NET: Building Data-Driven Solutions
by Mahesh Chand and David Talbot ISBN:1590590732
Forms Data-
Bound Controls
Apress 2003 (928 pages)
This text provides extensive coverage of ADO.NET technology
When it comes toincluding ADO.NET
developing internals,
interactive namespaces,
database classes,
applications, it'sand
difficult to resist using data-bound
interfaces, and takes a comprehensive look at XML
controls. Data-bound controls are easy to use, and they also provide
namespaces and classes, and how to integrate both with
many handy, built-in features. You
usedDataGrid,ListBox,
ADO.NET. and other data-bound controls in the previous chapters. In this chapter, we
discuss the basics of data binding, how to use data-bound controls, and how to develop interactive
database applications using these controls with a minimal amount of time and effort.
Table of Contents
Both Windows
Applied Forms andData-Driven
ADO.NETBuilding Web Forms provide a rich set of data-bound controls, which help developers
Solutions
build data-driven Windows and Web applications. In this chapter, we concentrate on Windows Forms.
Introduction
Chapter
Chapter 1 16 covers data
- ADO.NET binding in Web Forms.
Basics
Chapter 2 - Data Components in Visual Studio .NET
Understanding
Chapter 3 Data Binding
- ADO.NET in Disconnected Environments
Chapter 4 - ADO.NET in Connected Environments
So what are
Chapter 5
data-bound controls? You've already seen the DataGrid and ListBox controls in the
- Handling ADO.NET Events
previous chapters. You used these controls to display data from a data source. Data-bound controls are
Chapter 6 - Integrating XML with ADO.NET
Windows controls that represent and manipulate data in Graphical User Interface (GUI) forms. Both
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
Windows Forms and Web Forms provide a variety of flexible and powerful data-bound controls. These
Chapter 8 - Constraints and Data Relations
data-bound controls vary from a TextBox to a DataGrid.
Chapter 9 - ADO.NET Exception Handling
Chapter 10 - Working
The process witha the
of binding dataODBC .NET data
source's Data to
Provider
GUI controls is called data binding. Most of the editable
Chapter
Windows11 controls
- Stored provide
Proceduresdataand Views either directly or indirectly. These controls contain members that
binding,
connect
Chapter 12directly to aSQLXML,
- Oracle, data source, and then
and Other .NET the
Datacontrol takes care of displaying the data and other details.
Providers
For example,
Chapter to view data
13 - Developing in a DataGrid
a Custom control, you just need to set its DataSource property to a data
Data Provider
source.14
Chapter This data source
- Developing could be
Database a DataSet,
Web DataView,
Applications array, collection, or other data source. Data-
using ASP.NET
bound controls
Chapter can
15 - Using display in
ADO.NET data,
Xml and
Webthey are smart enough to display properties (metadata) of the stored
Services
data such
Chapter 16 -as data relations.
ASP.NET Server Controls and Data Binding
Chapter 17 - Building Real-World Web Applications
You can divide data binding into two categories: simple data binding and complex data binding. In simple
Chapter 18 - Object-Relational Mapping in .NET
data binding, a control displays data provided by a data feed. In fact, the control itself is not capable of
Chapter 19 -complex
displaying Mapped data.
Objects: Performance
Setting the TextConsiderations
property of a and Data Binding
TextBox or Label control is an example of
Chapter 20 - COM Interoperability and ADO.NET
simple data binding. Complex data binding, on the other hand, allows controls to bind to multiple columns
Chapter 21 - Messaging
and complex data. Binding an entire database table or multiple columns of a database table to a
Chapter 22 - or
DataGrid SQL Server andcontrol
a ListBox ADO.NET: Notes
is an on Performance
example of complex data binding.
Appendix A - Relational Databases: Some Basic Concepts
Appendix B - Commonly Used SQL Statements
Using the Binding Class
Appendix C - ADO.NET Frequently Asked Questions
Index
TheBinding class, defined in the System.Windows.Forms namespace, represents simple binding
List of Figures
between the data source item and a control.
List of Tables
Constructing
List of Listings a Binding Object
List of Sidebars
TheBinding class constructor, which creates an instance of the Binding class, takes three arguments:
a data-bound control's property name, a data source as an Object, and a data member, usually the
name of the data source columns as a string. You define the Binding class constructor as follows:
Listing 7-3 counts the total number of Binding objects associated with a control and removes the
Binding objects from various controls.
If (TextBox1.DataBindings(0).IsBinding) Then
Dim ds As DataSet = _
CType(TextBox1.DataBindings(0).DataSource, DataSet)
str = "DataSource : " + ds.Tables(0).TableName
str += ", Property Name: " + _
Applied ADO.NET: Building Data-Driven Solutions
TextBox1.DataBindings(0).PropertyName
by Mahesh Chand and David Talbot
MessageBox.Show(str) ISBN:1590590732
Note To test this code, you need to create a DataSet from the Employees table of the Northwind
database and use it as a data source when constructing a Binding object. Also, don't forget to
add a reference to the System.Globalization namespace because the NumberStyle
enumeration is defined in this namespace.
Answers
Table of Contents
Applied ADO.NETBuilding Data-Driven Solutions
IntroductionA: Have you ever developed database applications in Visual Basic 6.0 or Microsoft
Chapter 1 - ADO.NET Basics Classes (MFC)? In both of those languages, a data-bound control lets you
Foundation
Chapter 2 - Data Components in Visual
navigate through dataStudio
from .NET
one record to another and update data in the controls
Chapter 3 - ADO.NET in Disconnected
available Environments
on the form. As you move to the next record, the next row was fetched from the
Chapter 4 datainsource
- ADO.NET and every
Connected control was updated with the current row's data. This process is
Environments
Chapter 5 called
- Handling data synchronization.
ADO.NET Events
Chapter 6 - Integrating XML with ADO.NET
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
Chapter 8 - Constraints and Data Relations
Chapter
OK, now9 let's
- ADO.NET Exception
say a form Handling
has three controls: a TextBox, a Label, and a PictureBox. All three controls
Chapter 10 - Working with the ODBC
support data binding from a DataSet, .NET which
Data Provider
is filled with the data from the Employees table. The
Chapter
TextBox11 -control
Storeddisplays
Procedures and Views the Label control displays LastName, and the PictureBox
FirstName,
Chapter
control displays Photo propertiesOther
12 - Oracle, SQLXML, and .NET Data
(columns) Providers
of the DataSet. All of the controls must be synchronized in
Chapter
order to13display
- Developing a Custom
the correct Data Provider
first name, last name, and photo for the same employee.
Chapter 14 - Developing Database Web Applications using ASP.NET
CurrencyManager
Chapter accomplishes
15 - Using ADO.NET thisServices
in Xml Web synchronization by maintaining a pointer to the current item for the
list. All 16
Chapter controls are bound
- ASP.NET Serverto the current
Controls item Binding
and Data so they display the information for the same row. When the
current item changes, CurrencyManager notifies all the bound controls so that they can refresh their
Chapter 17 - Building Real-World Web Applications
data. Furthermore, you can set the Position property to specify the row in the DataSet or DataTable
Chapter 18 - Object-Relational Mapping in .NET
to which the controls point. Figure 7-1 shows the synchronization process.
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
Chapter 20 - COM Interoperability and ADO.NET
Chapter 21 - Messaging
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Appendix A - Relational Databases: Some Basic Concepts
Appendix B - Commonly Used SQL Statements
Appendix C - ADO.NET Frequently Asked Questions
Index
List of Figures
List of Tables
Figure 7-1: Synchronization between a data source and data-bound controls
List of Listings
List of Sidebars
Using the BindingManagerBase Class Members
As you learned, the Binding property returns the collection of binding objects as a
BindingsCollection object that BindingManagerBase manages. Listing 7-7 creates a
BindingManagerBase object for the form and reads all of the binding controls.
You create a CurrencyManager object by using the BindingContext object, which returns either
CurrencyManager or PropertyManager, depending on the value of the data source and data
members passed to the Item property of BindingContext. If the data source is an object that can only
Applied
return a single property ADO.NET:
(instead of a Building Data-Driven
list of objects), the typeSolutions
will be PropertyManager. For example, if
by Mahesh Chand and David Talbot
you specify a TextBoxcontrol as the data source, PropertyManager ISBN:1590590732
will be returned. If the data
Apress 2003 (928 pages)
source is an object that implements IList,IListSource, or IBindingList, such as a DataSet,
This text or
DataTable,DataView, provides extensive
an Array, coverage of ADO.NET
CurrencyManager technology
will be returned.
including ADO.NET internals, namespaces, classes, and
You can create ainterfaces, and takes a comprehensive
CurrencyManager lookas
from objects such at aXML
DataView and vice versa. For example,
namespaces and classes, and how to integrate both with
the following code creates
ADO.NET.
a CurrencyManager from a DataView and a DataView from a
CurrencyManager:
Table
Dim ofdv
Contents
As DataView
Applied
dv = ADO.NETBuilding Data-Driven Solutions
New DataView(ds.Tables("Customers"))
Introduction
Dim curManager1 As CurrencyManager = DataGrid1.BindingContext(dv)
Chapter 1 - ADO.NET
Dim list Basics
As IList = curManager1.List
Chapter
Dim dv12 -As
Data Components
DataView = inCType(curManager1.List,
Visual Studio .NET DataView)
Chapter 3 - ADO.NET inAs
Dim curManager2 Disconnected Environments
CurrencyManager = Me.BindingContext(ds1)
Chapter 4 - ADO.NET in Connected Environments
Chapter 5 - Handling ADO.NET Events
Unlike CurrencyManager,PropertyManager doesn't provide any additional members besides the
Chapter 6 - Integrating XML with ADO.NET
members provided by its base class, BindingManagerBase.
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
Chapter 8 - Constraints and Data Relations
Understanding
Chapter 9 BindingContext
- ADO.NET Exception Handling
Chapter 10 - Working with the ODBC .NET Data Provider
Each object inherited from the Control class has a BindingContext object attached to it.
Chapter 11 - Stored Procedures and Views
BindingContext manages the collection of BindingManagerBase objects for that object such as a
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
form. The BindingContext creates the CurrencyManager and PropertyManager objects, which
Chapter 13 - Developing a Custom Data Provider
were discussed previously. Normally you use the Form class's BindingContext to create a
Chapter 14 - Developingand
CurrencyManager Database Web Applications
PropertyManager forusing ASP.NET
a form and its controls, which provide data
Chapter 15 - Using
synchronization. ADO.NET in Xml Web Services
Chapter 16 - ASP.NET Server Controls and Data Binding
TheItem
Chapter 17 property
- Buildingof BindingContext
Real-World returns the BindingManagerBase (either
Web Applications
CurrencyManager
Chapter or PropertyManager).
18 - Object-Relational Mapping in .NET The Contains methods returns True if it contains the
specified
Chapter 19BindingManagerBase.
- Mapped Objects: Performance Considerations and Data Binding
Chapter 20 - COM Interoperability and ADO.NET
Besides the Item and Contains members, the BindingContext has three protected methods: Add,
Chapter 21 - Messaging
Clear, and Remove. The Add method adds a BindingManagerBase to the collection, the Clear
Chapter
method22removes
- SQL Server andin
all items ADO.NET: Notes on
the collection, andPerformance
the Remove method deletes the BindingManagerBase
Appendix
associated with the specified data source. Concepts
A - Relational Databases: Some Basic
Appendix B - Commonly Used SQL Statements
Appendix C - ADO.NET Frequently Asked Questions
Building a Record Navigation System
Index
List
Now of let's
Figures
see data binding in action. In this section, you'll develop an application that provides data
List of Tables
synchronization. In this application, you'll build a record navigation system. The controls will display
List of Listings
records, and then when you click the Move Next, Move Last, Move Previous, and Move First buttons, the
List of Sidebars
controls will display the respective records.
To begin, create a Windows application and design a form that looks like Figure 7-2. For this example, you
don't have to place the ReadBindingMemberInfo and Remove controls. Add a ComboBox control, two
TextBox controls, a ListBox control, some Label controls, and some Button controls. The Load
Data button loads data to the controls and attaches Binding objects to the BindingContext. You
should also add four buttons with brackets as the text (<<, <, >, >>), which represents the Move First, Move
Previous, Move Next, and Move Last records.
Applied ADO.NET: Building Data-Driven Solutions
by Mahesh Chand and David Talbot ISBN:1590590732
Apress 2003 (928 pages)
This text provides extensive coverage of ADO.NET technology
including ADO.NET internals, namespaces, classes, and
interfaces, and takes a comprehensive look at XML
namespaces and classes, and how to integrate both with
ADO.NET.
Table of Contents
Applied ADO.NETBuilding Data-Driven Solutions
Introduction
Chapter 1 - ADO.NET Basics
Chapter 2 - Data Components in Visual Studio .NET
Chapter 3 - ADO.NET in Disconnected Environments
Chapter 4 - ADO.NET in Connected Environments
Figure 7-2: Record navigation form
Chapter 5 - Handling ADO.NET Events
Chapter 6 You
Note - Integrating XML
can create withown
your ADO.NET
form, but to save you some time, you can download the code from the
Chapter 7 Apress
- Data Binding and Windows
(www.apress.com) or Forms Data-Bound
C# Corner Controls
(www.c-sharpcorner.com) Web sites. Open the project
Chapter 8 in
- Constraints and.NET
Visual Studio Data(VS
Relations
.NET) to understand it better.
Chapter 9 - ADO.NET Exception Handling
As usual,
Chapter 10 first you add
- Working some
with variables
the ODBC .NETtoData
the project,
Provider which shown in Listing 7-8. Don't forget to change
your server
Chapter name; Procedures
11 - Stored the server name in this example is MCB.
and Views
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Listing 7-8: Record Navigation System Variables
Chapter 13 - Developing a Custom Data Provider
Chapter 14 - Developing Database Web Applications using ASP.NET
Private ConnectionString As String = "Integrated Security=SSPI;" & _
Chapter 15 - Using ADO.NET in Xml Web Services
"Initial Catalog=Northwind;Data Source=MCB;"
Chapter 16 - ASP.NET Server Controls and Data Binding
Private conn As SqlConnection = Nothing
Chapter 17 - Building Real-World Web Applications
Private sql As String = Nothing
Chapter 18 - Object-Relational Mapping in .NET
Private adapter As SqlDataAdapter = Nothing
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
Private ds As DataSet = Nothing
Chapter 20 - COM Interoperability and ADO.NET
Chapter 21 - Messaging
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Second,Ayou
Appendix call the LoadData
- Relational Databases: method on the
Some Basic Load Data button click:
Concepts
Appendix B - Commonly Used SQL Statements
Appendix
Private C -Sub
ADO.NET Frequently Asked Questions
LoadBtn_Click(ByVal sender As System.Object, _
Index
ByVal e As System.EventArgs) Handles LoadBtn.Click
List of Figures
LoadData()
List
End of Tables
Sub
List of Listings
List of Sidebars
Listing 7-9 shows the LoadData and GetDataSet methods. The GetDataSet method returns a
DataSet object from the table name passed in the method. The LoadData method creates bindings for
these controls with different DataTable columns.
Table of Contents
Applied ADO.NETBuilding Data-Driven Solutions
Introduction
Chapter 1 - ADO.NET Basics
Chapter 2 - Data Components in Visual Studio .NET
Chapter 3 - ADO.NET in Disconnected Environments
Chapter 4 - ADO.NET in Connected Environments
Chapter 5 - Handling ADO.NET Events
Chapter 6 - Integrating XML with ADO.NET
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
Chapter 8 - Constraints and Data Relations
Chapter 9 - ADO.NET Exception Handling
Chapter 10 - Working with the ODBC .NET Data Provider
Figure 7-3: Record navigation system in action
Chapter 11 - Stored Procedures and Views
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Question and Answer
Chapter 13 - Developing a Custom Data Provider
Chapter 14 - Developing Database Web Applications using ASP.NET
Chapter 15 -Q: When
Using I click the
ADO.NET move
in Xml buttons,
Web ServicesI don't see the pointer in the ListBox moving. Why
not? Server Controls and Data Binding
Chapter 16 - ASP.NET
Chapter 17 - Building Real-World Web Applications
Chapter 18 Answers
- Object-Relational Mapping in .NET
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
Chapter 20 - COM Interoperability and ADO.NET
A: TheListBox control doesn't use the same binding method as simple data-bound
Chapter 21 - Messaging
controls such as TextBox or Label controls. We discuss this in the following section.
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Appendix A - Relational Databases: Some Basic Concepts
Appendix B - Commonly Used SQL Statements
Appendix C - ADO.NET Frequently Asked Questions
You just saw how to implement a record navigation system using simple data binding and simple data-
Index
bound
List controls. In the following section, we show you how to build a record navigation system using
of Figures
complex data-bound controls such as ListBox and DataGrid controls.
List of Tables
List of Listings
List of Sidebars
Working with Complex
Applied ADO.NET:Data-Bound Controls
Building Data-Driven Solutions
by Mahesh Chand and David Talbot ISBN:1590590732
Unlike simple data-bound controls,
Apress 2003 the complex data-bound controls can display a set of data such as a
(928 pages)
single column or This
a collection of columns. The
text provides extensive controlsofsuch
coverage as DataGrid
ADO.NET technologyare even able to display data
from multiple tables
including ADO.NET internals, namespaces, classes, andcontrols usually use their Text
of a database. Whereas the simple data-bound
interfaces,
properties for binding, and data-bound
complex takes a comprehensive look
controls use at XML
their DataSource and DataMember properties.
namespaces and classes, and how to integrate both with
ADO.NET.
In the following sections, we discuss some of the common complex data-bound controls such as the
ComboBox,ListBox, and DataGrid.
Table of Contents
The Role of Control Class in Data Binding
Applied ADO.NETBuilding Data-Driven Solutions
Introduction
TheControl
Chapter 1
class is the mother of all Windows controls. This class's basic functionality is required by
- ADO.NET Basics
visual Windows controls that are available from the Toolbox or through other wizards. The Control class
Chapter 2 - Data Components in Visual Studio .NET
handles user input through the keyboard, the mouse, and other pointing devices. It also defines the
Chapter 3 - ADO.NET in Disconnected Environments
position and size of controls; however, it doesn't implement painting.
Chapter 4 - ADO.NET in Connected Environments
Chapter 5 - Handling
If you count ADO.NET
the Control classEvents
members, you'll find that this class is one of the biggest classes available
Chapter 6 - Integrating XML with
in the .NET Framework Library. In ADO.NET
the following sections, you'll explore some of the data-binding
Chapter 7 - Data
functionality Binding and
implemented byWindows Forms Data-Bound Controls
this class.
Chapter 8 - Constraints and Data Relations
TheControl
Chapter 9
class provides two important and useful properties, which play a vital role in the data-
- ADO.NET Exception Handling
binding process. These properties are BindingContext and DataBinding. The BindingContext
Chapter 10 - Working with the ODBC .NET Data Provider
property represents the BindingContext attached to a control. As discussed earlier, BindingContext
Chapter 11 - Stored Procedures and Views
returns a single BindingManagerBase object for all data-bound controls. The BindingManagerBase
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
object provides the synchronization for all data-bound controls. The Control class also implements the
Chapter 13 - Developing a Custom Data Provider
DataSourceChanged event, which raises when the data source of a control is changed. We discuss this
Chapter 14 - Developing Database Web Applications using ASP.NET
event in more detail shortly.
Chapter 15 - Using ADO.NET in Xml Web Services
Chapter 16 - ASP.NET Server Controls and Data Binding
Using the ListControl Class
Chapter 17 - Building Real-World Web Applications
Chapter 18 - Object-Relational
TheListControl Mapping
class is the in .NET
base class for ListBox and ComboBox controls and implements the
Chapter 19 - Mapped
data-binding Objects:
functionality. Performance
The Considerations
ListControl and Data
class provides fourBinding
data-binding properties: DataManager,
Chapter 20 - COM
DataSource, Interoperability and
DisplayMember, andADO.NET
ValueMember.
Chapter 21 - Messaging
TheDataManager
Chapter (read-only)
22 - SQL Server property
and ADO.NET: returns
Notes the CurrencyManager object associated with a
on Performance
ListControl
Appendix class.Databases: Some Basic Concepts
A - Relational
Appendix B - Commonly Used SQL Statements
TheDataSource property (both get and set) represents the data source for a ListControl class.
Appendix C - ADO.NET Frequently Asked Questions
Index
TheDisplayMember (both get and set) represents a string, which specifies the property of a data source
whose
List contents you want to display. For example, if you want to display the data of a DataTable's Name
of Figures
column
List in a ListBox control, you set DisplayMember ="Name".
of Tables
List of Listings
TheValueMember (both get and set) property represents a string, which specifies the property of the
List of Sidebars
data source from which to draw the value. The default value of this property is an empty string ("").
Listing 7-16: Setting the DataSource and DataMember Properties of a DataGrid Control
Table of Contents
Applied
ds = ADO.NETBuilding
New DataSet() Data-Driven Solutions
Introduction
sql = "SELECT * FROM Customers"
Chapter 1 - ADO.NET
ds = New Basics
DataSet()
Chapter
adapter2 -=Data
NewComponents in Visual Studio .NET
SqlDataAdapter(sql, conn)
adapter.Fill(ds)
Chapter 3 - ADO.NET in Disconnected Environments
DataGrid1.DataSource
Chapter = dsEnvironments
4 - ADO.NET in Connected
DataGrid1.DataMember
Chapter 5 - Handling ADO.NET=Events
"Customers"
Chapter 6 - Integrating XML with ADO.NET
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
Chapter 8 - Constraints and Data Relations
You can also set the DataSource and DataMember properties by using the DataGrid control's
Chapter 9 - ADO.NET Exception Handling
SetDataBinding method. This method takes the first argument as a dataSource and the second
Chapter 10 - Working with the ODBC .NET Data Provider
argument as a dataMember. Typically, a data source is a DataSet, and the dataMember is the name of
Chapter
a table 11 - StoredinProcedures
available and Views
the DataSet. The following code shows how to call the SetDataBinding method of
Chapter 12 - Oracle,
aDataGrid control: SQLXML, and Other .NET Data Providers
Chapter 13 - Developing a Custom Data Provider
Chapter 14 - Developing Database Web Applications using ASP.NET
DataGrid1.SetDataBinding(ds, "Customers")
Chapter 15 - Using ADO.NET in Xml Web Services
Chapter 16 - ASP.NET Server Controls and Data Binding
You'll use
Chapter 17 -the
Building control
Real-World
DataGrid Weband its members throughout this chapter.
Applications
Chapter 18 - Object-Relational Mapping in .NET
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
Deleting Data Binding
Chapter 20 - COM Interoperability and ADO.NET
Chapter 21 -data
Removing Messaging
binding from a data-bound control is simple. The following code snippet deletes data
binding22
Chapter from a DataGrid
- SQL Server and control:
ADO.NET: Notes on Performance
Appendix A - Relational Databases: Some Basic Concepts
Appendix B - Commonly Used SQL
DataGrid1.DataSource Statements
= null;
Appendix C - ADO.NET Frequently
DataGrid1.DataMember Asked Questions
= "";
Index
List of Figures
List of Tables
List of Listings
List of Sidebars
The DataGrid: Super
Applied Data-Bound
ADO.NET: Control
Building Data-Driven Solutions
by Mahesh Chand and David Talbot ISBN:1590590732
TheDataGrid control
Apressis one
2003 of the
(928 most flexible and versatile controls in Windows Forms. In this section,
pages)
we discuss someThis
of the DataGrid functionality.
text provides extensive coverage of ADO.NET technology
including ADO.NET internals, namespaces, classes, and
TheDataGrid class represents
interfaces, the DataGrid
and takes controllook
a comprehensive in Windows
at XML Forms. Before writing any code, you'll
learn about the DataGrid
namespacesclass
and properties
classes, andand
howmethods. Figure
to integrate both7-6 shows a DataGrid's parent items
with
and background,ADO.NET.
and Figure 7-7 shows some of the DataGrid parts.
Table of Contents
Applied ADO.NETBuilding Data-Driven Solutions
Introduction
Chapter 1 - ADO.NET Basics
Chapter 2 - Data Components in Visual Studio .NET
Chapter 3 - ADO.NET in Disconnected Environments
Chapter 4 - ADO.NET in Connected Environments
Chapter 5 - Handling ADO.NET Events
Chapter 6 - Integrating XML with ADO.NET
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
Chapter 8 - Constraints and Data Relations
Chapter 9 - ADO.NET Exception Handling
Figure
Chapter 10 - 7-6: Thewith
Working the ODBCparent
DataGrid's itemsProvider
.NET Data and background
Chapter 11 - Stored Procedures and Views
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Chapter 13 - Developing a Custom Data Provider
Chapter 14 - Developing Database Web Applications using ASP.NET
Chapter 15 - Using ADO.NET in Xml Web Services
Chapter 16 - ASP.NET Server Controls and Data Binding
Chapter 17 - Building Real-World Web Applications
Chapter 18 - Object-Relational Mapping in .NET
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
Chapter 20 - COM Interoperability and ADO.NET
Chapter 21 - Messaging
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Appendix A - Relational Databases: Some Basic Concepts
Appendix B - Commonly Used SQL Statements
Appendix C - ADO.NET Frequently Asked Questions
Index
Figure 7-7: TheDataGrid's parts
List of Figures
List of Tables
Understanding the DataGrid Class Members
List of Listings
List of Sidebars
Like all other Windows controls, the DataGrid inherits from the Control class, which means that the
data-binding functionality defined in the Control class is available in the DataGrid control. Besides the
hundreds of members implemented in theControl class, the DataGrid provides many more members.
Table 7-2 describes the DataGrid class properties.
PROPERTY DESCRIPTION
AllowNavigation Indicates whether navigation is allowed. True or false. Both get
and set.
Indicates
AllowSortingApplied ADO.NET: whether
Building sorting isSolutions
Data-Driven allowed. True or false. Both get and
set.
by Mahesh Chand and David Talbot ISBN:1590590732
Apress 2003 (928Background
AlternatingBackColor pages) color of alternative rows.
This text provides extensive coverage of ADO.NET technology
BackColor including ADO.NETBackground color of the grid.
internals, namespaces, classes, and
interfaces, and takes a comprehensive look at XML
namespaces andColor
BackgroundColor of the
classes, and nonrow area of the
how to integrate grid.
both withThis is the background color
ADO.NET. if the grid has no rows.
BorderStyle Style of the border.
Table of Contents
CaptionBackColor Background color of caption.
Applied ADO.NETBuilding Data-Driven Solutions
CaptionFont
Introduction Font of caption.
Chapter 1 - ADO.NET Basics
CaptionForeColor Foreground color of caption.
Chapter 2 - Data Components in Visual Studio .NET
CaptionText
Chapter Caption
3 - ADO.NET in Disconnected text.
Environments
Chapter 4- ADO.NET in Connected Environments
CaptionVisible Indicates whether caption is visible.
Chapter 5 - Handling ADO.NET Events
ColumnHeadersVisible
Chapter Indicates whether column headers are visible.
6 - Integrating XML with ADO.NET
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
CurrentCell Returns current selected cell.
Chapter 8 - Constraints and Data Relations
CurrentRowIndex
Chapter Index of the selected row.
9 - ADO.NET Exception Handling
Chapter 10 - Working with the ODBC
DataMember .NET Data the
Represents Provider
data sources among multiple data sources. If
Chapter 11 - Stored Procedures andthere's
Views only one data source, such as a DataTable or a
Chapter 12 - Oracle, SQLXML, and Other .NET with
DataSet DataaProviders
single table, there's no need to set this property.
Chapter 13 - Developing a Custom Data
Both Provider
get and set.
Chapter 14 - Developing Database Web Applications using ASP.NET
DataSource Represents the data source such as a DataSet, a DataTable,
Chapter 15 - Using ADO.NET in Xml Web Services
or Ilist.
Chapter 16 - ASP.NET Server Controls and Data Binding
FirstVisibleColumn
Chapter Index
17 - Building Real-World Web of the first visible column.
Applications
Chapter 18 - Object-Relational Mapping in .NET
FlatMode FlatMode. Type of FlatMode enumeration.
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
ForeColor
Chapter Foreground
20 - COM Interoperability and ADO.NET color.
Chapter 21 - Messaging
GridLineColor Color of grid lines.
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
A - Relational Databases: Style
GridLineStyle
Appendix Someof gridConcepts
Basic lines.
Appendix B - Commonly Used SQL Statements
HeaderBackColor Background color of column headers.
Appendix C - ADO.NET Frequently Asked Questions
HeaderFont
Index Font of column headers.
ListHeaderForeColor
of Figures Foreground color of column headers.
List of Tables
ListItem
of Listings Value of the specified cell.
ListLinkColor
of Sidebars Color of the text that you can click to navigate to a child table.
LinkHoverColor Link color changes to when the mouse moves over it.
ParentRowBackColor Background color of parent rows. Parent rows are rows that allow
you to move to child tables.
ParentRowForeColor Foreground color of parent rows.
ParentRowLabelStyle Label style of parent rows.
ParentRowsVisible Indicates whether parent rows are visible.
PreferredColumnWidth Default width of columns in pixel.
PreferredRowHeight Default
Applied ADO.NET: heightData-Driven
Building of rows in pixels.
Solutions
ReadOnly by Mahesh Chand and David
Indicates Talbot grid is readISBN:1590590732
whether only.
Apress 2003 (928 pages)
RowHeaderVisible Indicates
This text provides whether
extensive rowofheader
coverage is visible.
ADO.NET technology
including ADO.NET internals, namespaces, classes, and
RowHeaderWidth Widtha of
interfaces, and takes row headers.look at XML
comprehensive
namespaces and classes, and how to integrate both with
SelectionBackColor
ADO.NET.
Background color of selected rows.
SelectionForeColor Foreground color of selected rows.
Table of Contents
TableStyles Table style. DataGridTableStyle type.
Applied ADO.NETBuilding Data-Driven Solutions
VisibleColumnCount Total number of visible columns.
Introduction
Chapter 1 - ADO.NET Basics
VisibleRowCount Total number of visible rows.
Chapter 2 - Data Components in Visual Studio .NET
HorizScrollBar Protected. Returns the horizontal scroll bar of the grid.
Chapter 3 - ADO.NET in Disconnected Environments
4 - ADO.NET in ConnectedProtected.
VertScrollBar
Chapter Returns the horizontal scroll bar of the grid.
Environments
Chapter 5 - Handling ADO.NET Events
ListManager Protected. Returns the CurrencyManager of the grid.
Chapter 6 - Integrating XML with ADO.NET
Chapter 7
Table 7-3 -describes
Data Binding and Windows Forms Data-Bound Controls
the DataGrid class methods.
Chapter 8 - Constraints and Data Relations
Chapter 9 - The
Table 7-3: ADO.NET Exception
DataGrid Handling
Class Methods
Chapter 10 - Working with the ODBC .NET Data Provider
METHOD
Chapter 11 - Stored Procedures and Views DESCRIPTION
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
BeginEdit Starts the editing operation
Chapter 13 - Developing a Custom Data Provider
BeginInit
Chapter Begins theusing
14 - Developing Database Web Applications initialization
ASP.NETof grid that is used on a form or
used by other components
Chapter 15 - Using ADO.NET in Xml Web Services
Chapter 16 - ASP.NET Server Controls and Collapses
Collapse Data Binding
children if a grid has parent and child
Chapter 17 - Building Real-World Web Applications
relationship nodes expanded
Chapter 18 - Object-Relational Mapping in .NET
Chapter 19 - Mapped Objects: PerformanceEnds the editingand
operation
EndEdit Considerations Data Binding
Chapter 20 - COM Interoperability and ADO.NET
EndInit Ends grid initialization
Chapter 21 - Messaging
Expand Expands children if grid has children in a parent/child
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
relation
Appendix A - Relational Databases: Some Basic Concepts
Appendix B - Commonly Used SQL Statements
GetCurrentCellBounds Returns a rectangle that specifies the four corners of the
selected cell
Appendix C - ADO.NET Frequently Asked Questions
Index
HitTest Gets information when clicking on the grid
List of Figures
ListIsExpanded
of Tables True if node of the specified row is expanded; otherwise
List of Listings false
ListIsSelected
of Sidebars True if specified row is selected; otherwise false
NavigateBack Navigates to the table previously displayed in the grid
NavigateTo Navigates to the table specified by the row and relation
name
ResetAlternatingBackColor Resets the AlternatingBackColor property to the
default color
ResetBackColor Resets background color to default
ResetGridLineColor Resets grid lines color to default
ResetHeaderBackColor Resets header background to default
ResetHeaderFont ResetsData-Driven
Applied ADO.NET: Building header font Solutions
to default
by Mahesh Chand and David
ResetHeaderForeColor Talbot
Resets ISBN:1590590732
header foreground color to default
Apress 2003 (928 pages)
ResetLinkColor Resets
This text provides extensive link color
coverage to default
of ADO.NET technology
including ADO.NET internals, namespaces, classes, and
ResetSelectionBackColor Resets selection
interfaces, and takes a comprehensive background
look at XML color to default
namespaces and classes, and how to integrate both with
ResetSelectionForeColor
ADO.NET.
Resets selection foreground color to default
Select Selects a specified row
Table of Contents
SetDataBinding Sets the DataSource and DataMember properties
Applied ADO.NETBuilding Data-Driven Solutions
UnSelect Unselects a specified row
Introduction
Chapter 1 - ADO.NET Basics
Chapter
Besides2 the
- Data Components
methods in Visual
described Studio
in Table 7-3,.NET
the DataGrid class provides some protected methods (see
Chapter 3 - ADO.NET in Disconnected Environments
Table 7-4).
Chapter 4 - ADO.NET in Connected Environments
Chapter 5 - The
Table 7-4: Handling ADO.NET
DataGrid Events
Class Protected Methods
Chapter 6 - Integrating XML with ADO.NET
PROTECTED METHOD DESCRIPTION
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
Chapter 8 - Constraints and Data Relations
CancelEditing Cancels the current edit operation and rolls back
Chapter 9 - ADO.NET Exception Handling all changes
Chapter 10 - Working with the ODBC .NET Data Provider
GridHScrolled Listens for the horizontal scroll bar's scroll event
Chapter 11 - Stored Procedures and Views
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
GridVScrolled Listens for the vertical scroll bar's scroll event
Chapter 13 - Developing a Custom Data Provider
OnBackButtonClicked Listens for the caption's Back button clicked event
Chapter 14 - Developing Database Web Applications using ASP.NET
OnBorderStyleChanged
Chapter 15 - Using ADO.NET in Xml Web Services Raises the BorderStyleChanged event
Chapter 16 - ASP.NET Server Controls and Data Binding
OnCaptionVisibleChanged Raises the CaptionVisibleChanged event
Chapter 17 - Building Real-World Web Applications
OnDataSourceChanged
Chapter 18 - Object-Relational Mapping in .NET Raises the DataSourceChanged event
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
OnFlatModeChanged Raises the FlatModeChanged event
Chapter 20 - COM Interoperability and ADO.NET
OnNavigate
Chapter 21 - Messaging Raises the Navigate event
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
OnParentRowsLabelStyleChanged Raises the ParentRowsLabelStyleChanged
Appendix A - Relational Databases: Some Basic Concepts
event
Appendix B - Commonly Used SQL Statements
C - ADO.NET Frequently Asked Questions Raises the ParentRowsVisibleChanged
OnParentRowsVisibleChanged
Appendix
Index event
ListOnReadOnlyChanged
of Figures Raises the ReadOnlyChanged event
List of Tables
OnRowHeaderClick Raises the RowHeaderClick event
List of Listings
ListOnScroll
of Sidebars Raises the Scroll event
OnShowParentDetailsButtonClicked Raises the ShowParentDetailsButtonClick
event
ProcessGridKey Processes keys for grid navigation
ProcessTabKey Gets a value indicating whether the Tab key
should be processed
ResetSelection Turns off selection for all rows that are selected
Exploring the DataGrid
Applied HelperData-Driven
ADO.NET: Building ObjectsSolutions
by Mahesh Chand and David Talbot ISBN:1590590732
TheDataGrid class comes with 13 helper objects (classes, structures, and enumerations). What do we
Apress 2003 (928 pages)
mean by helper classes? Helper classes provide simple methods to access some of the more
This of
complicated aspects text provides
the extensive
DataGrid class.coverage of ADO.NET
These helper technology
objects are DataGrid.HitTestInfo, the
including ADO.NET internals, namespaces, classes, and
DataGrid.HitTestType enumeration, DataGridBoolColumn,
interfaces, and takes a comprehensive look at XML the DataGridCell structure,
DataGridColumnStyle,
namespaces DataGridColumnStyle.CompModSwitches,
and classes, and how to integrate both with the
ADO.NET.
DataGridColumnStype.DataGridColumnHeaderAccessibleObject DataGridLineStyle
enumeration, the DataGridParentRowsLabelStyle enumeration,
DataGridPreferredColumnWidthTypeConverter,DataGridTableStyle,DataGridTextBox,
Table of Contents
andDataGridTextBoxColumn. We discuss some of these objects in the following section. You'll see
Applied ADO.NETBuilding Data-Driven Solutions
the rest of them later in this chapter.
Introduction
Chapter 1 - ADO.NET Basics
Understanding
Chapter the inDataGrid
2 - Data Components Visual Studio and
.NET DataGrid Column Styles
Chapter 3 - ADO.NET in Disconnected Environments
TheDataGrid control hides much more functionality in it. Not only can it display data and data relations,
Chapter 4 - ADO.NET in Connected Environments
it also provides functionality to customize its styles including color, text, caption, and font. The
Chapter 5 - Handling
TableStyles ADO.NET
property Events opens the door for formatting a grid and its columns. The
of DataGrid
Chapter 6 - Integrating XML
GridStyles property returns anwith ADO.NET
object of GridTableStyleCollection, which is a collection of
Chapter 7 - Data Binding
DataGridTableStyle. and Windows Forms Data-Bound Controls
Chapter 8 - Constraints and Data Relations
DataGridTableStyle
Chapter represents
9 - ADO.NET Exception the style of a DataTable that can be viewed in the grid area of a
Handling
DataGrid.
Chapter The GridTableStyles
10 - Working with the ODBC .NETclass
Dataof DataGridTableStyle represents a collection of
Provider
DataGridColumnStyle.Figure 7-8 represents the relationship between the DataGrid-related style
Chapter 11 - Stored Procedures and Views
objects. We discuss these objects in more detail in the following sections.
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Chapter 13 - Developing a Custom Data Provider
Chapter 14 - Developing Database Web Applications using ASP.NET
Chapter 15 - Using ADO.NET in Xml Web Services
Chapter 16 - ASP.NET Server Controls and Data Binding
Chapter 17 - Building Real-World Web Applications
Chapter 18 - Object-Relational Mapping in .NET
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
Chapter 20 - COM Interoperability and ADO.NET
Chapter 21 - Messaging
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Appendix A - Relational Databases: Some Basic Concepts
Appendix B - Commonly Used SQL Statements
Appendix C - ADO.NET Frequently Asked Questions
Index
List of Figures
List of Tables
Figure 7-8: DataGrid-related style objects
List of Listings
List of Sidebars
Before you see these objects in action, you'll look at these object classes and their members briefly.
Table
You of
canContents
even create a DataGridTableStyle from a CurrencyManager.Listing 7-18 creates a
Applied ADO.NETBuilding Data-Driven
DataGridTableStyle Solutions
from a CurrencyManager and adds it the collection.
Introduction
Listing17-18:
Chapter Creating
- ADO.NET a DataGridTableStyle from CurrencyManager
Basics
Chapter 2 - Data Components in Visual Studio .NET
Chapter
Private3 -Sub
ADO.NET in Disconnected Environments
CreateNewDGTableStyle()
ChapterDim
4 -curManager
ADO.NET in Connected Environments
As CurrencyManager
ChapterDim
5 -newTableStyle As DataGridTableStyle
Handling ADO.NET Events
ChaptercurManager = XML
6 - Integrating CType
with _
ADO.NET
Chapter(Me.BindingContext(ds,
7 - Data Binding and Windows "Customers"), CurrencyManager)
Forms Data-Bound Controls
ChapternewTableStyle = Data
8 - Constraints and New Relations
DataGridTableStyle(curManager)
ChapterDataGrid1.TableStyles.Add(newTableStyle)
9 - ADO.NET Exception Handling
End Sub
Chapter 10 - Working with the ODBC .NET Data Provider
Chapter 11 - Stored Procedures and Views
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Chapter 13 - Developing a Custom Data Provider
Using the DataGridColumnStyle Class
Chapter 14 - Developing Database Web Applications using ASP.NET
Chapter 15 - Using ADO.NET in Xml
TheDataGridColumnStyle Web Services
represents the style of a column. You can attach a
Chapter 16 - ASP.NET Server Controls
DataGridColumnStyle to each column and Dataof Binding
a DataGrid. The DataGrid can contain different types of
Chapter 17 - Building Real-World Web Applications
columns such as a check box or a text box. As you saw earlier, a DataGridTableStyle contains a
collection
Chapter 18 of
- Object-Relational objects, which can be accessed through the GridColumnStyles
Mapping in .NET
DataGridColumnStyle
property
Chapter 19of- DataGridTableStyle. ThisConsiderations
Mapped Objects: Performance object is pretty useful
and Data and allows many formatting- and style-
Binding
related20
Chapter members. Table 7-5 describes
- COM Interoperability the DataGridColumnStyle properties.
and ADO.NET
Chapter 21 - Messaging
Table 7-5:
Chapter 22 - The Server and ADO.NET: NotesProperties
SQLDataGridColumnStyle on Performance
Appendix A - Relational Databases: Some Basic Concepts
PROPERTY DESCRIPTION
Appendix B - Commonly Used SQL Statements
Alignment
Appendix Alignment
C - ADO.NET Frequently of text in a column. Both get and set.
Asked Questions
Index
DataGridTableStyle Returns the DataGridTableStyle object associated with the
List of Figures
column.
List of Tables
ListHeaderText
of Listings Text of the column header. Both get and set.
ListMappingName
of Sidebars Name used to map the column style to a data member. Both get and
set.
NullText You can set the column text when the column has null values using
this property. Both get and set.
PropertyDescriptor PropertyDescriptor object that determines the attributes of data
displayed by the column. Both get and set.
ReadOnly Indicates if column is read only. Both get and set.
Width Width of the column. Both get and set.
Besides the methods described in Table 7-6, the DataGridColumnStyle class provides a method,
ResetHeaderText,Applied ADO.NET:
which Building
resets the headerData-Driven Solutions
text to its default value of null.
by Mahesh Chand and David Talbot ISBN:1590590732
Apress 2003 (928 pages)
Table 7-6: The DataGridColumnStyle Methods
This text provides extensive coverage of ADO.NET technology
METHOD including ADO.NET internals, namespaces, classes, and
DESCRIPTION
interfaces, and takes a comprehensive look at XML
Abort namespaces andAbortsclasses, and
the how
edit to integrate both with
operation.
ADO.NET.
BeginUpdate Suspends the painting operation of the column until the
EndUpdate method is called.
Table of Contents
CheckValidDataSource If a column
Applied ADO.NETBuilding Data-Driven is not mapped to a valid property of a data source, this
Solutions
Introduction
throws an exception.
Chapter 1 - ADO.NET Basics
ColumnStartEditing InformsDataGrid that the user has start editing the column.
Chapter 2 - Data Components in Visual Studio .NET
Commit Completes the editing operation.
Chapter 3 - ADO.NET in Disconnected Environments
Chapter 4 - ADO.NET in ConnectedNotifies
ConcedeFocus Environments
a column that it must relinquish the focus to the control it's
hosting.
Chapter 5 - Handling ADO.NET Events
Chapter 6 - Integrating XML with ADO.NET
Edit Prepares the cell for editing a value.
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
EndUpdate
Chapter Resumes the painting of columns suspended by calling the
8 - Constraints and Data Relations
Chapter 9 BeginUpdate method.
- ADO.NET Exception Handling
Chapter 10 - Working with the ODBC
EnterNullValue .NET a
Enters Data Provider
DBNullValue into the column.
Chapter 11 - Stored Procedures and Views
GetColumnValueAtRow
Chapter Returns
12 - Oracle, SQLXML, and Other theData
.NET value in the specified row.
Providers
Chapter 13 - Developing a Custom Data
GetMinimumHeight Provider
Returns the minimum height of a row.
Chapter 14 - Developing Database Web Applications using ASP.NET
15 - Using ADO.NET in XmlReturns
GetPreferedHeight
Chapter the height used for automatically resizing columns.
Web Services
Chapter 16 - ASP.NET Server Controls
GetPreferedSize and Data
Automatic Binding
size.
Chapter 17 - Building Real-World Web Applications
Invalidate Redraws
Chapter 18 - Object-Relational Mapping the column.
in .NET
Chapter 19 - Mapped Objects: Performance
SetColumnValueAtRow Considerations
Sets a value and Data
in the specified row.Binding
Chapter 20 - COM Interoperability and ADO.NET
SetDataGrid Sets the DataGrid to which this column belongs.
Chapter 21 - Messaging
Chapter 22 - SQL Server and ADO.NET:
SetDataGridInColumn Sets Notes on Performance
the DataGrid for the column.
Appendix A - Relational Databases: Some Basic Concepts
UpdateUI Updates the value of a row.
Appendix B - Commonly Used SQL Statements
Appendix C - ADO.NET Frequently Asked Questions
Index
Using the DataGridBoolColumn Class
List of Figures
List of Tables can contain different types of columns such as a check box or a text box. By default all
ADataGrid
columns
List are in a simple grid format. The DataGridBoolColumn class represents a Boolean column of
of Listings
aDataGrid.
List of Sidebars Each cell of a Boolean column contains a check box, which can be checked (true) or
unchecked (false). The DataGridBoolColumn class is inherited from the DataGridColumnStyle
class. Besides the functionality provided by the DataGridColumnStyle, it provides its own members.
Table 7-7 describes the DataGridBoolColumn class properties.
TablePrivate
of Contents
Sub AllowNavigationEvent(ByVal sender As Object, _
Applied ADO.NETBuilding
ByVal Data-Driven Solutions
e As System.EventArgs) Handles dtGrid.AllowNavigationChanged
Introduction
Dim nav As Boolean = dtGrid.AllowNavigation
ChapterDim
1 -strADO.NET Basics
As String = "AllowNavigationChanged event fired. "
ChapterIf
2 (nav)
- Data Components
Then in Visual Studio .NET
Chapter 3 str = str in+Disconnected
- ADO.NET "Navigation is allowed"
Environments
Chapter 4 NavigationMenu.Checked = True
- ADO.NET in Connected Environments
ChapterElse
5 - Handling ADO.NET Events
Chapter 6 str = str +XML
- Integrating "Navigation
with ADO.NET is not allowed"
Chapter 7 NavigationMenu.Checked = False
- Data Binding and Windows Forms Data-Bound Controls
End -If
Chapter 8 Constraints and Data Relations
MessageBox.Show(str, "AllowNavigation")
Chapter 9 - ADO.NET Exception Handling
End Sub
Chapter 10 - Working with the ODBC .NET Data Provider
Chapter 11 - Stored Procedures and Views
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Chapter 13 - Developing a Custom Data Provider
Setting DataGrid Coloring and Font Styles
Chapter 14 - Developing Database Web Applications using ASP.NET
Chapter 15 - Using
As mentioned, theADO.NET in Xml
DataGrid Web Services
provides properties to set the foreground and background color of almost
every part
Chapter 16 -ofASP.NET
a DataGrid
Serversuch as headers,
Controls and Data grid lines, and so on. The DataGrid also provides font
Binding
properties
Chapter 17 -toBuilding
set theReal-World
font of the Web
DataGrid. Listing 7-21 sets Font and Color properties of a DataGrid.
Applications
Chapter 18 - Object-Relational Mapping in .NET
Listing 7-21: Using Some of the DataGrid's Color and Font Properties
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
Chapter 20 - COM Interoperability and ADO.NET
' Setting
Chapter DataGrid's Color and Font properties
21 - Messaging
dtGrid.BackColor
Chapter = Color.Beige
22 - SQL Server and ADO.NET: Notes on Performance
dtGrid.ForeColor
Appendix = Color.Black
A - Relational Databases: Some Basic Concepts
dtGrid.BackgroundColor
Appendix B - Commonly Used SQL =Statements
Color.Red
dtGrid.SelectionBackColor
Appendix = Questions
C - ADO.NET Frequently Asked Color.Blue
dtGrid.SelectionForeColor = Color.Yellow
Index
dtGrid.GridLineColor = Color.Blue
List of Figures
dtGrid.HeaderBackColor = Color.Black
List of Tables
dtGrid.HeaderForeColor = Color.Gold
List of Listings
'dtGrid.AlternatingBackColor = Color.AliceBlue
List of Sidebars
dtGrid.LinkColor = Color.Pink
dtGrid.HeaderFont = New Font("Verdana", FontStyle.Bold)
dtGrid.Font = New Font("Verdana", 8, FontStyle.Regular)
Tip You can customize a DataGrid and allow the user to select a color and font for each part of the
DataGrid at runtime as well as at design-time using the Properties window.
TheCreateDataSet method in Listing 7-24 simply creates a DataSet by creating a DataTable and
adding three columns: EmployeeID (integer), Name (string), and StillWorking (Boolean). This
method also adds four rows to the DataTable and adds the DataTable to a DataSet.
The second pop-up menu will pop up when you right-click any grid's cell. This menu will have options such
as Move First, Move Previous, Move Next, and Move Last that will allow you to move to the first, previous,
next, and last rows of a DataGrid.
Now, using only these two cases, you can find out what DataGrid part is processing the hit test action (in
other words, which one is being clicked by the user). The HitTest method of DataGrid performs a hit
test action.
MEMBER
Table of Contents DESCRIPTION
Applied ADO.NETBuilding
Caption Data-Driven
Returns True if Solutions
the caption was clicked.
Introduction
Cell1
Chapter ReturnsTrue if a cell was clicked.
- ADO.NET Basics
Chapter 2 - Data Components
ColumnHeader Returnsin Visual
True if aStudio
column.NET
header was clicked.
Chapter 3 - ADO.NET in Disconnected Environments
ColumnResize
Chapter 4
- ADO.NET inRepresents
Connected the column border, the line between column headers.
Environments
Chapter
None5 - Handling ADO.NET Eventsif the background area was clicked.
ReturnsTrue
Chapter 6 - Integrating XML with ADO.NET
ParentRow
Chapter 7
The parent row displays information about the parent table of the currently
- Data Binding and Windows Forms Data-Bound Controls
displayed child table.
Chapter 8 - Constraints and Data Relations
Chapter ReturnsTrue
9 - ADO.NET Exception
RowHeader if the row header was clicked.
Handling
Chapter 10 - Working with the ODBC .NET Data Provider
RowResize ReturnsTrue if the line between rows.
Chapter 11 - Stored Procedures and Views
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
You can also check the Type property against the combination of DataGrid.HitTestType
Chapter 13 - Developing a Custom Data Provider
enumeration members. Listing 7-26 is the mouse down event handler of a DataGrid, which tracks
Chapter
almost 14 - Developing
every portion ofDatabase Web Applications
a DataGrid and generatesusing ASP.NET when you right-click a DataGrid. Simply
a message
Chapter 15 - Using ADO.NET in Xml Web Services
copy this code, right-click the DataGrid, and see it in action.
Chapter 16 - ASP.NET Server Controls and Data Binding
Listing17
Chapter 7-26: Seeing
- Building HitTestWeb
Real-World in Action
Applications
Chapter 18 - Object-Relational Mapping in .NET
Chapter 19 - Mapped
' DataGrid Objects:
Mouse downPerformance Considerations and Data Binding
event handler
Chapter 20 - COM
Private Interoperability
Sub and ADO.NET
dtGrid_MouseDown(ByVal sender As Object, _
Chapter
ByVal21 -eMessaging
As System.Windows.Forms.MouseEventArgs) Handles dtGrid.MouseDown
ChapterDim
22 -grid
SQL Server and ADO.NET:
As DataGrid Notes on Performance
= CType(sender, DataGrid)
Appendix
DimA -hti
Relational Databases: Some Basic Concepts
As DataGrid.HitTestInfo
' BWhen
Appendix right Used
- Commonly mouse
SQL button was clicked
Statements
IfC (e.Button
Appendix = MouseButtons.Right)
- ADO.NET Frequently Asked Questions Then
Index hti = grid.HitTest(e.X, e.Y)
List of Select
Figures Case hti.Type
List of Tables Case DataGrid.HitTestType.None
List of Listings
MessageBox.Show("Background")
Case DataGrid.HitTestType.Cell
List of Sidebars
MessageBox.Show("Cell - Row:" & hti.Row & ", Col: " & hti.Column)
Case DataGrid.HitTestType.ColumnHeader
MessageBox.Show("Column header " & hti.Column)
Case DataGrid.HitTestType.RowHeader
MessageBox.Show("Row header " & hti.Row)
Case DataGrid.HitTestType.ColumnResize
MessageBox.Show("Column seperater " & hti.Column)
Case DataGrid.HitTestType.RowResize
MessageBox.Show("Row seperater " & hti.Row)
Case DataGrid.HitTestType.Caption
MessageBox.Show("Caption")
Case DataGrid.HitTestType.ParentRows
MessageBox.Show("Parent row")
Applied ADO.NET: Building Data-Driven Solutions
End Select
End If by Mahesh Chand and David Talbot ISBN:1590590732
How about reshuffling or moving DataGrid columns? Reshuffling a DataGrid's columns is a simple
Table
trick.ofYou
Contents
need to find which column you want to reshuffle. You can do this by using the column name or
Applied
columnADO.NETBuilding Data-Driven
index. In this sample, Solutions
you'll use the column index.
Introduction
How about
Chapter 1 - reading
ADO.NETinformation
Basics about a DataGridTableStyle and its columns? The following code
reads information
Chapter about a grid's
2 - Data Components tablesStudio
in Visual and their
.NETnames:
Chapter 3 - ADO.NET in Disconnected Environments
Dim gridStyle
Chapter Asin DataGridTableStyle
4 - ADO.NET Connected Environments
For Each
Chapter gridStyle
5 - Handling In Events
ADO.NET DataGrid1.TableStyles
infoStr
Chapter = "Table
6 - Integrating XMLName: " + gridStyle.MappingName
with ADO.NET
Dim colStyle
Chapter 7
As DataGridColumnStyle
- Data Binding and Windows Forms Data-Bound Controls
For Each colStyle In gridStyle.GridColumnStyles
Chapter 8 - Constraints and Data Relations
infoStr = "Column: " + colStyle.MappingName
Chapter 9 - ADO.NET Exception Handling
Next
Chapter 10 - Working with the ODBC .NET Data Provider
Next
Chapter 11 - Stored Procedures and Views
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Let's see
Chapter 13 this in action. aCreate
- Developing Customa Windows application, add a DataGrid control, two Button controls, two
Data Provider
Label14
Chapter controls, two TextBox
- Developing Databasecontrols, and a ListBox
Web Applications control. Next, set their properties and positions.
using ASP.NET
The final
Chapter 15form looks
- Using like Figure
ADO.NET 7-9.
in Xml WebAsServices
you can see, to exchange two columns, you enter column index in
both text
Chapter 16boxes and click
- ASP.NET theControls
Server Exchangeand Columns button.
Data Binding
Chapter 17 - Building Real-World Web Applications
Chapter 18 - Object-Relational Mapping in .NET
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
Chapter 20 - COM Interoperability and ADO.NET
Chapter 21 - Messaging
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Appendix A - Relational Databases: Some Basic Concepts
Appendix B - Commonly Used SQL Statements
Appendix C - ADO.NET Frequently Asked Questions
Index
List of Figures
List of Tables
List of Listings
List of Sidebars
Now let's write the code. As usual, you first define some variables:
TablePrivate
of Contents
Sub Form1_Load(ByVal sender As System.Object, _
Applied ADO.NETBuilding
ByVal Data-Driven Solutions
e As System.EventArgs) Handles MyBase.Load
Introduction
FillDataGrid()
Chapter
End1 Sub
- ADO.NET Basics
Chapter
Private2 -Sub
Data FillDataGrid()
Components in Visual Studio .NET
Chaptersql
3 -=ADO.NET
"SELECT * FROM Customers"
in Disconnected Environments
Chapterconn = New SqlConnection(connectionString)
4 - ADO.NET in Connected Environments
Chapteradapter = New
5 - Handling SqlDataAdapter(sql,
ADO.NET Events conn)
Chapterds
6 =- Integrating
New DataSet("Customers")
XML with ADO.NET
Chapteradapter.Fill(ds, "Customers")
7 - Data Binding and Windows Forms Data-Bound Controls
DataGrid1.DataSource
Chapter 8
= ds.Tables(0).DefaultView
- Constraints and Data Relations
' By default there is no DataGridTableStyle object.
Chapter 9 - ADO.NET Exception Handling
' Add all DataSet table's style to the DataGrid
Chapter 10 - Working with the ODBC .NET Data Provider
Dim dTable As DataTable
Chapter 11 - Stored Procedures and Views
For Each dTable In ds.Tables
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Dim dgStyle As DataGridTableStyle = New DataGridTableStyle()
Chapter 13 - Developing a Custom Data
dgStyle.MappingName = Provider
dTable.TableName
Chapter 14 - Developing Database Web Applications using ASP.NET
DataGrid1.TableStyles.Add(dgStyle)
ChapterNext
15 - Using ADO.NET in Xml Web Services
Chapter'16 - ASP.NET Server
DataGrid Controls and Data Binding
settings
ChapterDataGrid1.CaptionText
17 - Building Real-World Web Applications
= "DataGrid Customization"
ChapterDataGrid1.HeaderFont
18 - Object-Relational Mapping
= in
New.NET
Font("Verdana", 12)
End19Sub
Chapter - Mapped Objects: Performance Considerations and Data Binding
Chapter 20 - COM Interoperability and ADO.NET
Chapter 21 - Messaging
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Caution What if you don't add DataGridTableStyle? By default, the DataGrid doesn't have any
Appendix A - Relational Databases: Some Basic Concepts
DataGridTableStyle and uses the default DataGridTableStyle. To make this
Appendix B - Commonly Used SQL Statements
program work, you must add it manually.
Appendix C - ADO.NET Frequently Asked Questions
Index
Now you write code on the Exchange Columns button click event handler (see Listing 7-28). As you can
List
see,of you
Figures
need to make sure that the text boxes aren't empty. After that you call the ReshuffleColumns
List of Tables
method, which actually moves the columns from one position to another.
List of Listings
Listing
List 7-28: Exchanging the Button Click Handler
of Sidebars
Table of Contents
As mentioned earlier, moving column positions in a grid involves resetting a DataGridTableStyle. As
Applied
you canADO.NETBuilding
see from Listing Data-Driven Solutions
7-29, you read the current DataGridTableStyle and create a new
DataGridTableStyle. Next, you copy the entire current DataGridTableStyle including the two
Introduction
columns
Chapter 1 that you want
- ADO.NET to exchange and then change positions of these columns. Next, you remove the
Basics
current2DataGridTableStyle
Chapter from the
- Data Components in Visual DataGrid
Studio .NET and apply the new DataGridTableStyle by
using the
Chapter 3 DataGrid.TableStyles.Remove and DataGrid.TableStyles.Add methods.
- ADO.NET in Disconnected Environments
Chapter 4 - ADO.NET in Connected Environments
Listing 7-29: The ReshuffleColumns Method
Chapter 5 - Handling ADO.NET Events
Chapter 6 - Integrating XML with ADO.NET
Private
Chapter 7 -Sub
Data ReshuffleColumns(ByVal col1 As
Binding and Windows Forms Data-Bound Integer, _
Controls
ByVal8 col2
Chapter As Integer,
- Constraints and DataByVal mapName As String, ByVal grid As DataGrid)
Relations
Dim9 existingTableStyle
Chapter As DataGridTableStyle = grid.TableStyles(mapName)
- ADO.NET Exception Handling
Dim counter As Integer = existingTableStyle.GridColumnStyles.Count
Chapter 10 - Working with the ODBC .NET Data Provider
Dim NewTableStyle As DataGridTableStyle = New DataGridTableStyle()
Chapter 11 - Stored Procedures and Views
NewTableStyle.MappingName = mapName
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Dim i As Integer
Chapter 13 - Developing a Custom Data Provider
For i = 0 To counter - 1 Step +1
Chapter 14 - Developing Database Web Applications using ASP.NET
If i <> col1 And col1 < col2 Then
Chapter 15 - Using ADO.NET in Xml Web Services
NewTableStyle.GridColumnStyles.Add _
Chapter 16 - ASP.NET Server Controls and Data Binding
(existingTableStyle.GridColumnStyles(i))
ChapterEnd17 -IfBuilding Real-World Web Applications
ChapterIf 18 i- Object-Relational
= col2 Then Mapping in .NET
Chapter 19 - Mapped Objects: Performance Considerations and
NewTableStyle.GridColumnStyles.Add _ Data Binding
Chapter 20 - COM Interoperability and ADO.NET
(existingTableStyle.GridColumnStyles(col1))
ChapterEnd21 -IfMessaging
ChapterIf 22 i- SQL
<> Server
col1 and
AndADO.NET:
col1 >Notes
col2onThen
Performance
Appendix A NewTableStyle.GridColumnStyles.Add
- Relational Databases: Some Basic Concepts _
(existingTableStyle.GridColumnStyles(i))
Appendix B - Commonly Used SQL Statements
AppendixEnd C -If
ADO.NET Frequently Asked Questions
Index
Next
' Remove the existing table style and add new style
List of Figures
grid.TableStyles.Remove(existingTableStyle)
List of Tables
grid.TableStyles.Add(NewTableStyle)
List of Listings
End Sub
List of Sidebars
Reading information about a DataGrid's columns using a DataGridColumnStyle is simple. You just
read the GridColumnStyleCollection using the GridColumnStyles property of
DataGridTableStyle.Listing 7-30 reads a DataGrid's column styles and adds them to the ListBox
control.
If DataGrid.HitTestType is ColumnHeader, you add menu items and get the current column, as
shown in Listing 7-32. In this listing, you simply store the current DataGridColumnStyle and the name
of the column.
Listing 7-32: Getting the Current DataGridColumnStyle
Applied ADO.NET: Building Data-Driven Solutions
by Mahesh Chand and David Talbot ISBN:1590590732
Case DataGrid.HitTestType.ColumnHeader
Apress 2003 (928 pages)
' Add context menus
This text provides extensive coverage of ADO.NET technology
popUpMenu = New internals,
including ADO.NET ContextMenu()
namespaces, classes, and
popUpMenu.MenuItems.Add("Sort ASC")
interfaces, and takes a comprehensive look at XML
namespaces and classes, and how to integrate
popUpMenu.MenuItems.Add("Sort DESC") both with
ADO.NET.
popUpMenu.MenuItems.Add("Find")
popUpMenu.MenuItems.Add("Hide Column")
Me.ContextMenu = popUpMenu
Table of Contents
Me.BackColor = Color.Sienna
Applied ADO.NETBuilding Data-Driven Solutions
sortAscMenu = Me.ContextMenu.MenuItems(0)
Introduction
sortDescMenu = Me.ContextMenu.MenuItems(1)
Chapter 1 - ADO.NET Basics
findMenu = Me.ContextMenu.MenuItems(2)
Chapter 2 - Data Components in Visual Studio .NET
hideMenu = Me.ContextMenu.MenuItems(3)
Chapter 3 - ADO.NET in Disconnected Environments
' Find the Column header name
Chapter 4 - ADO.NET in ConnectedAs
Dim gridStyle Environments
DataGridTableStyle = _
Chapter 5 - Handling ADO.NET Events
dtGrid.TableStyles("Customers")
Chapter 6 - Integrating
curColNameXML with ADO.NET
= gridStyle.GridColumnStyles _
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
(hti.Column).MappingName.ToString()
Chapter 8 - Constraints and Data Relations
curColumnStyle = gridStyle.GridColumnStyles(hti.Column)
Chapter 9 - ADO.NET Exception Handling
Chapter 10 - Working with the ODBC .NET Data Provider
Chapter 11 - Stored Procedures and Views
Finally,12
Chapter you- Oracle,
write the Find menu
SQLXML, button.NET
and Other clickData
event handler and set curColumnStyle.Width to 0:
Providers
Chapter 13 - Developing a Custom Data Provider
Private
Chapter 14 -Sub hideMenuHandler(ByVal
Developing sender
Database Web Applications As System.Object, _
using ASP.NET
ByVal
Chapter 15 e- Using
As System.EventArgs) Handles hideMenu.Click
ADO.NET in Xml Web Services
ChaptercurColumnStyle.Width
16 - ASP.NET Server Controls=and
0 Data Binding
End17Sub
Chapter - Building Real-World Web Applications
Chapter 18 - Object-Relational Mapping in .NET
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
Implementing Custom Sorting in a DataGrid
Chapter 20 - COM Interoperability and ADO.NET
Chapter 21 - Messaging
By default a DataGrid provides you with sorting options when you click a DataGrid column. But there
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
may be occasions when you don't want to use the default behavior and instead want to implement your
Appendix A - Relational Databases: Some Basic Concepts
own custom sorting.
Appendix B - Commonly Used SQL Statements
Appendix
In FigureC7-11,
- ADO.NET Frequently
you saw the Sort Asked Questions
ASC and Sort DESC menu options. As you probably remember from
Index
Chapter 3 and Chapter 4, sorting is easy to implement in a DataView. To sort a DataView, you simply
List
setofthe
Figures
Sort property of the DataView to the column name and to ASC or DESC for ascending and
List of Tables
descending sorting, respectively. Listing 7-33 shows the Sort ASC and Sort DESC menu event handler
code.
List of Listings
List of Sidebars
Listing 7-33: Sorting a DataGrid Control's Columns
You use the SELECT statement in a DataAdapter, which reads data based on the SELECT statement
and the criteria passed in it. However, using this method for searching may not be useful when you're
searching data frequentlyespecially when you're searching data in a DataGrid. We suggest not using
this method when searching data in an isolated application and there's no other application updating the
Applied
data. Why? The main ADO.NET:
reason Building
is that every timeData-Driven
you change Solutions
the SELECT statement, you need to create a
by Mahesh Chand and David Talbot
newDataAdapter and fill the DataSet when you change theISBN:1590590732
SELECT statement. This method is useful
Apress applications
when there are multiple 2003 (928 pages)
updating the data simultaneously and you want to search in the latest
updated data. This text provides extensive coverage of ADO.NET technology
including ADO.NET internals, namespaces, classes, and
interfaces, and takes a comprehensive look at XML
Searching Using a DataTable
namespaces and
and classes, andDataView
how to integrate both with
ADO.NET.
TheDataTable and DataView objects provide members that can filter data based on criteria. (See "The
DataView" section in Chapter 3 for more information.) You can simply create a DataView from a
Table set a DataView'sRowFilter property to the search criteria, and then bind the DataView to a
of Contents
DataSet,
DataGrid,
Applied which will display
ADO.NETBuilding the filtered
Data-Driven records.
Solutions
Introduction
Tip Using
Chapter 1
the same method, you can implement a Search or Find feature in a DataGrid control. You
- ADO.NET Basics
can also provide a Search option on a DataGrid control's header so that you know on which
Chapter 2 - Data Components in Visual Studio .NET
column a user has clicked.
Chapter 3 - ADO.NET in Disconnected Environments
Chapter
The new4 application
- ADO.NET looks
in Connected Environments
like Figure 7-13. Obviously, the Search button searches the column entered in
Chapter 5 - Handling ADO.NET Events
the Column Name text box for a value entered in the Value text box.
Chapter 6 - Integrating XML with ADO.NET
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
Chapter 8 - Constraints and Data Relations
Chapter 9 - ADO.NET Exception Handling
Chapter 10 - Working with the ODBC .NET Data Provider
Chapter 11 - Stored Procedures and Views
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Chapter 13 - Developing a Custom Data Provider
Chapter 14 - Developing Database Web Applications using ASP.NET
Chapter 15 - Using ADO.NET in Xml Web Services
Chapter 16 - ASP.NET Server Controls and Data Binding
Chapter 17 - Building Real-World Web Applications
Chapter 18 - Object-Relational Mapping in .NET
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
Chapter 20 - COM Interoperability and ADO.NET
Chapter 21 - Messaging
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Appendix A - 7-13:
Figure Relational Databases:search
Implementing Some Basic Concepts
functionality in a DataGrid control
Appendix B - Commonly Used SQL Statements
Appendix C - ADO.NET Frequently Asked Questions
Index
Note If you search for a string, use a singe quote (') before and after the string.
List
Weofdiscuss
Figuresthe Save method functionality in the following section.
List of Tables
After
List creating a Windows application and adding controls to the form, define following variables:
of Listings
List of Sidebars
' Developer defined variables
Private conn As SqlConnection = Nothing
Private connectionString As String = _
"Integrated Security=SSPI;Initial Catalog=Northwind;Data Source=MCB;"
Private sql As String = Nothing
Private searchView As DataView = Nothing
Dim adapter As SqlDataAdapter = Nothing
Dim ds As DataSet = Nothing
Now add the FillDataGrid method, which fills the DataGrid and creates a DataView called
searchView (seeApplied
ListingADO.NET:
7-37). Building Data-Driven Solutions
by Mahesh Chand and David Talbot ISBN:1590590732
Apress 2003 (928
Listing 7-37: FillDataGrid Method
pages)
This text provides extensive coverage of ADO.NET technology
including ADO.NET internals, namespaces, classes, and
' Fill DataGrid
interfaces, and takes a comprehensive look at XML
Private Subnamespaces
FillDataGrid()
and classes, and how to integrate both with
ADO.NET.
sql = "SELECT * FROM Orders"
conn = New SqlConnection(connectionString)
adapter = New SqlDataAdapter(sql, conn)
Table of Contents
ds = New DataSet("Orders")
Applied ADO.NETBuilding Data-Driven Solutions
adapter.Fill(ds, "Orders")
Introduction
DataGrid1.DataSource = ds.Tables("Orders")
ChaptersearchView
1 - ADO.NET = Basics
New DataView(ds.Tables("Orders"))
ChapterDim
2 -cmdBuilder
Data ComponentsAs inSqlCommandBuilder
Visual Studio .NET = _
ChapterNew
3 -SqlCommandBuilder(adapter)
ADO.NET in Disconnected Environments
Chapter'4 Disconnect.
- ADO.NET in Connected
Otherwise Environments
you would get
Chapter'5 Access
- Handling ADO.NET Events
violations when try multiple operations
Chapterconn.Close()
6 - Integrating XML with ADO.NET
Chapterconn.Dispose()
7 - Data Binding and Windows Forms Data-Bound Controls
Chapter 8 Sub
End - Constraints and Data Relations
Chapter 9 - ADO.NET Exception Handling
Chapter 10 - Working with the ODBC .NET Data Provider
Chapter 11 - Stored Procedures and Views
Now, the next step is to set a RowFilter of searchView based on the values entered in the Column
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Name and Value text fields. Listing 7-38 shows the code for the Search button. As you can see, the code
Chapter 13 - Developing a Custom Data Provider
sets the RowFilter of searchView and binds it to the DataGrid to display the filtered data.
Chapter 14 - Developing Database Web Applications using ASP.NET
Chapter
Listing15 - Using
7-38: ADO.NET
Seach in Click
Button Xml Web Services
Event Handler
Chapter 16 - ASP.NET Server Controls and Data Binding
Chapter 17 - Building Real-World Web Applications
Private Sub SearchBtn_Click(ByVal sender As System.Object, _
Chapter 18 - Object-Relational Mapping in .NET
ByVal e As System.EventArgs) Handles SearchBtn.Click
ChapterIf 19 (TextBox1.Text.Equals(String.Empty))
- Mapped Objects: Performance Considerations and Data
ThenBinding
Chapter 20 - COM Interoperability and ADO.NET
MessageBox.Show("Enter a column name")
Chapter 21 - Messaging
TextBox1.Focus()
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Return
AppendixEnd -If
A Relational Databases: Some Basic Concepts
AppendixIfB (TextBox2.Text.Equals(String.Empty))
- Commonly Used SQL Statements Then
Appendix C MessageBox.Show("Enter a value")
- ADO.NET Frequently Asked Questions
Index TextBox1.Focus()
Return
List of Figures
End If
List of Tables
' Construct a row filter and apply on the DataView
List of Listings
Dim str As String = TextBox1.Text + "=" + TextBox2.Text
List of Sidebars
searchView.RowFilter = str
' Set DataView as DataSource of DataGrid
DataGrid1.DataSource = searchView
End Sub
At this time, if you run the application, the data from the Orders table is filled in the DataGrid If you enter
EmployeeID in the Column Name text box and 6 in the Value field and then click the Search button, the
filtered data looks like Figure 7-14.
Applied ADO.NET: Building Data-Driven Solutions
by Mahesh Chand and David Talbot ISBN:1590590732
Apress 2003 (928 pages)
This text provides extensive coverage of ADO.NET technology
including ADO.NET internals, namespaces, classes, and
interfaces, and takes a comprehensive look at XML
namespaces and classes, and how to integrate both with
ADO.NET.
Table of Contents
Applied ADO.NETBuilding Data-Driven Solutions
Introduction
Chapter 1 - ADO.NET Basics
Chapter 2 - Data Components in Visual Studio .NET
Chapter 3 - ADO.NET in Disconnected Environments
Chapter 4 - ADO.NET in Connected Environments
Figure 7-14: Filtered data after searching
Chapter 5 - Handling ADO.NET Events
Chapter 6 - Integrating XML with ADO.NET
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
Inserting, Updating, and Deleting Data through DataGrids
Chapter 8 - Constraints and Data Relations
Chapter
As you 9learned
- ADO.NET Exception
earlier, Handlingcontrol is one of the most powerful, flexible, and versatile controls
the DataGrid
Chapter 10 in
available - Working
Windowswith the ODBC
Forms. It has.NET Data Provider
an almost unlimited number of properties and methods. You can add
new records,
Chapter update
11 - Stored records, and
Procedures and Views
delete existing records on a DataGrid with little effort, and you can
easily save
Chapter 12 - the affected
Oracle, dataand
SQLXML, in aOther
database.
.NET Data Providers
Chapter 13 - Developing a Custom Data Provider
When a DataGrid control is in edit mode (the default mode), you can simply add a new record by
Chapter 14 - Developing Database Web Applications using ASP.NET
clicking the last row of the grid and editing the column values. You can update data by changing the
Chapter 15 - Using ADO.NET in Xml Web Services
existing value of cells. You can delete a row by simply selecting a row and clicking the Delete button.
Chapter 16 - ASP.NET Server Controls and Data Binding
Chapter 17 - Building
In the previous Real-World
example, WebaApplications
you used Save Changes button on a form (see Figure 7-14). Now just write the
Chapter
code in18 - Object-Relational
Listing Mapping
7-39 on the Save in .NET
Changes button click to save the data.
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
Listing20
Chapter 7-39: Saving
- COM Updated Data
Interoperability in a Data Source from a DataGrid Control
and ADO.NET
Chapter 21 - Messaging
Chapter
Private22 -Sub
SQL Server and ADO.NET: Notes on
SaveBtn_Click(ByVal Performance
sender As System.Object, _
Appendix
ByVal A -eRelational Databases: Some Basic
As System.EventArgs) Concepts SaveBtn.Click
Handles
Appendix B - Commonly Used SQL Statements
Dim
Appendix C -changeDS As DataSet
ADO.NET Frequently = New DataSet()
Asked Questions
Index ' Data is modified
If (ds.HasChanges(DataRowState.Modified)) Then
List of Figures
changeDS = ds.GetChanges(DataRowState.Modified)
List of Tables
Dim changedRecords As Integer
List of Listings
changedRecords = adapter.Update(changeDS, "Orders")
List of Sidebars
If (changedRecords > 0) Then
MessageBox.Show(changedRecords.ToString() & _
" records modified.")
End If
End If
' Data is deleted
If (ds.HasChanges(DataRowState.Deleted)) Then
changeDS = ds.GetChanges(DataRowState.Deleted)
Dim changedRecords As Integer
changedRecords = adapter.Update(changeDS, "Orders")
If (changedRecords > 0) Then
MessageBox.Show(changedRecords.ToString() & _
" records deleted.")
End If Applied ADO.NET: Building Data-Driven Solutions
End If by Mahesh Chand and David Talbot ISBN:1590590732
Apress
' Data is added 2003 (928 pages)
This text provides extensive coverage of ADO.NET
If (ds.HasChanges(DataRowState.Added)) Then technology
including ADO.NET internals, namespaces,
changeDS = ds.GetChanges(DataRowState.Added) classes, and
interfaces, and takes a comprehensive look at XML
Dim changedRecords As Integer
namespaces and classes, and how to integrate both with
changedRecords
ADO.NET. = adapter.Update(changeDS, "Orders")
If (changedRecords > 0) Then
MessageBox.Show(changedRecords.ToString() & _
Table of Contents
" records added.")
Applied ADO.NETBuilding
End If Data-Driven Solutions
Introduction
End If
Chapter 1 ds.AcceptChanges()
- ADO.NET Basics
Chapter 2 DataGrid1.Refresh()
- Data Components in Visual Studio .NET
End3 Sub
Chapter - ADO.NET in Disconnected Environments
Chapter 4 - ADO.NET in Connected Environments
Chapter 5 - Handling ADO.NET Events
Chapter 6 - Integrating XML with ADO.NET
As you can- Data
Chapter 7
see from Listing 7-39, you simply get the modified, deleted, and updated changes in a new
Binding and Windows Forms Data-Bound Controls
DataSet by calling the DataSet.GetChanges method and save the changes by calling the
Chapter 8 - Constraints and Data Relations
DataAdapter.Update method. In the end, you accept the changes by calling
Chapter 9 - ADO.NET Exception Handling
DataSet.AcceptChanges and refresh the DataGrid control by calling the DataGrid.Refresh
Chapter 10 - Working with the ODBC .NET Data Provider
method.
Chapter 11 - Stored Procedures and Views
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Chapter 13 - Developing a Custom Data Provider
Chapter 14 - Developing Database Web Applications using ASP.NET
Chapter 15 - Using ADO.NET in Xml Web Services
Chapter 16 - ASP.NET Server Controls and Data Binding
Chapter 17 - Building Real-World Web Applications
Chapter 18 - Object-Relational Mapping in .NET
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
Chapter 20 - COM Interoperability and ADO.NET
Chapter 21 - Messaging
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Appendix A - Relational Databases: Some Basic Concepts
Appendix B - Commonly Used SQL Statements
Appendix C - ADO.NET Frequently Asked Questions
Index
List of Figures
List of Tables
List of Listings
List of Sidebars
Summary Applied ADO.NET: Building Data-Driven Solutions
by Mahesh Chand and David Talbot ISBN:1590590732
Data-bound controls aredefinitely
Apress one of the greatest additions to GUI applications. In this chapter, we
2003 (928 pages)
discussed the basics of data binding and how
This text provides extensive data binding
coverage works technology
of ADO.NET in Windows Forms data-bound controls
and ADO.NET. We including ADO.NET internals, namespaces, classes, and in the data-binding phenomena,
discussed some essential objects that participate
interfaces,
including Binding, and takes a comprehensive
BindingContext, look at XMLBindingManagerBase,
BindingsCollection,
PropertyManager,namespaces and classes, and
CurrencyManager, how
and to integrate both with
BindingContext.
ADO.NET.
After discussing basics of data binding and how to use these objects, you learned about some data-bound
controls and how to bind data using the data-binding mechanism. You also saw some practical usage of
Table of Contents
data binding and data-bound controls; specifically, you created a record navigation system with a
Applied ADO.NETBuilding Data-Driven Solutions
DataGrid control. Some of the examples discussed in this chapter included changing DataGrid styles
Introduction
programmatically, binding data sources to various data-bound controls, building a record navigation
Chapter 1 - ADO.NET Basics
application, and implementing search, add, update, and delete record features in a DataGrid.
Chapter 2 - Data Components in Visual Studio .NET
Chapter
Thenext3 chapter
- ADO.NET in Disconnected
covers Environments
constraints and data relations in more detail.
Chapter 4 - ADO.NET in Connected Environments
Chapter 5 - Handling ADO.NET Events
Chapter 6 - Integrating XML with ADO.NET
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
Chapter 8 - Constraints and Data Relations
Chapter 9 - ADO.NET Exception Handling
Chapter 10 - Working with the ODBC .NET Data Provider
Chapter 11 - Stored Procedures and Views
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Chapter 13 - Developing a Custom Data Provider
Chapter 14 - Developing Database Web Applications using ASP.NET
Chapter 15 - Using ADO.NET in Xml Web Services
Chapter 16 - ASP.NET Server Controls and Data Binding
Chapter 17 - Building Real-World Web Applications
Chapter 18 - Object-Relational Mapping in .NET
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
Chapter 20 - COM Interoperability and ADO.NET
Chapter 21 - Messaging
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Appendix A - Relational Databases: Some Basic Concepts
Appendix B - Commonly Used SQL Statements
Appendix C - ADO.NET Frequently Asked Questions
Index
List of Figures
List of Tables
List of Listings
List of Sidebars
Chapter Applied
8: Constraints and DataISBN:1590590732
Relations
ADO.NET: Building Data-Driven Solutions
by Mahesh Chand and David Talbot
Apress 2003 (928
In chapter 3, you encountered pages)
constraints and data relations. In this chapter, we discuss constraints and
data relations in more detail. First, extensive
This text provides coverage
we start this chapterof with
ADO.NET technology
a discussion of constraints and how ADO.NET
including ADO.NET internals, namespaces, classes, and
constraint objects maintain data integrity. Second, we discuss data relations. An object that encapsulates a
interfaces, and takes a comprehensive look at XML
data relationship namespaces
may be a newandconcept
classes,for
andmany
how programmers.
to integrate both with
ADO.NET.
Understanding Constraints
Table of Contents
Aconstraint is a rule used to automatically maintain the integrity of a column's data. When we say
Applied ADO.NETBuilding Data-Driven Solutions
automatically, we mean that the database itself makes sure the rule is being followed when changes are
Introduction
made to the data. For example, a UNIQUE constraint on a column makes sure that there aren't any
Chapter 1 values
duplicate - ADO.NET Basics There are different types of constraints, including NOT NULL, UNIQUE,
in a column.
Chapter
PRIMARY2 -KEY,
Data FOREIGN
Components in Visual
KEY, Studio .NET
and CHECK constraints:
Chapter 3 - ADO.NET in Disconnected Environments
The NOT NULL constraint specifies that a column can't contain null values.
Chapter 4 - ADO.NET in Connected Environments
Chapter
The5 UNIQUE
- Handling ADO.NETenforces
constraint Events a rule of uniqueness on a column, which means two rows of the
Chapter 6 - Integrating
column can't have XML with ADO.NET
duplicate values. A UNIQUE constraint may also apply to a combination of
columns,
Chapter which
7 - Data means
Binding andthe combination
Windows of the columns
Forms Data-Bound must be a unique value. For example, a
Controls
database
Chapter table canand
8 - Constraints have twoRelations
Data fields-a path and a file-and the combination of these fields must be
unique
Chapter 9 - to maintain
ADO.NET the unique
Exception file entry in the database. In this case, the path or file column may have
Handling
duplicate
Chapter valueswith
10 - Working individually,
the ODBCbut they
.NET must
Data be unique when used together.
Provider
Chapter 11 - Stored Procedures and Views
A PRIMARY KEY constraint on a column or combination of columns enforces both the UNIQUE
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
constraint and the NOT NULL constraint. This type of constraint is enforced when you need to identify
Chapter 13 - Developing a Custom Data Provider
column values as unique items and not null values such as a customer ID number or an order
Chapter 14 - Developing Database Web Applications using ASP.NET
number.
Chapter 15 - Using ADO.NET in Xml Web Services
The
Chapter 16FOREIGN
- ASP.NETKEY constraint
Server Controlsidentifies
and Data the relationships between two tables. A foreign key in the first
Binding
table
Chapter 17 points to aReal-World
- Building primary key in the
Web second table. Foreign keys prevent actions that would ignore rows
Applications
with
Chapter 18foreign key values when
- Object-Relational there
Mapping in are
.NETno primary keys with that value. For example, the Orders table
of a
Chapter 19database
- Mappedmay havePerformance
Objects: a foreign keyConsiderations
on the CustomerID column
and Data of the Customers table, which
Binding
would
Chapter 20 -prevent a user from entering
COM Interoperability an order that related to a nonexistent customer.
and ADO.NET
Chapter 21 - Messaging
The CHECK constraint enforces data integrity by limiting a column's values. For example, you can
Chapter 22 - SQL
specify Servertype
a column and as
ADO.NET: Notes
an integer, on Performance
which means only integer values can be placed in a column.
Appendix A - Relational Databases: Some Basic Concepts
To implement
Appendix many ofUsed
B - Commonly theseSQL
constraints,
StatementsADO.NET provides various classes. In the following sections, we
discuss some
Appendix of these
C - ADO.NET classes, their
Frequently Askedmembers,
Questions and how to use them to implement constraints.
Index
Implementing the Constraint Classes
List of Figures
List of Tables
The
List ofConstraint
Listings class represents a constraint and serves as a base class of the
ForeignKeyConstraint
List of Sidebars and UniqueConstraint classes. This class provides three properties:
ConstraintName represents the name of a constraint, ExtendedProperties represents a collection
of user-defined properties, and Table represents a DataTable object to which the constraint applies.
Before you learn how to implement constraints on a table, you'll look at the constraint classes.
TheForeignKeyConstraint class provides properties that can represent the relation name; the
columns participating in the relationship; the accept, delete, and update rules; and so on. Table 8-1
Applied ADO.NET: Building
describes the ForeignKeyConstraint Data-Driven
class properties. Solutions
by Mahesh Chand and David Talbot ISBN:1590590732
Apress 2003 (928 pages)
Table 8-1: The ForeignKeyConstraint Class Properties
This text provides extensive coverage of ADO.NET technology
PROPERTY including ADO.NET internals, namespaces, classes, and
DESCRIPTION
interfaces, and takes a comprehensive look at XML
namespaces and
AcceptRejectRule Occurs when
classes, the
and how to integrate both method
AcceptChanges with of a DataTable is
ADO.NET. called. The parameter of AcceptRejectRule is represented by the
AcceptRejectRule enumeration, which has two members:
Cascade and None. The default action is None.
Table of Contents
Applied ADO.NETBuilding Data-Driven
Columns ReturnsSolutions
the child columns of a constraint.
Introduction
ConstraintName Represents the name of the constraint.
Chapter 1 - ADO.NET Basics
Chapter Occurs
2 - Data Components in
DeleteRule Visual when
Studioa.NET
row is deleted. The parameter of DeleteRule is
Chapter 3 represented
- ADO.NET in Disconnected by the Rule enumeration, which has four members:
Environments
Chapter 4 Cascade,
- ADO.NET in Connected None,SetDefault, and SetNull. The default action is
Environments
Chapter 5 - Handling ADO.NET Cascade.
Events
Chapter 6 - Integrating XML with ADO.NET
ExtendedProperties Returns any user-defined properties that exist for the object.
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
RelatedColumns
Chapter Represents
8 - Constraints and Data Relations the parent column of a constraint.
Chapter
Table 9 - ADO.NET ExceptionReturns
Handlingthe DataTable of a constraint.
Chapter 10 - Working with the ODBC .NET Data Provider
UpdateRule
Chapter Occurs
11 - Stored Procedures and when a row is updated. The parameter of UpdateRule is
Views
represented by the Rule enumeration, which has four members:
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Cascade,None,SetDefault, and SetNull. The default action is
Chapter 13 - Developing a Custom Data Provider
Cascade.
Chapter 14 - Developing Database Web Applications using ASP.NET
Chapter 15 - Using ADO.NET in Xml Web Services
Chapter
Listing 16
8-1-creates
ASP.NETa Server Controls
FOREIGN KEYand Data Binding
constraint on the id column of custTable and the CustID column of
Chapter 17 - Building Real-World Web Applications
ordersTable.custTable and ordersTable are two DataTable objects created by the
Chapter 18 - Object-Relational and
CreateCustomersTable Mapping in .NET
CreateOrdersTable methods, respectively.
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
Listing20
Chapter 8-1: Creating
- COM a FOREIGN
Interoperability andKEY Constraint
ADO.NET
Chapter 21 - Messaging
Chapter 22 - SQL Server
Dim custTable As and ADO.NET: =
DataTable Notes on Performance
CreateCustomersTable()
Appendix A - Relational Databases:
Dim ordersTable Some Basic
As DataTable Concepts
= CreateOrdersTable()
Dim parentColumn
Appendix As DataColumn
B - Commonly Used SQL Statements= custTable.Columns("id")
Dim childColumn
Appendix As DataColumn
C - ADO.NET Frequently = ordersTable.Columns("CustID")
Asked Questions
Dim fkConst As ForeignKeyConstraint = New ForeignKeyConstraint _
Index
"CustOrderConts",
List of Figures parentColumn, childColumn)
fkConst.DeleteRule
List of Tables = Rule.SetNull
fkConst.UpdateRule = Rule.Cascade
List of Listings
fkConst.AcceptRejectRule = AcceptRejectRule.Cascade
List of Sidebars
Caution Be careful when using the Cascade action. The default action for AcceptRejectRule is
None, but the default action for UpdateRule and DeleteRule is Cascade. Calling the
Cascade action on DeleteRule deletes all the children rows, which are related using the
FOREIGN KEY constraint.
Dim i As Apress
Integer 2003 (928 pages)
This text provides extensive coverage of ADO.NET technology
Dim cnst As Constraint
including
For Each cnst In ADO.NET internals, namespaces, classes, and
contCollection
interfaces, and takes a comprehensive look at XML
str = str + ", "
namespaces and classes, and how to integrate both with
str = str + cnst.ConstraintName
ADO.NET.
Next
Table of Contents
Applied ADO.NETBuilding Data-Driven Solutions
Introduction
Adding PRIMARY KEY Constraints
Chapter 1 - ADO.NET Basics
There's2no- specific
Chapter primary key
Data Components class to
in Visual add a.NET
Studio PRIMARY KEY constraint to a DataTable. The
PrimaryKey
Chapter property
3 - ADO.NET in of DataTable
Disconnected sets the primary key of that table, and you assign a DataColumn
Environments
as the PrimaryKey
Chapter property.
4 - ADO.NET in Listing
Connected 8-6 creates a DataColumnCollection and sets it as the primary
Environments
key of the
Chapter 5 -CustTable.
Handling ADO.NET Events
Chapter 6 - Integrating XML with ADO.NET
Listing 8-6: Adding a PRIMARY KEY Constaint to a DataTable
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
Chapter 8 - Constraints and Data Relations
Dim custTable
Chapter 9 - ADO.NETAsException
DataTable = CreateCustomersTable()
Handling
' Make the ID column the primary key column.
Chapter 10 - Working with the ODBC .NET Data Provider
Dim PrimaryKeyColumns() As DataColumn = New DataColumn(1) {}
Chapter 11 - Stored Procedures and Views
PrimaryKeyColumns(0) = custTable.Columns("id")
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
custTable.PrimaryKey = PrimaryKeyColumns
Chapter 13 - Developing a Custom Data Provider
Chapter 14 - Developing Database Web Applications using ASP.NET
Chapter 15 - Using ADO.NET in Xml Web Services
Chapter 16 - ASP.NET Server Controls and Data Binding
Using SQL Statements to Add and Remove Constraints
Chapter 17 - Building Real-World Web Applications
Chapter 18 - Object-Relational
When working in a connectedMapping in .NETusing SQL may be a better way to add constraints to a
environment,
database
Chapter 19 table. YouObjects:
- Mapped can addPerformance
constraints to a table whenand
Considerations youData
create a table or by altering an already
Binding
existing20
Chapter table.
- COM Interoperability and ADO.NET
Chapter 21 - Messaging
TheCREATE TABLE SQL statement allows you to set a column as a constraint when you create a table.
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
TheCONSTRAINT keyword sets a column as the specified constraint. For example, the following SQL
Appendix A - Relational Databases: Some Basic Concepts
statement creates a table with myId as the primary key:
Appendix B - Commonly Used SQL Statements
Appendix C - ADO.NET Frequently Asked Questions
Dim sql As String = "CREATE TABLE myTable" & _
Index
"(myId INTEGER CONSTRAINT PKeyMyId PRIMARY KEY," & _
List of Figures
"myName CHAR(50), myAddress CHAR(255), myBalance FLOAT)"
List of Tables
List of Listings
List
You of can
Sidebars
always add and delete constraints from a database table using the ALTER TABLE SQL
statement. If you read the SQL documentation, you'll see that this statement allows options such as ADD
CONSTRAINT and DROP CONSTRAINT to add and remove constraints.
If you're working in a connected environment and you can execute commands (through SqlCommand),
using SQL statements to add and remove constraints is preferable because it entails less overhead and
code and has better performance.
Understanding
AppliedData Relations
ADO.NET: Building Data-Driven Solutions
by Mahesh Chand and David Talbot ISBN:1590590732
Until now it was the job of
Apress the (928
2003 database
pages) server to maintain data relationships, but with the flexibility of
ADO.NET, now programmers can also create
This text provides extensive and maintain
coverage data relationships
of ADO.NET technology in a disconnected
environment. A data relationship relates two tables to each other
including ADO.NET internals, namespaces, classes, and through their columns-for example, a
interfaces, and
customer/order relationship. Thetakes a comprehensive
Customers lookrecords
table stores at XML of a customer, and the Orders table
stores records of namespaces
orders made and
byclasses,
customers.and how
Eachtocustomer
integrate has
bothonly
withone record in the Customers table,
ADO.NET.
which is identified by a unique column value called Customer Id. Each order is related to a customer,
which has a column that stores the customer ID. The Orders table can have multiple records for a single
customer.
Table In this scenario, the Customer Id row in the Customers table acts as a parent row, and all
of Contents
related rows in the OrdersData-Driven
Applied ADO.NETBuilding table act as its child rows. One condition in this example is that the data type of
Solutions
both the parent
Introduction and row columns must be identical.
Chapter 1 - ADO.NET Basics
In ADO.NET, the DataRelation class represents a data relation between two DataTable objects, and
Chapter 2 - Data Components in Visual
theDataRelationCollection Studio .NET
represents a collection of data relations.
Chapter 3 - ADO.NET in Disconnected Environments
In a connected
Chapter environment,
4 - ADO.NET you can
in Connected access and maintain data relations through a DataSet. The
Environments
Relations
Chapter propertyADO.NET
5 - Handling of the DataSet
Events returns a collection of data relations associated with that DataSet
in the form
Chapter 6 - of a DataRelationCollection
Integrating XML with ADO.NET object. The ChildRelations and ParentRelations
properties
Chapter 7 -ofData
a DataTable
Binding and return theForms
Windows child relations andControls
Data-Bound parent relations associated with that
DataTable.
Chapter 8 - Constraints and Data Relations
Chapter 9 - ADO.NET Exception Handling
As you know from "The DataRow" section of Chapter 3, the DataRow also provides methods to return a
Chapter 10 - Working
row's parent with
and child the The
rows. ODBCGetParentRow
.NET Data Provider
method of a DataRow returns the parent row of a
Chapter 11 - Stored Procedures and Views
DataRow, and the GetParentRows method returns all parent rows related to a DataRow. The
Chapter 12 - Oracle,
GetChildRows SQLXML,
method and Other
returns all the.NET Data
child Providers
rows associated with a DataRow.
Chapter 13 - Developing a Custom Data Provider
Chapter 14 - Developing Database Web Applications using ASP.NET
Chapter 15 - Using ADO.NET in Xml Web Services
Chapter 16 - ASP.NET Server Controls and Data Binding
Chapter 17 - Building Real-World Web Applications
Chapter 18 - Object-Relational Mapping in .NET
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
Chapter 20 - COM Interoperability and ADO.NET
Chapter 21 - Messaging
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Appendix A - Relational Databases: Some Basic Concepts
Appendix B - Commonly Used SQL Statements
Appendix C - ADO.NET Frequently Asked Questions
Index
List of Figures
List of Tables
List of Listings
List of Sidebars
Understanding
Appliedthe DataRelation
ADO.NET: and DataRelationCollection
Building Data-Driven Solutions Objects
by Mahesh Chand and David Talbot ISBN:1590590732
TheDataRelation class
Apress represents
2003 (928 pages)a parent/child relationship between two tables. The
DataRelation's overloaded constructors
This text provides extensive allow you of
coverage to ADO.NET
create a DataRelation
technology object from a parent
and a child column or a collection of columns. The first argument
including ADO.NET internals, namespaces, classes, and of the constructors is the name of the
interfaces,
relation. The second andarguments
and third takes a comprehensive
are the parentlook at XML
and child column(s), respectively. The last
optional argumentnamespaces
is a Booleanandtype,
classes,
whichand how to integrate
indicates whether both with to create a constraint.
you want
ADO.NET.
Before you create a DataRelation, let's fill a DataSet from two tables. Listing 8-7 fills a DataSet from
the Customers and Orders tables.
Table of Contents
Applied
ListingADO.NETBuilding Data-Driven
8-7: Filling a DataSet fromSolutions
Two Tables
Introduction
Chapter 1 - ADO.NET Basics
' Create a Connection Object
Chapter 2 - Data Components in Visual Studio .NET
Dim conn As SqlConnection = New SqlConnection(ConnectionString)
Chapter 3 - ADO.NET in Disconnected Environments
SQL = "SELECT * FROM Customers"
Chapter 4 - ADO.NET in Connected Environments
conn.Open()
Chapter 5 - Handling ADO.NET Events
Dim adapter As SqlDataAdapter = New SqlDataAdapter(SQL, conn)
Chapter
Dim ds16 -AsIntegrating
DataSet XML=with
NewADO.NET
DataSet("Customers")
Chapter 7 - Data Binding and
adapter.Fill(ds1, "Customers")Windows Forms Data-Bound Controls
Chapter
SQL =8 "SELECT
- Constraints and Data
* FROM Relations
Orders"
Chapter
adapter9 -=ADO.NET Exception Handling
New SqlDataAdapter(SQL, conn)
Chapter
Dim ds210 -As
Working with the
DataSet = ODBC .NET Data Provider
New DataSet("Orders")
Chapter 11 - Stored Procedures
adapter.Fill(ds2, and Views
"Orders")
ds1.Merge(ds2)
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Chapter 13 - Developing a Custom Data Provider
Chapter 14 - Developing Database Web Applications using ASP.NET
Chapter 15 - Using ADO.NET in Xml Web Services
Now let's create a DataRelation between the CustomerId column of the Customers table and the
Chapter 16 - ASP.NET Server Controls and Data Binding
CustomerID column of Orders table (see Listing 8-8).
Chapter 17 - Building Real-World Web Applications
Chapter
Listing18 - Object-Relational
8-8: Mapping in .NET
Creating a DataRelation
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
Chapter 20 - COM Interoperability and ADO.NET
' Get the DataColumn objects from Customers
Chapter 21 - Messaging
' and Orders tables of a DataSet
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Dim parentCol As DataColumn = New DataColumn()
Appendix A - Relational Databases: Some Basic Concepts
Dim childCol As DataColumn = New DataColumn()
Appendix
'Retrieve B - Commonly
columnsUsed SQL aStatements
from DataSet
Appendix C - ADO.NET Frequently Asked Questions
parentCol = ds1.Tables("Customers").Columns("CustomerID")
Index
childCol = ds1.Tables("Orders").Columns("CustomerID")
List
Dim of Figures
bConstraints As Boolean
List of Tables
bConstraints = True
List
' of Listings a DataRelation.
Create
Dim
List CustOrderRelation As DataRelation = _
of Sidebars
New DataRelation("CustOrdersRelation", parentCol, childCol, bConstraints)
Now you can add a DataRelation to a DataSet using the Add method of
DataRelationCollection, which you access through the DataSet.Relations property. (We
dicuss DataRelationCollection in a moment.) Use this code to add the DataRelation:
Listing 8-10 calls the Contains,CanRemove, and Remove methods to delete a data relation from the
collection.
Table of Contents
Applied ADO.NETBuilding Data-Driven Solutions
Introduction
Chapter 1 - ADO.NET Basics
Chapter 2 - Data Components in Visual Studio .NET
Chapter 3 - ADO.NET in Disconnected Environments
Chapter 4 - ADO.NET in Connected Environments
Chapter 5 - Handling ADO.NET Events
Chapter 6 - Integrating XML with ADO.NET
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
Chapter 8 - Constraints and Data Relations
Chapter 9 - ADO.NET Exception Handling
Chapter 10 - Working with the ODBC .NET Data Provider
Chapter 11 - Stored Procedures and Views
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Chapter 13 - Developing a Custom Data Provider
Chapter 14 - Developing Database Web Applications using ASP.NET
Chapter 15 - Using ADO.NET in Xml Web Services
Chapter 16 - ASP.NET Server Controls and Data Binding
Chapter 17 - Building Real-World Web Applications
Chapter 18 - Object-Relational Mapping in .NET
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
Chapter 20 - COM Interoperability and ADO.NET
Chapter 21 - Messaging
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Appendix A - Relational Databases: Some Basic Concepts
Appendix B - Commonly Used SQL Statements
Appendix C - ADO.NET Frequently Asked Questions
Index
List of Figures
List of Tables
List of Listings
List of Sidebars
Summary Applied ADO.NET: Building Data-Driven Solutions
by Mahesh Chand and David Talbot ISBN:1590590732
Managing data relations
Apress and
2003constraints
(928 pages) programmatically is a new concept for developers. In this chapter,
you learned how This
ADO.NET
text provides you
helps createcoverage
extensive and manage data relations
of ADO.NET and constraints.
technology
including ADO.NET internals, namespaces, classes, and
Exception and error handling
interfaces, is another
and important part look
takes a comprehensive of programming.
at XML In next chapter, you'll learn how to
namespaces
handle exceptions and
in your code classes,
with andof
the help how to integrate
ADO.NET both with
classes.
ADO.NET.
Table of Contents
Applied ADO.NETBuilding Data-Driven Solutions
Introduction
Chapter 1 - ADO.NET Basics
Chapter 2 - Data Components in Visual Studio .NET
Chapter 3 - ADO.NET in Disconnected Environments
Chapter 4 - ADO.NET in Connected Environments
Chapter 5 - Handling ADO.NET Events
Chapter 6 - Integrating XML with ADO.NET
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
Chapter 8 - Constraints and Data Relations
Chapter 9 - ADO.NET Exception Handling
Chapter 10 - Working with the ODBC .NET Data Provider
Chapter 11 - Stored Procedures and Views
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Chapter 13 - Developing a Custom Data Provider
Chapter 14 - Developing Database Web Applications using ASP.NET
Chapter 15 - Using ADO.NET in Xml Web Services
Chapter 16 - ASP.NET Server Controls and Data Binding
Chapter 17 - Building Real-World Web Applications
Chapter 18 - Object-Relational Mapping in .NET
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
Chapter 20 - COM Interoperability and ADO.NET
Chapter 21 - Messaging
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Appendix A - Relational Databases: Some Basic Concepts
Appendix B - Commonly Used SQL Statements
Appendix C - ADO.NET Frequently Asked Questions
Index
List of Figures
List of Tables
List of Listings
List of Sidebars
Chapter Applied
9: ADO.NET Exception ISBN:1590590732
Handling
ADO.NET: Building Data-Driven Solutions
by Mahesh Chand and David Talbot
Apress 2003 (928 pages)
Overview This text provides extensive coverage of ADO.NET technology
including ADO.NET internals, namespaces, classes, and
Effective exception and error
interfaces, handling
and takes ais one of the most
comprehensive important
look at XML things to learn in order to write reliable
namespaces In
and error-proof applications. and classes,
this andwe
chapter, how to integrate
discuss how toboth
usewith
the exception and error handling
ADO.NET.
classes provided by the .NET Framework.
If you come from a C++ background, you're probably familiar with different exception handling methods
Table of Contents
such as C++ exception handling, structured exception handling, and MFC exceptions. If you come from a
Applied ADO.NETBuilding Data-Driven Solutions
Visual Basic (VB) background, you're probably familiar with the On Error statement. Although you can
Introduction
continue to use these techniques to handle errors, .NET implements exceptions differently. In addition, all
Chapter 1 - ADO.NET
.NET-supported Basics (C# and VB .NET) share the same mechanism. Now VB developers can enjoy
languages
Chapter
the same2 rich
- Data Components
exception in Visual
handling that Studio .NET
C++ developers enjoy.
Chapter 3 - ADO.NET in Disconnected Environments
Note
Chapter 4 Discussing .NET
- ADO.NET in exception
Connected handling is beyond the scope of this book. In this chapter, we
Environments
Chapter 5 concentrate on ADO.NET
- Handling ADO.NET Eventsexception handling classes only.
Chapter 6 - Integrating XML with ADO.NET
VB .NET supports two types of exceptions-unstructured and structured. Remember using the On Error
Chapter 7
statement -inData
VB?Binding and Windows Forms Data-Bound Controls
Using the On Error statement is unstructured handling. In other words, you place the
Chapter
On Error8 - statement
Constraintsat
and
theData Relations
beginning of a block of code and errors are handled at the end of the block.
Chapter 9 - ADO.NET Exception Handling
Unstructured exception handling also employs the Error and Resume statements. All the code after the
Chapter
On Error10 - statement
Working with the ODBC
is within .NET Data
the scope Provider
of the error handler. If there's another On Error statement, then
Chapter 11 - Stored Procedures and Views
that becomes the active error handler. However, structured exception handling is a better approach, and
Chapter
there's 12
no -reason
Oracle,why
SQLXML, and Other
you should .NET the
be using DataOnProviders
Error statement.
Chapter 13 - Developing a Custom Data Provider
Structured
Chapter 14 -exception handling
Developing works
Database Web a little differently
Applications usingthan unstructured handling. If you come from a C++
ASP.NET
background, you're probably familiar with Try...Catch blocks. However, if you haven't encountered
Chapter 15 - Using ADO.NET in Xml Web Services
them before, it's OK-they're simple enough. Specifically, you place the code within a Try block that you
Chapter 16 - ASP.NET Server Controls and Data Binding
think may cause an exception, and when an exception rises, the control goes to the Catch block.
Chapter 17 - Building Real-World Web Applications
Chapter 18 - Object-Relational Mapping in .NET
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
Chapter 20 - COM Interoperability and ADO.NET
Chapter 21 - Messaging
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Appendix A - Relational Databases: Some Basic Concepts
Appendix B - Commonly Used SQL Statements
Appendix C - ADO.NET Frequently Asked Questions
Index
List of Figures
List of Tables
List of Listings
List of Sidebars
Why Use Exception Handling?
Applied ADO.NET: Building Data-Driven Solutions
by Mahesh Chand and David Talbot ISBN:1590590732
If you've been writing
Apresssoftware for pages)
2003 (928 a while, you're probably familiar with why you want to handle exceptions.
Whenever an exception occurs in a program,coverage
This text provides extensive if there'sofno exception
ADO.NET handling, the program crashes with
technology
system-generated messages. Unfortunately, system-generated
including ADO.NET internals, namespaces, classes, and messages are often incomprehensible.
Instead of systeminterfaces,
messages, and takes
you canahandle
comprehensive
exceptionslookand
at XML
generate user-readable messages. Let's
namespaces
take a simple example. Listingand
9-1classes,
opens and howc:\abc.txt.
the file to integrate both with
ADO.NET.
Listing 9-1: Opening a File
Table of Contents
Applied
ImportsADO.NETBuilding
System.IO Data-Driven Solutions
Module Module1
Introduction
Sub1 Main()
Chapter - ADO.NET Basics
Chapter 2 File.Open("c:\\abc.txt", FileMode.Open)
- Data Components in Visual Studio .NET
End3 Sub
Chapter - ADO.NET in Disconnected Environments
End Module
Chapter 4 - ADO.NET in Connected Environments
Chapter 5 - Handling ADO.NET Events
Chapter 6 - Integrating XML with ADO.NET
Chapter 7
What if the- file
Data Binding and Windows Forms Data-Bound Controls
c:\abc.txt doesn't exist? Well, you get a lengthy error message, which looks like Figure
Chapter 8 - Constraints and Data Relations
9-1.
Chapter 9 - ADO.NET Exception Handling
Chapter 10 - Working with the ODBC .NET Data Provider
Chapter 11 - Stored Procedures and Views
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Chapter 13 - Developing a Custom Data Provider
Chapter 14 - Developing Database Web Applications using ASP.NET
Chapter 15 - Using ADO.NET in Xml Web Services
Chapter 16 - ASP.NET Server Controls and Data Binding
Chapter 17 - Building Real-World Web Applications
Chapter 18 - 9-1:
Figure Object-Relational Mapping in
A system-generated .NET
error
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
Chapter 20 - COM Interoperability and ADO.NET
Now let's modify this program little bit to make the error message more readable. As you can see from this
Chapter 21 - Messaging
Listing 9-2, you handle the exception using a simple Try...Catch block.
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Appendix A - Relational
Listing 9-2: A SimpleDatabases:
ExceptionSome Basic Concepts
Handling Block
Appendix B - Commonly Used SQL Statements
Appendix C - ADO.NET Frequently Asked Questions
Imports System.IO
Index
Module Module1
List of
SubFigures
Main()
List of Tables
Try
List of Listings
File.Open("c:\\abc.txt", FileMode.Open)
List of Sidebars
Catch exp As Exception
Console.WriteLine("Exception Ocurred :" + exp.Message.ToString())
End Try
End Sub
End Module
If you run the program, the output now looks like Figure 9-2, which not only handles the exception but also
reports the cause of exception.
Applied ADO.NET: Building Data-Driven Solutions
by Mahesh Chand and David Talbot ISBN:1590590732
Apress 2003 (928 pages)
This text provides extensive coverage of ADO.NET technology
including ADO.NET internals, namespaces, classes, and
interfaces,
Figure 9-2: An and takes a error
exception-handled comprehensive
message look at XML
namespaces and classes, and how to integrate both with
ADO.NET.
OK, now you'll see the SqlException class in action. Listing 9-7 connects to a SQL Server called MCB,
reads data from the Customers table, and then fills a DataSet.
Listing 9-7: Reading Data from a SQL Server
Applied ADO.NET: Building Data-Driven Solutions
by Mahesh Chand and David Talbot ISBN:1590590732
' Create a Connection Object
Apress 2003 (928 pages)
Dim ConnectionString As String ="Integrated Security=SSPI;" & _
This text provides extensive coverage of ADO.NET technology
"Initial
includingCatalog=Northwind;Data
ADO.NET internals, namespaces,Source=MCB;"
classes, and
Dim conn interfaces,
As SqlConnection = New SqlConnection(ConnectionString)
and takes a comprehensive look at XML
namespaces
Dim SQL As String and classes, and*how
= "SELECT to integrate
FROM both with
Customers"
ADO.NET.
Dim adapter As SqlDataAdapter = New SqlDataAdapter(SQL, conn)
Dim ds As DataSet = New DataSet()
Table of Contents
Try
Applied ADO.NETBuilding Data-Driven Solutions
' open a connection
Introduction
conn.Open()
Chapter 1 - ADO.NET Basics
adapter.Fill(ds, "Customers")
Chapter 2 - Data Components in Visual Studio .NET
Catch exp As SqlException
Chapter 3 - ADO.NET in Disconnected Environments
' Generate error message
Chapter 4 Console.WriteLine("Error:"
- ADO.NET in Connected Environments + exp.Message & _
Chapter 5 ",- Handling
Number:" ADO.NET Events
+ exp.Number.ToString() & _
Chapter 6 ",- Integrating XML with
Line Number: " ADO.NET
+ exp.LineNumber.ToString() & _
Chapter 7 ",- Data Binding and
Server:" Windows Forms Data-Bound Controls
+ exp.Server.ToString() & _
Chapter 8 ",- Constraints
Source:" and+Data Relations
exp.Source.ToString())
ChapterFinally
9 - ADO.NET Exception Handling
Chapter 10' -Close
Workingthe connection
with the ODBC .NET Data Provider
Chapter 11If- Stored
conn.State
Procedures= and
ConnectionState.Open
Views Then
Chapter 12 -conn.Close()
Oracle, SQLXML, and Other .NET Data Providers
Chapter 13End If
- Developing a Custom Data Provider
Chapter 14 - Developingthe
' Dispose connection
Database Web Applications using ASP.NET
If (Not conn Is Nothing) Then
Chapter 15 - Using ADO.NET in Xml Web Services
conn.Dispose()
Chapter 16 - ASP.NET Server Controls and Data Binding
End If
Chapter 17 - Building Real-World Web Applications
End Try
Chapter 18 - Object-Relational Mapping in .NET
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
Chapter 20 - COM Interoperability and ADO.NET
Chapter 21 - Messaging
Now change the SQL Server name to MCB1. The connection string looks like following:
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Appendix A - Relational Databases:
Dim ConnectionString As Some Basic
String = Concepts
"Integrated Security=SSPI;" & _
Appendix B - Commonly
"InitialUsed SQL Statements
Catalog=Northwind;Data Source=MCB1;"
Appendix C - ADO.NET Frequently Asked Questions
Index
If you
List run the code after changing the SQL Server name, it generates an error that looks like Figure 9-4.
of Figures
List of Tables
List of Listings
List of Sidebars
Now let's switch the SQL Server to MCB and change the SQL string to the following:
The of
Table ODBC data provider uses ODBC drivers to connect to different data sources; it's useful when you're
Contents
not sure
Applied what database your
ADO.NETBuilding clients will
Data-Driven be using in their applications. The user shouldn't have any trouble
Solutions
connecting as long as they have an ODBC driver for the database installed on their machine. In this
Introduction
chapter,
Chapter 1 you'll see how
- ADO.NET you can use the ODBC .NET data provider to work with MySQL, Oracle, Excel, and
Basics
even text
Chapter 2 data files.
- Data Components in Visual Studio .NET
Chapter 3 - ADO.NET in Disconnected Environments
Using the
Chapter 4 ODBC
- ADO.NET .NET Environments
in Connected Data Provider
Chapter 5 - Handling ADO.NET Events
You read a- brief
Chapter 6
discussion about the ODBC .NET data provider in Chapter 4. The ODBC .NET data
Integrating XML with ADO.NET
provider provides access to ODBC data sources with the help of native ODBC drivers in the same way that
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
the OleDb data provider accesses native OLE DB providers. One of the best things about working with
Chapter 8 - Constraints and Data Relations
ADO.NET data providers is that all the data providers define a similar class hierarchy. The only things you
Chapter 9 - ADO.NET Exception Handling
need to change are the classes and the connection string.
Chapter 10 - Working with the ODBC .NET Data Provider
Chapter
Before 11
you- start
Stored Procedures
using and .NET
the ODBC Viewsdata provider, let's quickly look at some installation issues.
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Note
Chapter 13 If- you're usinga Visual
Developing CustomStudio .NET (VS .NET) code name Everett, you don't need to worry about
Data Provider
installation because the ODBC .NET data provider is already installed.You can skip the following
Chapter 14 - Developing Database Web Applications using ASP.NET
section.
Chapter 15 - Using ADO.NET in Xml Web Services
Chapter 16 - ASP.NET Server Controls and Data Binding
Installing the ODBC .NET Data Provider
Chapter 17 - Building Real-World Web Applications
Chapter 18 - Object-Relational Mapping in .NET
Unlike the Sql and OleDb data providers, the ODBC data provider is an add-on component to the .NET
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
Framework. If the ODBC .NET provider isn't installed on your system, you can download it from the .NET
Chapter 20 - COM Interoperability and ADO.NET
Software Development Kit (SDK) and VS .NET on the Microsoft site (www.microsoft.com/data).
Chapter 21 - Messaging
Chapter 22 Microsoft
Note - SQL Server and ADO.NET:
VS .NET Notes
code name on Performance
Everett installs the ODBC .NET data provider automatically.
Appendix A - Relational Databases: Some Basic Concepts
After installing
Appendix the ODBC
B - Commonly data
Used SQLprovider, you need to customize the Toolbox to add the ODBC data
Statements
components
Appendix to it. YouFrequently
C - ADO.NET can customize
Asked the Toolbox by right-clicking the Data tab and selecting Customize
Questions
Toolbox.
Index
List ofNote
Figures
Make sure the Data tab is selected when you choose Customize Toolbox. Otherwise, new
List of Tables
components will be added to the active tab.
List of Listings
Next,
List click the .NET Framework Components tab (not the default COM components) and look for the
of Sidebars
ODBC components. Check the appropriate boxes, and then click the OK button. These check boxes are
OdbcCommand,OdbcCommandBuilder,OdbcConnection, and OdbcDataAdapter.
Next, you need to add a reference to the Microsoft.Data.Odbc.dll assembly using Project Add
Reference. You can use the Browse button to browse the directory. The Microsoft.Data.Odbc.dll
assembly resides in the \Program Files\Microsoft.NET\Odbc.NET directory. On the Add
Reference dialog box, select Microsoft.Data.Odbc.dll and then click the OK button, which adds the
Microsoft.Data.Odbc namespace reference to the project. You can see the namespace reference by
expanding the References node of your project in the Server Explorer.
To make sure the ODBC data provider is installed and added to your project, you can also look at the
Toolbox. If the ODBC data provider is installed on your machine, the Toolbox will display the ODBC data
components.
Applied ADO.NET: Building Data-Driven Solutions
by Mahesh
Note The Toolbox's Chand
Data and available
tab isn't David Talbot
for console applications. However, you can use ADO.NET
ISBN:1590590732
Apress 2003
in console-based applications
(928 pages) by writing the code manually.
This text provides extensive coverage of ADO.NET technology
You saw how to use the SQL
including and OleDb
ADO.NET datanamespaces,
internals, providers inclasses,
previousand
chapters. Working with the ODBC data
interfaces,
provider is no different fromand takeswith
working a comprehensive look atdata
the Sql and OleDb XML providers. Unlike the Sql and OleDb data
providers, however,namespaces
the ODBC and classes,
data andishow
provider to integrate
defined both with
in the Microsoft.Data.Odbc namespace. You
ADO.NET.
must add the following reference to this namespace before you can start using the ODBC data provider
classes:
Table of Contents
Applied
ImportsADO.NETBuilding Data-Driven Solutions
Microsoft.Data.Odbc
Introduction
Chapter 1 - ADO.NET Basics
Chapter 2 - Data Components in Visual Studio .NET
Note If you're using Microsoft VS .NET code name Everett, the ODBC data provider is defined in the
Chapter 3 - ADO.NET in Disconnected Environments
System.Data.Odbc namespace. Make sure you import the correct namespace.
Chapter 4 - ADO.NET in Connected Environments
Chapter 5 - Handling ADO.NET Events
Understanding
Chapter 6 thewith
- Integrating XML ODBC
ADO.NET.NET Data Provider
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
The ODBC data provider defines similar classes and a similar class hierarchy as the Sql and OleDb data
Chapter 8 - Constraints and Data Relations
providers. Further, you can use the ODBC data provider classes the same way as you've used the Sql and
Chapter 9 - ADO.NET Exception Handling
OleDb data provider classes. Table 10-1 defines the ODBC data provider classes.
Chapter 10 - Working with the ODBC .NET Data Provider
Chapter 11 - Stored Procedures and Views
Table 10-1: The ODBC .NET Data Provider Classes
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
CLASS
Chapter 13 - Developing a Custom DataDESCRIPTION
Provider
Chapter 14 - Developing Database Web Applications using ASP.NET
OdbcCommand Similar to OleDbCommand and SqlCommand, this class
Chapter 15 - Using ADO.NET in Xml Web Services
represents an SQL statement or stored procedure to execute
Chapter 16 - ASP.NET Server Controls and Data Binding
against a data source.
Chapter 17 - Building Real-World Web Applications
18 - Object-Relational Mapping Similar
OdbcCommandBuilder
Chapter in .NET to OleDbCommandBuilder and
SqlCommandBuilder,
Chapter 19 - Mapped Objects: Performance thisBinding
Considerations and Data class automatically generates
SELECT,INSERT,UPDATE, and DELETE SQL commands.
Chapter 20 - COM Interoperability and ADO.NET
Chapter 21 - Messaging
OdbcConnection Represents a connection.
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
OdbcDataAdapter Represents a DataAdapter.
Appendix A - Relational Databases: Some Basic Concepts
Appendix B - Commonly Used SQL Statements
OdbcDataReader Represents a DataReader.
Appendix C - ADO.NET Frequently Asked Questions
OdbcError Represents errors and warnings.
Index
ListOdbcErrorCollection
of Figures Represents a collection of errors and warnings.
List of Tables
OdbcException Represents an ODBC Exception class.
List of Listings
ListOdbcParameter
of Sidebars Represents an ODBC parameter.
OdbcParameterCollection Represents a parameter collection.
OdbcTransaction Represents a transaction.
As you can see from Table 10-1, the ODBC data provider has many classes that are similar to the Sql and
OleDb data providers. To use the ODBC data provider classes, you create a Connection object and
then fill data from the Connection object to a DataAdapter or a DataReader, and they display the
data.
Accessing Applied
Access Databases
ADO.NET: Building Data-Driven Solutions
by Mahesh Chand and David Talbot ISBN:1590590732
Now you'll see anApress
example of (928
2003 howpages)
to access data from a data source using the ODBC data provider. In this
example, you'll use the Access 2000 Northwind
This text provides extensive database
coverage as the data
of ADO.NET source.
technology
including ADO.NET internals, namespaces, classes, and
Before creating ainterfaces,
connection, the
and firstathing
takes you need to
comprehensive setatis XML
look the connection string. The connection string
for OdbcConnection contains
namespaces anda classes,
data source driver
and how to and the data
integrate bothsource
with path with an optional user ID and
ADO.NET.
password. Optionally, you can also use an ODBC Data Source Name (DSN) as the connection string. You
create a DSN from the ODBC Administration applet in the Windows Control Panel.
Table of Contents
The connection string for an Oracle database looks like the following:
Applied ADO.NETBuilding Data-Driven Solutions
Introduction
Driver={Microsoft ODBC for Oracle};Server=ORACLE8i7;UID=odbcuser;PWD=odbc$5xr
Chapter 1 - ADO.NET Basics
Chapter 2 - Data Components in Visual Studio .NET
Chapter 3 - ADO.NET
The connection stringinfor
Disconnected
a Microsoft Environments
Access database looks like the following:
Chapter 4 - ADO.NET in Connected Environments
Chapter 5 - Handling ADO.NET
Driver={Microsoft AccessEvents
Driver (*.mdb)};DBQ=c:\\Northwind.mdb
Chapter 6 - Integrating XML with ADO.NET
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
The connection
Chapter string for
8 - Constraints andanData
Excel database looks like the following:
Relations
Chapter 9 - ADO.NET Exception Handling
Chapter 10 - Working with Excel
Driver={Microsoft the ODBC .NET Data
Driver Provider
(*.xls)};DBQ=c:\bin\book1.xls
Chapter 11 - Stored Procedures and Views
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
The connection string for a text database looks like the following:
Chapter 13 - Developing a Custom Data Provider
Chapter 14 - Developing Database Web Applications using ASP.NET
Driver={Microsoft
Chapter Text
15 - Using ADO.NET Driver
in Xml (*.txt; *.csv)};DBQ=c:\\
Web Services
Chapter 16 - ASP.NET Server Controls and Data Binding
Chapter 17 - Building Real-World Web Applications
You can use any DSN by using the following connection string:
Chapter 18 - Object-Relational Mapping in .NET
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
DSN=dsnname
Chapter 20 - COM Interoperability and ADO.NET
Chapter 21 - Messaging
Chapter 22 - SQL string
The connection Serverfor
anda ADO.NET: Notes
SQL Server on Performance
database looks like following:
Appendix A - Relational Databases: Some Basic Concepts
Appendix B - Commonly
"DRIVER={SQL Used SQL Statements
Server};SERVER=MyServer;UID=sa;PWD=Qvr&77xk;DATABASE=northwind;";
Appendix C - ADO.NET Frequently Asked Questions
Index
Listing
List 10-1 reads data from the Northwind database and shows the results on the console. For this
of Figures
example,
List create a console application to test the code. As you can see from Listing 10-1, first you import the
of Tables
Microsoft.Data.Odbc
List of Listings namespace. After that you create an OdbcConnection object with the
Microsoft
List Access ODBC driver and the Northwind database. The next step is to create an OdbcCommand
of Sidebars
object and call the ExecuteReader method, which returns an OdbcDataReader object. Finally, you read
data from the DataReader and display the results on the console.
Listing 10-1: Reading Data from Northwind Using the ODBC Data Provider
Imports Microsoft.Data.Odbc
Module Module1
Sub Main()
' Build a connection and SQL strings
Dim connectionString As String = _
"Driver={Microsoft Access Driver (*.mdb)};DBQ=c:\\Northwind.mdb"
Dim SQL As String _
= "SELECTApplied ADO.NET: FirstName,
EmployeeID, Building Data-Driven Solutions
LastName FROM Employees"
by Mahesh Chand
' Create connection object and David Talbot ISBN:1590590732
Note You may need Administrator rights to install and register the MySQL server and its services.
Table of Contents
Applied ADO.NETBuilding
After installing Data-Driven
MySQL, make sure it'sSolutions
running. If the service isn't running, you may need to start it
Introduction
manually. You can start it by selecting Control Panel Administrative Tools Services, right-clicking the
Chapter 1 - ADO.NET
MySql service, Basics
and then selecting the Start menu option. This action will start MySql as a service. Because
Chapter 2 - Data
in this chapter Components
you'll be using in VisualtoStudio
ODBC .NET
connect to a MySQL database, you need to install an ODBC driver
Chapter 3 -can
for it. You ADO.NET
find theinmost
Disconnected Environments
widely used ODBC driver for MySQL, MyODBC, at
www.mysql.com/downloads/api-myodbc.html.
Chapter 4 - ADO.NET in Connected Environments
Chapter 5 - Handling ADO.NET Events
After downloading
Chapter 6
the zipped driver file, the obvious action is to unzip it and install it. If the driver is installed
- Integrating XML with ADO.NET
properly, you can see it from the ODBC Data Source Administrator by selecting Control Panel Data
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
Source (ODBC). You must see MySQL in the ODBC Drivers list to proceed.
Chapter 8 - Constraints and Data Relations
Chapter 9 program,
For your - ADO.NET
youException
can useHandling
any MySQL database you have on the server, but for this example, use the
Chapter 10 -database.
Northwind Working with the ODBC
You've never .NET
heardData
of aProvider
MySQL version of the Northwind database, you say? Well,
Chapter 11 -one.
there isn't Stored Procedures
You'll andAccess
convert the Views Northwind database to MySQL and then you'll use it.
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
To convert
Chapter 13 - (or, import) athe
Developing Access
Custom Northwind
Data Provider database, you can use a free tool called DBTools Manager.
This tool provides many handy functions for MySQL developers. You can download DBTools at
Chapter 14 - Developing Database Web Applications using ASP.NET
www.dbtools.com.br.
Chapter 15 - Using ADO.NET in Xml Web Services
Chapter 16 - ASP.NET Server Controls and Data Binding
Chapter 17 - Building Real-World Web Applications
Chapter 18 - Object-Relational Mapping in .NET
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
Chapter 20 - COM Interoperability and ADO.NET
Chapter 21 - Messaging
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Appendix A - Relational Databases: Some Basic Concepts
Appendix B - Commonly Used SQL Statements
Appendix C - ADO.NET Frequently Asked Questions
Index
List of Figures
List of Tables
List of Listings
List of Sidebars
Accessing Applied
MySQL Databases
ADO.NET: Building Data-Driven Solutions
by Mahesh Chand and David Talbot ISBN:1590590732
As we've been saying,
Apressworking with
2003 (928 different data sources is only a matter of changing the connection
pages)
string and class names. You can access
This text provides extensivea MySQL database
coverage either
of ADO.NET using a DSN or using the database
technology
name directly in the
including ADO.NET internals, namespaces, classes, and directly, as shown in the following
connection string. You can use a database name
code: interfaces, and takes a comprehensive look at XML
namespaces and classes, and how to integrate both with
ADO.NET.
dim connectionString as string =
"Driver={MySQL};SERVER=localhost;DATABASE=NorthwindMySQL;"
Table of Contents
Applied ADO.NETBuilding Data-Driven Solutions
Introduction
Or you 1can- use
Chapter an ODBC
ADO.NET BasicsDSN, as you can see from the following code that uses TestDSN to connect to
the data
Chapter 2 source:
- Data Components in Visual Studio .NET
Chapter 3 - ADO.NET in Disconnected Environments
Dim conn
Chapter as OdbcConnection
4 - ADO.NET = new OdbcConnection("DSN=TestDSN")
in Connected Environments
Chapter 5 - Handling ADO.NET Events
Chapter 6 - Integrating XML with ADO.NET
To test this code, create a Windows application, add a DataGrid control to the form, and then write the
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
code in Listing 10-2 on the Form_Load event. As you can see in Listing 10-2, this code is similar to the
Chapter 8 saw
code you - Constraints
in Listingand Data
10-1. Relations
It creates a Connection object, a DataAdapter, fills the DataSet from
Chapter 9 - ADO.NET Exception Handling
theDataAdapter, and then sets the DataSet'sDefaultViewManager as the DataGrid control's
Chapter 10 - Working
DataSource with the ODBC .NET Data Provider
property.
Chapter 11 - Stored Procedures and Views
Listing12
Chapter 10-2: Accessing
- Oracle, a MySQL
SQLXML, Database
and Other .NET Data Providers
Chapter 13 - Developing a Custom Data Provider
Chapter
Private14 -Sub
Developing Database Web Applications
Form1_Load(ByVal sender using ASP.NET
As System.Object, _
Chapter
ByVal15 -eUsing
As ADO.NET in Xml Web Services
System.EventArgs) Handles MyBase.Load
ChapterDim
16 -connectionString
ASP.NET Server ControlsAs
andString
Data Binding
= _
Chapter"Driver={MySQL};SERVER=localhost;DATABASE=NorthwindMySQL;"
17 - Building Real-World Web Applications
ChapterDim
18 -conn As OdbcConnection
Object-Relational = New OdbcConnection(connectionString)
Mapping in .NET
Chapterconn.Open()
19 - Mapped Objects: Performance Considerations and Data Binding
ChapterDim
20 -da
COMAs OdbcDataAdapter
Interoperability = New OdbcDataAdapter _
and ADO.NET
Chapter("SELECT CustomerID, ContactName, ContactTitle FROM Customers", conn)
21 - Messaging
ChapterDim
22 -ds
SQLAs DataSet
Server = NewNotes
and ADO.NET: DataSet("Cust")
on Performance
da.Fill(ds, "Customers")
Appendix A - Relational Databases: Some Basic Concepts
DataGrid1.DataSource = ds.DefaultViewManager
Appendix B - Commonly Used SQL Statements
conn.Close()
Appendix C - ADO.NET Frequently Asked Questions
conn.Dispose()
Index
End Sub
List of Figures
List of Tables
List of Listings
List of Sidebars
Accessing Applied
Text File Databases
ADO.NET: Building Data-Driven Solutions
by Mahesh Chand and David Talbot ISBN:1590590732
To test text database connectivity,
Apress you can export the Employees table of the Northwind database using
2003 (928 pages)
the File ExportThis
option of Access 2000. In the
text provides extensive following
coverage section, you'll
of ADO.NET export a table to a text file, and
technology
you'll see how to including
use it withADO.NET
the ODBC DataAdapter.
internals, namespaces, classes, and
interfaces, and takes a comprehensive look at XML
namespaces and classes, and how to integrate both with
Exporting an Access Table to a Text File
ADO.NET.
You can export an Access database table to a text file using the Export option. In other words, select a
Table
tableofand
Contents
choose File Export. Another option is to rightclick a table and choose the Export option from
Applied ADO.NETBuilding Data-Driven Solutions
the menu.
Introduction
After clicking
Chapter the Export
1 - ADO.NET option, the dialog box that appears lets you pick a path and the file you want to
Basics
export. There
Chapter 2
are many export formats available. For this example, select the Text Files option.
- Data Components in Visual Studio .NET
Chapter 3 Export
Next, the - ADO.NET
Text in Disconnected
Wizard lets youEnvironments
define the format of the text file-either delimited or fixed width (see
Chapter 4 - ADO.NET
Figure 10-2). in Connected Environments
Chapter 5 - Handling ADO.NET Events
Chapter 6 - Integrating XML with ADO.NET
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
Chapter 8 - Constraints and Data Relations
Chapter 9 - ADO.NET Exception Handling
Chapter 10 - Working with the ODBC .NET Data Provider
Chapter 11 - Stored Procedures and Views
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Chapter 13 - Developing a Custom Data Provider
Chapter 14 - Developing Database Web Applications using ASP.NET
Chapter 15 - Using ADO.NET in Xml Web Services
Chapter 16 - ASP.NET Server Controls and Data Binding
Chapter 17 - Building Real-World Web Applications
Chapter 18 - Object-Relational Mapping in .NET
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
Chapter 20 - COM Interoperability and ADO.NET
Figure 10-2: Export Text Wizard options
Chapter 21 - Messaging
Chapter
You can22also
- SQL Server
click and ADO.NET:
the Advanced Notes
button on more
to set Performance
options, such as specifying the delimiters and other
options (see
Appendix Figure 10-3).
A - Relational Databases: Some Basic Concepts
Appendix B - Commonly Used SQL Statements
Appendix C - ADO.NET Frequently Asked Questions
Index
List of Figures
List of Tables
List of Listings
List of Sidebars
Table of Contents
Applied ADO.NETBuilding Data-Driven Solutions
Introduction
Chapter 1 - ADO.NET Basics
Chapter 2 - Data Components in Visual Studio .NET
Chapter 3 - ADO.NET in Disconnected Environments
Chapter 4 - ADO.NET in Connected Environments
Chapter 5 - Handling ADO.NET Events
Figure
Chapter 6 - 10-4: Delimiter
Integrating XML options of the Export Text Wizard
with ADO.NET
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
Figure 10-4 also shows the Include Field Names on First Row check box selected. This option adds the
Chapter 8 - Constraints and Data Relations
first row of the text file as field names.
Chapter 9 - ADO.NET Exception Handling
Chapter 10page
The last - Working
of the with theasks
wizard ODBC .NET
you forData Provider of where you want to export the data. Enter the
the filename
Chapter 11C:\Employees.txt.
filename - Stored Procedures and Views
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Finally,13
Chapter click the Finish abutton.
- Developing Custom When
Data the wizard is done exporting, you'll see a message saying the export
Provider
is finished.
Chapter 14 -Click OK and
Developing close Access.
Database Web Applications using ASP.NET
Chapter 15 -C:\Employees.txt,
If you view Using ADO.NET in Xml Web Services
it looks like Figure 10-5.
Chapter 16 - ASP.NET Server Controls and Data Binding
Chapter 17 - Building Real-World Web Applications
Chapter 18 - Object-Relational Mapping in .NET
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
Chapter 20 - COM Interoperability and ADO.NET
Chapter 21 - Messaging
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Appendix A - Relational Databases: Some Basic Concepts
Appendix B - Commonly Used SQL Statements
Appendix C - 10-5:
Figure ADO.NET Frequently
Exported Asked Questions
Employees.txt file from Nothwind.mdb
Index
List of Figures
List of Tables
Accessing a Text File
List of Listings
List
You of can
Sidebars
access a text file using the ODBC data provider. There are two ways to access text files: You can
create a DSN from the ODBC Data Source Administrator, or you can access the text file directly from your
application. To create a data source for a text file, go to ODBC Data Source Admin, click the New button
(or the Add button if you're using Windows XP), and select the Microsoft Text Driver (*.txt, *.csv) option
(see Figure 10-6).
Applied ADO.NET: Building Data-Driven Solutions
by Mahesh Chand and David Talbot ISBN:1590590732
Apress 2003 (928 pages)
This text provides extensive coverage of ADO.NET technology
including ADO.NET internals, namespaces, classes, and
interfaces, and takes a comprehensive look at XML
namespaces and classes, and how to integrate both with
ADO.NET.
Table of Contents
Applied ADO.NETBuilding Data-Driven Solutions
Introduction
Chapter 1 - 10-6:
Figure ADO.NET Basics the Microsoft Text Driver (*.txt, *.csv) option
Selecting
Chapter 2 - Data Components in Visual Studio .NET
Chapter 3 - ADO.NET in Disconnected Environments
You define the DSN name and description in the ODBC Text Setup dialog box. If you don't want to use the
Chapter 4 - ADO.NET in Connected Environments
current directory, uncheck the Use Current Directory option to enable the Select Directory button and click
Chapter 5 - Handling ADO.NET Events
Options to see more options (see Figure 10-7).
Chapter 6 - Integrating XML with ADO.NET
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
Chapter 8 - Constraints and Data Relations
Chapter 9 - ADO.NET Exception Handling
Chapter 10 - Working with the ODBC .NET Data Provider
Chapter 11 - Stored Procedures and Views
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Chapter 13 - Developing a Custom Data Provider
Chapter 14 - Developing Database Web Applications using ASP.NET
Chapter 15 - Using ADO.NET in Xml Web Services
Chapter 16 - ASP.NET Server Controls and Data Binding
Chapter 17 - Building Real-World Web Applications
Chapter 18 - Object-Relational Mapping in .NET
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
Chapter 20 - COM Interoperability and ADO.NET
Chapter 21 - Messaging
Figure 10-7: Setting the DSN name and description
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Appendix
Now youAcan
- Relational Databases:
select any directorySome BasictoConcepts
you want use. An entire text file is used as a database table (see
Appendix B - Commonly Used SQL Statements
Figure 10-8).
Appendix C - ADO.NET Frequently Asked Questions
Index
List of Figures
List of Tables
List of Listings
List of Sidebars
You can even define different formats by using the Define Format button in the ODBC Text Setup dialog
box. As you can see from Figure 10-9, all files are treated as a database table. From the Format drop-
down box, you can select the type of format you want such as comma delimited or tab delimited. The
Guess button assigns the column names for you. If it doesn't find a proper format file, it creates F1...Fn
columns for you. You can also add, modify, and remove columns and their types.
Applied ADO.NET: Building Data-Driven Solutions
by Mahesh Chand and David Talbot ISBN:1590590732
Apress 2003 (928 pages)
This text provides extensive coverage of ADO.NET technology
including ADO.NET internals, namespaces, classes, and
interfaces, and takes a comprehensive look at XML
namespaces and classes, and how to integrate both with
ADO.NET.
Table of Contents
Applied ADO.NETBuilding Data-Driven Solutions
Introduction
Chapter 1 - ADO.NET Basics
Chapter 2 - Data Components in Visual Studio .NET
Chapter 3 - ADO.NET in Disconnected Environments
Figure 10-9: Defining a text file format and column settings
Chapter 4 - ADO.NET in Connected Environments
Chapter 5 - Handling
After creating a DSN,ADO.NET
you can Events
use it as a connection source for your connection:
Chapter 6 - Integrating XML with ADO.NET
Chapter 7 - Data
Dim conn Binding and Windows =Forms
As OdbcConnection New Data-Bound Controls
OdbcConnection("DSN=TxtDSN")
Chapter 8 - Constraints and Data Relations
Chapter 9 - ADO.NET Exception Handling
Another10way
Chapter to access
- Working withtext
thefiles
ODBCis directly
.NET Datausing the text ODBC driver in the connection string. For
Provider
example,
Chapter 11ConnectionString in Views
- Stored Procedures and the following code defines a connection with the Microsoft Text Driver
and the12
Chapter source directory
- Oracle, c:\:
SQLXML, and Other .NET Data Providers
Chapter 13 - Developing a Custom Data Provider
Dim connectionString
Chapter As Web
14 - Developing Database String = _ using ASP.NET
Applications
"Driver={Microsoft
Chapter 15 - Using ADO.NETText
in Xml Driver (*.txt; *.csv)};DBQ=c:\\"
Web Services
Chapter 16 - ASP.NET Server Controls and Data Binding
Chapter 17 - Building Real-World Web Applications
Chapter 18 - Object-Relational Mapping in .NET
Every.txt or .csv file in the C:\ directory will be treated as a database table, which you pass in your
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
SQL string:
Chapter 20 - COM Interoperability and ADO.NET
Chapter 21 - Messaging
OdbcConnection conn = new OdbcConnection(ConnectionString);
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
OdbcDataAdapter da = new OdbcDataAdapter
Appendix A - Relational Databases: Some Basic Concepts
("Select * FROM Employees.txt", conn
Appendix B - Commonly Used SQL Statements
Appendix C - ADO.NET Frequently Asked Questions
To test this code, create a Windows application, drop a DataGrid control onto the form, and use the
Index
code
List in Listing 10-3 for the Form_Load event.
of Figures
List of Tables
Listing 10-3: Accessing the TextDB.txt File
List of Listings
List of Sidebars
Private Sub Form1_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
' Connection string for a Text File
Dim connectionString As String = _
"Driver={Microsoft Text Driver (*.txt; *.csv)};DBQ=c:\\"
' Query the Employees.txt file as a table
Dim conn As OdbcConnection = New OdbcConnection(connectionString)
conn.Open()
' Create a data adapter and fill a DataSet
Dim da As OdbcDataAdapter = New OdbcDataAdapter _
("Select * FROM Employees.txt", conn)
Dim ds As DataSet = New DataSet()
Applied
da.Fill(ds, ADO.NET: Building Data-Driven Solutions
"TextDB")
by Mahesh
' Bind the DataSet Chandtoanda David Talbot
DataGrid ISBN:1590590732
Apress 2003 (928 pages)
DataGrid1.DataSource = ds.DefaultViewManager
This text
' Close the provides extensive coverage of ADO.NET technology
connection
including
conn.Close() ADO.NET internals, namespaces, classes, and
interfaces, and takes a comprehensive look at XML
conn.Dispose()
namespaces and classes, and how to integrate both with
End Sub ADO.NET.
Table of Contents
Applied ADO.NETBuilding
Note Data-Driven
Don't forget to add Solutions
a reference to the Microsoft.Data.Odbc namespace.
Introduction
If you compile
Chapter and run
1 - ADO.NET the application, you should see data in the DataGrid control.
Basics
Chapter 2 - Data Components in Visual Studio .NET
Chapter 3 - ADO.NET in Disconnected Environments
Chapter 4 - ADO.NET in Connected Environments
Chapter 5 - Handling ADO.NET Events
Chapter 6 - Integrating XML with ADO.NET
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
Chapter 8 - Constraints and Data Relations
Chapter 9 - ADO.NET Exception Handling
Chapter 10 - Working with the ODBC .NET Data Provider
Chapter 11 - Stored Procedures and Views
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Chapter 13 - Developing a Custom Data Provider
Chapter 14 - Developing Database Web Applications using ASP.NET
Chapter 15 - Using ADO.NET in Xml Web Services
Chapter 16 - ASP.NET Server Controls and Data Binding
Chapter 17 - Building Real-World Web Applications
Chapter 18 - Object-Relational Mapping in .NET
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
Chapter 20 - COM Interoperability and ADO.NET
Chapter 21 - Messaging
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Appendix A - Relational Databases: Some Basic Concepts
Appendix B - Commonly Used SQL Statements
Appendix C - ADO.NET Frequently Asked Questions
Index
List of Figures
List of Tables
List of Listings
List of Sidebars
Accessing Applied
ExcelADO.NET:
Databases
Building Data-Driven Solutions
by Mahesh Chand and David Talbot ISBN:1590590732
You'll now learn how to
Apress connect
2003 (928topages)
Excel databases. If you don't have an Excel database, you can export
data from your Northwind database to test this
This text provides extensive example.
coverage As you did
of ADO.NET in the previous section, export the
technology
Employees table including
from Microsoft
ADO.NET internals, namespaces, classes, and selecting the Export option. (You
Access by right-clicking the table and
can also choose interfaces, and takes a comprehensive look at XML
File Export).
namespaces and classes, and how to integrate both with
When you export,ADO.NET.
make sure you select the Microsoft Excel 97-2000 (*.xls) option in the Save as Type
drop-down list. For this example, save the file as Employees.xls.
Table
Now,ofif Contents
you open Employees.xls, it looks like Figure 10-10.
Applied ADO.NETBuilding Data-Driven Solutions
Introduction
Chapter 1 - ADO.NET Basics
Chapter 2 - Data Components in Visual Studio .NET
Chapter 3 - ADO.NET in Disconnected Environments
Chapter 4 - ADO.NET in Connected Environments
Chapter 5 - Handling ADO.NET Events
Chapter 6 - Integrating XML with ADO.NET
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
Chapter 8 - Constraints and Data Relations
Chapter 9 - ADO.NET Exception Handling
Figure 10-10: Employees.xls data view
Chapter 10 - Working with the ODBC .NET Data Provider
Chapter 11 - Stored Procedures and Views
Again, you can access the Excel database either by using an ODBC DSN or by passing the database
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
name directly in the connection string. In this example, you're passing the database name directly:
Chapter 13 - Developing a Custom Data Provider
Chapter 14 - Developing Database Web Applications using ASP.NET
Dim ConnectionString as string =
Chapter 15 - Using ADO.NET in Xml Web Services
"Driver={Microsoft Excel Driver (*.xls)};DBQ=c:\\Employees.xls"
Chapter 16 - ASP.NET Server Controls and Data Binding
Chapter 17 - Building Real-World Web Applications
After that,
Chapter 18 -the code should beMapping
Object-Relational familiarinto.NET
you. It's the same steps as creating a DataAdapter, selecting
some fields
Chapter of the table,
19 - Mapped filling
Objects: a DataSetConsiderations
Performance from the DataAdapter, and binding data with the data-bound
and Data Binding
controls.
Chapter 20To test this
- COM code, create
Interoperability a Windows
and ADO.NET application, add a DataGrid control and a ListBox
control21
Chapter to the form, and import the Microsoft.Data.Odbc namespace. Listing 10-4 shows the full
- Messaging
source 22
Chapter code.
- SQL Server and ADO.NET: Notes on Performance
Appendix A - Relational Databases: Some Basic Concepts
Listing 10-4: AccessingEmployees.xls Using the ODBC Data Provider
Appendix B - Commonly Used SQL Statements
Appendix C - ADO.NET Frequently Asked Questions
private void Form1_Load(object sender, System.EventArgs e)
Index
{ of Figures
List
// Connection string for ODBC Excel Driver
List of Tables
string ConnectionString =
List of Listings
@"Driver={Microsoft Excel Driver (*.xls)};DBQ=c:\Employees.xls";
List of Sidebars
OdbcConnection conn = new OdbcConnection(ConnectionString);
dataGrid1.DataSource = ds.DefaultViewManager;
listBox1.DataSource = ds.DefaultViewManager;
Applied ADO.NET:
listBox1.DisplayMember Building Data-Driven Solutions
= "Employees.FirstName";
} by Mahesh Chand and David Talbot ISBN:1590590732
Apress 2003 (928 pages)
This text provides extensive coverage of ADO.NET technology
including ADO.NET internals, namespaces, classes, and
interfaces, and takes a comprehensive look at XML
The output of Listing 10-4 looks like Figure 10-11.
namespaces and classes, and how to integrate both with
ADO.NET.
Table of Contents
Applied ADO.NETBuilding Data-Driven Solutions
Introduction
Chapter 1 - ADO.NET Basics
Chapter 2 - Data Components in Visual Studio .NET
Chapter 3 - ADO.NET in Disconnected Environments
Chapter 4 - ADO.NET in Connected Environments
Chapter 5 - Handling ADO.NET Events
Chapter 6 - Integrating XML with ADO.NET
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
Figure 10-11: Output of Listing 10-4
Chapter 8 - Constraints and Data Relations
Chapter 9 - ADO.NET Exception Handling
Chapter 10 - Working with the ODBC .NET Data Provider
Chapter 11 - Stored Procedures and Views
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Chapter 13 - Developing a Custom Data Provider
Chapter 14 - Developing Database Web Applications using ASP.NET
Chapter 15 - Using ADO.NET in Xml Web Services
Chapter 16 - ASP.NET Server Controls and Data Binding
Chapter 17 - Building Real-World Web Applications
Chapter 18 - Object-Relational Mapping in .NET
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
Chapter 20 - COM Interoperability and ADO.NET
Chapter 21 - Messaging
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Appendix A - Relational Databases: Some Basic Concepts
Appendix B - Commonly Used SQL Statements
Appendix C - ADO.NET Frequently Asked Questions
Index
List of Figures
List of Tables
List of Listings
List of Sidebars
Implementing Two
Applied .NETBuilding
ADO.NET: 1.1 Updates
Data-Driven Solutions
by Mahesh Chand and David Talbot ISBN:1590590732
The following twoApress
.NET version 1.1
2003 (928 updates affect the ODBC data provider:
pages)
This text provides extensive coverage of ADO.NET technology
Require FullTrust forADO.NET
including OleDb, ODBC, and
internals, OracleClient:
namespaces, Youand
classes, can now use portions of
System.Data interfaces, andtrusted
in partially takes aapplications,
comprehensive look
such asatSQL
XMLClient. This means that it's now
necessary tonamespaces and classes, and how to integrate both with
require FullTrust permission for OleDb, ODBC, and OracleClient. It's not possible to
ADO.NET.
allow these providers to work in partially trusted scenarios because of their interaction with native
pointers and Application Programming Interfaces (APIs).
Table of Contents
Applied ADO.NETBuilding
Workaround: Data-Driven
If you're Solutions
using .NET Framework version 1.0 and are setting system.data.dll as
Introduction
allowed in partially trusted scenarios, you must modify your security settings to allow these
Chapter 1 - ADO.NET
components Basics
to work in partially trusted scenarios.
Chapter 2 - Data Components in Visual Studio .NET
Chapter 3 - ADO.NET in Disconnected Environments
Removed an OnStateChange(Open) event from OLE DB client and ODBC client packages: The
Chapter 4 - ADO.NET in Connected Environments
.NET Framework version 1.0 was incorrectly firing an OnStatechange(Open) event when there was
Chapter 5 - Handling ADO.NET Events
an invalid connection string.
Chapter 6 - Integrating XML with ADO.NET
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
Workaround:
Chapter No workaround
8 - Constraints is available for this change. Generally, this indicates that the change
and Data Relations
isn't intended to have a workaround.
Chapter 9 - ADO.NET Exception Handling
Chapter 10 - Working with the ODBC .NET Data Provider
Chapter 11 - Stored Procedures and Views
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Chapter 13 - Developing a Custom Data Provider
Chapter 14 - Developing Database Web Applications using ASP.NET
Chapter 15 - Using ADO.NET in Xml Web Services
Chapter 16 - ASP.NET Server Controls and Data Binding
Chapter 17 - Building Real-World Web Applications
Chapter 18 - Object-Relational Mapping in .NET
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
Chapter 20 - COM Interoperability and ADO.NET
Chapter 21 - Messaging
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Appendix A - Relational Databases: Some Basic Concepts
Appendix B - Commonly Used SQL Statements
Appendix C - ADO.NET Frequently Asked Questions
Index
List of Figures
List of Tables
List of Listings
List of Sidebars
Summary Applied ADO.NET: Building Data-Driven Solutions
by Mahesh Chand and David Talbot ISBN:1590590732
The best thing about
ApressADO.NET is pages)
2003 (928 that it treats all types of data sources similarly. As we've stated
repeatedly, the only difference is the connection
This text provides extensive stringofand
coverage the class
ADO.NET names. If you know how to build a
technology
connection string,including
you canADO.NET
use the same code to work with multiple
internals, namespaces, classes, and data sources. Based on this theory,
interfaces,
you saw how to work and
with the takes aOracle,
MySQL, comprehensive
and Sybaselook at XML
databases. You also saw how to work with
namespaces
Excel spreadsheets and classes, and how to integrate both with
and text files.
ADO.NET.
When it comes to the performance of database applications, server-side data objects such as stored
procedures and views play a vital role. ADO.NET-with the help of VS .NET-provides great support for
Table of Contents
creating, managing, and executing stored procedures. The next chapter covers stored procedures and
Applied ADO.NETBuilding Data-Driven Solutions
views, as well as how to write database applications using these two objects.
Introduction
Chapter 1 - ADO.NET Basics
Chapter 2 - Data Components in Visual Studio .NET
Chapter 3 - ADO.NET in Disconnected Environments
Chapter 4 - ADO.NET in Connected Environments
Chapter 5 - Handling ADO.NET Events
Chapter 6 - Integrating XML with ADO.NET
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
Chapter 8 - Constraints and Data Relations
Chapter 9 - ADO.NET Exception Handling
Chapter 10 - Working with the ODBC .NET Data Provider
Chapter 11 - Stored Procedures and Views
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Chapter 13 - Developing a Custom Data Provider
Chapter 14 - Developing Database Web Applications using ASP.NET
Chapter 15 - Using ADO.NET in Xml Web Services
Chapter 16 - ASP.NET Server Controls and Data Binding
Chapter 17 - Building Real-World Web Applications
Chapter 18 - Object-Relational Mapping in .NET
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
Chapter 20 - COM Interoperability and ADO.NET
Chapter 21 - Messaging
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Appendix A - Relational Databases: Some Basic Concepts
Appendix B - Commonly Used SQL Statements
Appendix C - ADO.NET Frequently Asked Questions
Index
List of Figures
List of Tables
List of Listings
List of Sidebars
Chapter Applied
11: Stored Procedures ISBN:1590590732
and Views
ADO.NET: Building Data-Driven Solutions
by Mahesh Chand and David Talbot
Apress
Relational databases 2003
such as (928
SQLpages)
Server and Oracle rely on stored procedures to do repetitive tasks, so
This text provides
a programmer's main jobs when creating extensive coverageapplications
database of ADO.NETaretechnology
creating, debugging, and testing
including ADO.NET internals, namespaces, classes, and
stored procedures (often called stored procs). Another database object it behooves programmers to learn
interfaces, and takes a comprehensive look at XML
is the view-or virtual table. In this
namespaces and chapter, you'll
classes, and howlearn how to take
to integrate bothadvantage
with of Visual Studio .NET (VS
.NET) tools to work with both stored procedures and views.
ADO.NET.
The right-click menu option allows you to create a new stored procedure and edit, delete, and execute
existing stored procedures (see Figure 11-2).
Applied ADO.NET: Building Data-Driven Solutions
by Mahesh Chand and David Talbot ISBN:1590590732
Apress 2003 (928 pages)
This text provides extensive coverage of ADO.NET technology
including ADO.NET internals, namespaces, classes, and
interfaces, and takes a comprehensive look at XML
namespaces and classes, and how to integrate both with
ADO.NET.
Table of Contents
Applied ADO.NETBuilding Data-Driven Solutions
Introduction
Chapter 1 - ADO.NET Basics
Chapter 2 - Data Components in Visual Studio .NET
Chapter 3 - ADO.NET in Disconnected Environments
Chapter 4 - ADO.NET in Connected Environments
Figure
Chapter 5 - 11-2: Create,
Handling edit,Events
ADO.NET delete, and run stored procedure options
Chapter 6 - Integrating XML with ADO.NET
Chapter 7 Stored
The Edit - Data Procedure
Binding andoption
WindowsletsForms Data-Bound
you edit Controls
a stored procedure. To edit an existing stored procedure of
the Northwind
Chapter database,
8 - Constraints right-click
and the CustOrderHist stored procedure, and select the Edit Stored
Data Relations
Procedure
Chapter 9 - option.
ADO.NET The stored procedure
Exception Handling editor opens (see Figure 11-3).
Chapter 10 - Working with the ODBC .NET Data Provider
Chapter 11 - Stored Procedures and Views
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Chapter 13 - Developing a Custom Data Provider
Chapter 14 - Developing Database Web Applications using ASP.NET
Chapter 15 - Using ADO.NET in Xml Web Services
Chapter 16 - ASP.NET Server Controls and Data Binding
Chapter 17 - 11-3:
Figure Building Real-World
Stored Web Applications
procedure editor
Chapter 18 - Object-Relational Mapping in .NET
Note
Chapter 19 In SQL Server,
- Mapped thePerformance
Objects: login that creates or has the
Considerations ownership
and of a database or the administrator of
Data Binding
Chapter 20 the server
- COM is known asand
Interoperability the ADO.NET
database owner. In the database and its objects, the username dbo is
Chapter 21 always associated with the login name of the database owner.
- Messaging
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Now that you know how to edit an existing stored procedure, let's create a one. You can create a stored
Appendix A - Relational Databases: Some Basic Concepts
procedure by right-clicking the Stored Procedures node and selecting the New Stored Procedure option.
Appendix B - Commonly Used SQL Statements
This launches the stored procedure editor, which you use to write stored procedures. In SQL Server, dbo
Appendix
stands forC -the
ADO.NET Frequently
database Asked
owner. In Questions
Figure 11-4, the syntax CREATE PROCEDURE
Index
dbo.StoredProcedure2 creates a stored procedure where StoredProcedure1 is the name of the
List of Figures
stored procedure and dbo is the owner of the stored procedure.
List of Tables
List of Listings
List of Sidebars
A stored procedure can return data as a result of SELECT statement, a return code (an integer value), or
an output parameter. As you can see from Figure 11-4, the section after CREATE PROCEDURE is the
parameters section, which is closed with comments (/* and */). If you have no requirement for using
parameters in a stored procedure, you can skip this area. The section after AS is used for the actual SQL
Applied
statement, and the sectionADO.NET: Building
after RETURN Data-Driven
is used Solutions
for returning a value when you execute a stored
procedure. by Mahesh Chand and David Talbot ISBN:1590590732
Apress 2003 (928 pages)
Now, you can write a simple
This SELECT
text provides statement
extensive and save
coverage it as a stored
of ADO.NET procedure. Use this SQL
technology
including
statement to select ADO.NETvalues
three columns internals,
for namespaces, classes,
customers from and
the United States:
interfaces, and takes a comprehensive look at XML
namespaces and classes, and how to integrate both with
SELECT CustomerId,
ADO.NET.CompanyName, ContactName
FROM Customers WHERE Country ='USA'
Table of Contents
You can
Applied change the stored
ADO.NETBuilding procedureSolutions
Data-Driven name to whatever you want; this example uses mySP (my stored
procedure). The final stored procedure looks like Figure 11-5.
Introduction
Chapter 1 - ADO.NET Basics
Chapter 2 - Data Components in Visual Studio .NET
Chapter 3 - ADO.NET in Disconnected Environments
Chapter 4 - ADO.NET in Connected Environments
Chapter 5 - Handling ADO.NET Events
Chapter 6 - Integrating XML with ADO.NET
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
Chapter 8 - Constraints and Data Relations
Chapter 9 - ADO.NET Exception Handling
Chapter 10 - Working with the ODBC .NET Data Provider
Chapter 11 - Stored Procedures and Views
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Figure 11-5: ThemySP stored procedure in the editor
Chapter 13 - Developing a Custom Data Provider
Chapter
You can14save
- Developing
a stored Database
procedureWeb Applications
by using File using
SaveASP.NET
mySP or the Save All menu option or toolbar
Chapter 15 - Using ADO.NET in Xml Web Services
button. The Save option is also available after right-clicking on the stored procedure editor.
Chapter 16 - ASP.NET Server Controls and Data Binding
Note
Chapter 17 The Save Real-World
- Building option not only
Web creates a stored procedure, but it also changes the CREATE
Applications
Chapter 18 PROCEDURE statement
- Object-Relational to ALTER
Mapping in .NET PROCEDURE because the stored procedure has already been
Chapter 19 created.
- Mapped Objects: Performance Considerations and Data Binding
Chapter 20 - COM Interoperability and ADO.NET
Now, if you go to the Server Explorer and look at all the stored procedures for the Northwind database,
Chapter 21 - Messaging
your stored procedure should be listed. As you can see from Figure 11-6, the stored procedure mySP has
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
three fields listed under it that appear in the SELECT statement.
Appendix A - Relational Databases: Some Basic Concepts
Appendix B - Commonly Used SQL Statements
Appendix C - ADO.NET Frequently Asked Questions
Index
List of Figures
List of Tables
List of Listings
List of Sidebars
Applied ADO.NET: Building Data-Driven Solutions
by Mahesh Chand and David Talbot ISBN:1590590732
Apress 2003 (928 pages)
This text provides extensive coverage of ADO.NET technology
including ADO.NET internals, namespaces, classes, and
interfaces, and takes a comprehensive look at XML
namespaces and classes, and how to integrate both with
ADO.NET.
Table of Contents
Applied ADO.NETBuilding Data-Driven Solutions
Introduction
Chapter 1 - ADO.NET Basics
Chapter 2 - Data Components in Visual Studio .NET
Chapter 3 - ADO.NET in Disconnected Environments
Chapter 4 - ADO.NET in Connected Environments
Chapter 5 - Handling ADO.NET Events
Chapter 6 - Integrating XML with ADO.NET
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
Chapter 8 - Constraints and Data Relations
Figure 11-6: ThemySP stored procedure listed for the Northwind database
Chapter 9 - ADO.NET Exception Handling
Chapter 10 - Working with the ODBC .NET Data Provider
Chapter 11 - Stored Procedures and Views
Executing a Stored Procedure from VS .NET
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Chapter 13 -a Developing
Executing a Custom
stored procedure DataServer
in the Provider
Explorer is simple. You run (or execute) a stored procedure by
Chapter 14 - Developing Database Web Applications using ASP.NET
right-clicking on the stored procedure editor and selecting Run Stored Procedure.
Chapter 15 - Using ADO.NET in Xml Web Services
When you
Chapter 16 -run the stored
ASP.NET procedure
Server mySP,
Controls and theBinding
Data output looks like Figure 11-7.
Chapter 17 - Building Real-World Web Applications
Chapter 18 - Object-Relational Mapping in .NET
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
Chapter 20 - COM Interoperability and ADO.NET
Chapter 21 - Messaging
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Appendix A - Relational Databases: Some Basic Concepts
Appendix B - Commonly Used SQL Statements
Appendix C - ADO.NET Frequently Asked Questions
Index
List of Figures
List of Tables
List of Listings
List of Sidebars
Note Like your SELECT SQL statement, you can use almost any SQL statement, such as UPDATE
andDELETE, in the stored procedure. (Exceptions include CREATE TRIGGER,CREATE VIEW,
CREATE DEFAULT,CREATE PROCEDURE, and CREATE RULE.)
A stored procedure can also accept input parameters. For example, the CustOrdersDetail stored
procedure takes a parameter value of OrderID. Based on the OrderID value, it returns ProductName
and calculates Discount and ExtendedPrice (see Figure 11-8).
Applied ADO.NET: Building Data-Driven Solutions
by Mahesh Chand and David Talbot ISBN:1590590732
Apress 2003 (928 pages)
This text provides extensive coverage of ADO.NET technology
including ADO.NET internals, namespaces, classes, and
interfaces, and takes a comprehensive look at XML
namespaces and classes, and how to integrate both with
ADO.NET.
As an application developer, most of the time you'll be creating and testing stored procedures
programmatically. You can execute a stored procedure programmatically using the Command object.
Instead of passing a SQL statement, you pass the stored procedure name as the SQL statement to
execute a stored procedure. As you saw in Chapter 4, each data provider provides a Command object to
execute SQL statements. The Command classes for the OleDb, ODBC, and Sql data providers are
OleDbCommand,OdbcCommand, and SqlCommand (respectively). Listing 11-1 shows how to use
SqlCommand to execute a stored procedure programmatically against a SQL Server database.
Listing 11-1: Executing the mySP Stored Procedure Using the Sql Data Provider
Sub Main()
' Create a Connection Object
Applied ADO.NET:
Dim ConnectionString AsBuilding
String Data-Driven Solutions
= "Integrated Security=SSPI;" & _
by "Initial
Mahesh Chand and David Talbot
Catalog=Northwind;" & ISBN:1590590732
_
Apress
"Data 2003 (928 pages)
Source=localhost;"
This text provides
Dim conn As SqlConnection extensive
= coverage of ADO.NET technology
New SqlConnection(ConnectionString)
including
' Open the connection ADO.NET internals, namespaces, classes, and
interfaces, and takes a comprehensive look at XML
conn.Open() namespaces and classes, and how to integrate both with
' Create ADO.NET.
a SqlCommand object and pass mySP as the
' SQL command and set CommandType property to
' CommandType.StoredProcedure
Table of Contents
Dim cmd As SqlCommand = New SqlCommand("mySP", conn)
Appliedcmd.CommandType
ADO.NETBuilding Data-Driven Solutions
= CommandType.StoredProcedure
Introduction
' Call ExecuteReader of SqlCommand
ChapterDim
1 -reader
ADO.NET AsBasics
SqlDataReader = cmd.ExecuteReader()
Chapter'2 Read
- Data Components
all data and in Visual Studio on
display .NETthe console
ChapterWhile reader.Read()
3 - ADO.NET in Disconnected Environments
Chapter 4 Console.Write(reader(0).ToString())
- ADO.NET in Connected Environments
Chapter 5 Console.Write(reader(1).ToString())
- Handling ADO.NET Events
Chapter 6 Console.WriteLine(reader(2).ToString())
- Integrating XML with ADO.NET
ChapterEnd
7 -While
Data Binding and Windows Forms Data-Bound Controls
Console.Read()
Chapter 8 - Constraints and Data Relations
' Close reader and connection
Chapter 9 - ADO.NET Exception Handling
reader.Close()
Chapter 10 - Working with the ODBC .NET Data Provider
conn.Close()
Chapter 11 - Stored Procedures and Views
End Sub
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Chapter 13 - Developing a Custom Data Provider
Chapter 14 - Developing Database Web Applications using ASP.NET
Chapter 15 -two
There are Using ADO.NET
steps in Xml
involved Web Services
in executing a stored procedure from your program. First, you set the
Chapter
Command16 -object property
ASP.NET ServerCommandText to the
Controls and Data stored procedure name; second, you set the
Binding
CommandType
Chapter property
17 - Building to CommandType.StoredProcedure.
Real-World Web Applications Listing 11-1 executes the mySP stored
procedure
Chapter 18 -you created in theMapping
Object-Relational previousinsection.
.NET To test code in Listing 11-1, create a console application
and type
Chapter 19Listing 11-1Objects:
- Mapped on the Main method.
Performance Don't forget and
Considerations to import the following two namespaces to the
Data Binding
project 20
Chapter before
- COMusing Sql data provider
Interoperability classes:
and ADO.NET
Chapter 21 - Messaging
Imports
Chapter 22 -System.Data
SQL Server and ADO.NET: Notes on Performance
Imports
Appendix A -System.Data.SqlClient
Relational Databases: Some Basic Concepts
Appendix B - Commonly Used SQL Statements
Appendix C - ADO.NET Frequently Asked Questions
Listing 11-1, creates a SqlCommand object by passing the stored procedure as the first parameter of the
Index
SqlCommand constructor and then sets the CommandType property
List of Figures
CommandType.StoredProcedure. The result of Listing 11-1 looks like Figure 11-11.
List of Tables
List of Listings
List of Sidebars
A stored procedure can also accept input, output, or both types of parameters. Next, let's modify the mySP
stored procedure a little bit. This time give the user an option to select the customers based on their
Applied ADO.NET: Building Data-Driven Solutions
country. The modified stored procedure looks like Figure 11-12.
by Mahesh Chand and David Talbot ISBN:1590590732
Apress 2003 (928 pages)
This text provides extensive coverage of ADO.NET technology
including ADO.NET internals, namespaces, classes, and
interfaces, and takes a comprehensive look at XML
namespaces and classes, and how to integrate both with
ADO.NET.
Table of Contents
Applied ADO.NETBuilding Data-Driven Solutions
Introduction
Figure 11-12: A stored procedure with parameters
Chapter 1 - ADO.NET Basics
As you 2can- Data
Chapter see from Figure 11-12,
Components theStudio
in Visual stored.NET
procedure selects customers based on the country entered
by the user.
Chapter 3
You can use the SqlParameter class to create a parameter. The SqlParameter class has
- ADO.NET in Disconnected Environments
properties such as Direction and Value. The Direction property defines whether the stored
Chapter 4 - ADO.NET in Connected Environments
procedure is an input, output, or both. It also defines whether it has a return value. The
Chapter 5 - Handling ADO.NET Events
ParameterDirection enumeration defines values of Direction (see Table 11-1).
Chapter 6 - Integrating XML with ADO.NET
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
Table 11-1: The ParameterDirection Members
Chapter 8 - Constraints and Data Relations
MEMBER
Chapter 9 - ADO.NETDESCRIPTION
Exception Handling
Chapter 10 - Working with the ODBC .NET Data Provider
Input Input parameter
Chapter 11 - Stored Procedures and Views
InputOutput
Chapter Both input
12 - Oracle, SQLXML, andand output
Other .NETparameter
Data Providers
Chapter 13 - Developing a Custom Data Provider
Output Output only
Chapter 14 - Developing Database Web Applications using ASP.NET
ReturnValue
Chapter Returns
15 - Using ADO.NET in aXml
value
Webfrom the stored procedure
Services
Chapter 16 - ASP.NET Server Controls and Data Binding
Chapter 17 - Building Real-World Web Applications
TheValue property sets the value of the parameter. The following code adds a parameter with the value
Chapter 18 - Object-Relational Mapping in .NET
UK. After you execute the mySP stored procedure, it will return customers from the United Kingdom only:
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
Chapter 20 - COM Interoperability and ADO.NET
'Set the SqlParameter
Chapter 21 - Messaging
Dim param As SqlParameter = New SqlParameter()
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
param = cmd.Parameters.Add("@country", SqlDbType.VarChar, 50)
Appendix A - Relational Databases: Some Basic Concepts
param.Direction = ParameterDirection.Input
Appendix B - Commonly Used SQL Statements
param.Value = "UK"
Appendix C - ADO.NET Frequently Asked Questions
Index
List
The of updated
Figures source code looks like Listing 11-2, and the output of Listing 11-2 looks like Figure 11-13.
Listing
List 11-2 creates SqlParameter as the country and sets its value to UK.ExecuteReader only
of Tables
returns
List rows where Country = "UK".
of Listings
List of Sidebars
Table of Contents
Applied ADO.NETBuilding Data-Driven Solutions
Introduction
Chapter 1 - ADO.NET Basics
Chapter 2 - Data Components in Visual Studio .NET
Figure 11-15: Creating a view after selecting columns from three tables
Chapter 3 - ADO.NET in Disconnected Environments
Chapter
You can4 save
- ADO.NET in Connected
a view by Environments
using the Save button, by using File Save, or by right-clicking on the view and
Chapter 5 Save
selecting - Handling ADO.NET
ViewName (seeEvents
Figure 11-16).
Chapter 6 - Integrating XML with ADO.NET
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
Chapter 8 - Constraints and Data Relations
Chapter 9 - ADO.NET Exception Handling
Chapter 10 - Working with the ODBC .NET Data Provider
Chapter 11 - Stored Procedures and Views
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Chapter 13 - Developing a Custom Data Provider
Chapter 14 - Developing Database Web Applications using ASP.NET
Chapter 15 - Using ADO.NET in Xml Web Services
Chapter 16 - ASP.NET Server Controls and Data Binding
Chapter 17 - Building Real-World Web Applications
Figure
Chapter 18 - 11-16: Saving a view
Object-Relational Mapping in .NET
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
Chapter
For this20 - COM Interoperability
example, save the view asandCustEmpView
ADO.NET and click OK (see Figure 11-17).
Chapter 21 - Messaging
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Appendix A - Relational Databases: Some Basic Concepts
Appendix B - Commonly Used SQL Statements
Appendix C - ADO.NET Frequently Asked Questions
Index
List of Figures
List of Tables
List of Listings
Figure 11-17: Entering a name for the view
List of Sidebars
When you now see the Server Explorer views, you'll see CustEmpView listed (see Figure 11-18).
Applied ADO.NET: Building Data-Driven Solutions
by Mahesh Chand and David Talbot ISBN:1590590732
Apress 2003 (928 pages)
This text provides extensive coverage of ADO.NET technology
including ADO.NET internals, namespaces, classes, and
interfaces, and takes a comprehensive look at XML
namespaces and classes, and how to integrate both with
ADO.NET.
Table of Contents
Applied ADO.NETBuilding Data-Driven Solutions
Introduction
Chapter 1 - ADO.NET Basics
Chapter 2 - Data Components in Visual Studio .NET
Chapter 3 - ADO.NET in Disconnected Environments
Chapter 4 - ADO.NET in Connected Environments
Chapter 5 - Handling ADO.NET Events
Chapter 6 - Integrating XML with ADO.NET
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
Chapter 8 - Constraints and Data Relations
Figure 11-18: Available views in the Server Explorer
Chapter 9 - ADO.NET Exception Handling
Chapter 10 - Working with the ODBC .NET Data Provider
Chapter 11 - Stored Procedures and Views
Executing a View from VS .NET
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Chapter 13 - Developing
To execute a Custom
a view, right-click it inData Provider
the Server Explorer and select Retrieve Data from the View option. The
Chapter 14 CustEmpView
output of - Developing Database
looks likeWeb Applications
Figure 11-19. using ASP.NET
Chapter 15 - Using ADO.NET in Xml Web Services
Chapter 16 - ASP.NET Server Controls and Data Binding
Chapter 17 - Building Real-World Web Applications
Chapter 18 - Object-Relational Mapping in .NET
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
Chapter 20 - COM Interoperability and ADO.NET
Chapter 21 - Messaging
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Appendix A - 11-19:
Figure Relational Databases:
Results of the Some Basic Concepts
CustEmpView view after executing it from the Server Explorer
Appendix B - Commonly Used SQL Statements
Appendix C - ADO.NET Frequently Asked Questions
Retrieving Data from a View Programmatically
Index
List of Figures
In the
List same way that you execute a stored proc, the Command object executes a view. You can retrieve
of Tables
data
List of from a view programmatically by replacing the view name with the table name in a SQL statement.
Listings
Listing
List 11-5 shows you how to use the CustEmpView view in an application. As you can see, the code
of Sidebars
uses the CustEmpView view as the table name in the SELECT statement:
Table of Contents
Applied ADO.NETBuilding Data-Driven Solutions
To test this code, create a Windows application in VS .NET, add a DataGrid control to the form, and
Introduction
write the
Chapter 1 code in Listing
- ADO.NET 11-5 on the Form_Load event. Also, don't forget to import the
Basics
System.Data.SqlClient
Chapter namespace
2 - Data Components in in the
Visual Studio .NETproject.
Chapter 3 - ADO.NET in Disconnected Environments
The output of Listing 11-5 looks like Figure 11-20.
Chapter 4 - ADO.NET in Connected Environments
Chapter 5 - Handling ADO.NET Events
Chapter 6 - Integrating XML with ADO.NET
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
Chapter 8 - Constraints and Data Relations
Chapter 9 - ADO.NET Exception Handling
Chapter 10 - Working with the ODBC .NET Data Provider
Chapter 11 - Stored Procedures and Views
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Chapter 13 - Developing a Custom Data Provider
Chapter 14 - Developing Database Web Applications using ASP.NET
Chapter 15 - Using ADO.NET in Xml Web Services
Chapter 16 - ASP.NET Server Controls and Data Binding
Figure
Chapter 17 - 11-20:
BuildingThe output the
Real-World WebCustEmpView
Applications view from a program
Chapter 18 - Object-Relational Mapping in .NET
Caution TheORDER BY,COMPUTE,COMPUTE BY, and INTO SQL keywords don't work with views.
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
Chapter 20 - COM Interoperability and ADO.NET
Filling a DataSet from Multiple Views
Chapter 21 - Messaging
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
If you want, you can fill a DataSet from multiple views. You just need to change the SQL statement you
Appendix A - Relational Databases: Some Basic Concepts
used in Listing 11-5. For example, say you want to fill a DataSet from the CustEmpView and Invoices
Appendix B - Commonly Used SQL Statements
views. Just replace the SQL statement in Listing 11-5 with the following:
Appendix C - ADO.NET Frequently Asked Questions
Index
Dim adapter As SqlDataAdapter = New SqlDataAdapter _
List of Figures
("SELECT * FROM CustEmpView; SELECT * FROM Invoices", conn)
List of Tables
List of Listings
List of Sidebars
Summary Applied ADO.NET: Building Data-Driven Solutions
by Mahesh Chand and David Talbot ISBN:1590590732
VS .NET providesApress
plentyof support
2003 to create and manage stored procedures and views. This chapter
(928 pages)
discussed how you can take advantage of the
This text provides extensive VS .NET
coverage of tools to create,
ADO.NET manage, and execute stored
technology
procedures and views. You also learned how to work with stored
including ADO.NET internals, namespaces, classes, and procedures and views programmatically
as well. interfaces, and takes a comprehensive look at XML
namespaces and classes, and how to integrate both with
ADO.NET.
In the next chapter, we'll discuss two new data providersOracle and XML .NETand see how to use
these data providers to work with Oracle databases and XML data sources.
Table of Contents
Applied ADO.NETBuilding Data-Driven Solutions
Introduction
Chapter 1 - ADO.NET Basics
Chapter 2 - Data Components in Visual Studio .NET
Chapter 3 - ADO.NET in Disconnected Environments
Chapter 4 - ADO.NET in Connected Environments
Chapter 5 - Handling ADO.NET Events
Chapter 6 - Integrating XML with ADO.NET
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
Chapter 8 - Constraints and Data Relations
Chapter 9 - ADO.NET Exception Handling
Chapter 10 - Working with the ODBC .NET Data Provider
Chapter 11 - Stored Procedures and Views
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Chapter 13 - Developing a Custom Data Provider
Chapter 14 - Developing Database Web Applications using ASP.NET
Chapter 15 - Using ADO.NET in Xml Web Services
Chapter 16 - ASP.NET Server Controls and Data Binding
Chapter 17 - Building Real-World Web Applications
Chapter 18 - Object-Relational Mapping in .NET
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
Chapter 20 - COM Interoperability and ADO.NET
Chapter 21 - Messaging
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Appendix A - Relational Databases: Some Basic Concepts
Appendix B - Commonly Used SQL Statements
Appendix C - ADO.NET Frequently Asked Questions
Index
List of Figures
List of Tables
List of Listings
List of Sidebars
Chapter Applied
12: Oracle, SQLXML, and
by Mahesh Chand and David Talbot
Other .NET Data
ADO.NET: Building Data-Driven Solutions
ISBN:1590590732
Providers
Apress 2003 (928 pages)
This text provides extensive coverage of ADO.NET technology
including
In previous chapters, ADO.NET internals,
we discussed namespaces,
the Sql, OleDb, classes,
and ODBC and
data providers and how to use them work
interfaces, and takes a comprehensive look at XML
with various databases including SQL Server, Access, Excel, and MySQL.
namespaces and classes, and how to integrate both with
As mentioned, ADO.NET is
flexible enough so anyone
ADO.NET. can develop their data provider and add it to the library as an add-on.
In this chapter, you'll see some more data providers. Once you've come to grips with any one data
provider,
Table working with the rest of them is a piece of cake. All data providers implement a similar class
of Contents
hierarchy
Applied model with onlyData-Driven
ADO.NETBuilding a few changes.
Solutions
Introduction
Using Oracle
Chapter 1 .NET Data Providers
- ADO.NET Basics
Chapter 2 - Data Components in Visual Studio .NET
Besides3 the
Chapter OleDb and
- ADO.NET ODBC providers,
in Disconnected you can use other data providers to access an Oracle database:
Environments
Chapter 4 - ADO.NET in Connected Environments
Microsoft has developed the Oracle .NET data provider (although some documentation refers to it as
Chapter 5 - Handling ADO.NET Events
theOracle managed provider.
Chapter 6 - Integrating XML with ADO.NET
Chapter 7 - has
Oracle Datadeveloped
Binding andthe
Windows
OracleForms Data-Bound
data provider Controls
for .NET or ODP.NET.
Chapter 8 - Constraints and Data Relations
CoreLab
Chapter Software
9 - ADO.NET Development
Exception has developed the OraDirect.NET data provider.
Handling
Chapter 10 - Working with the ODBC .NET Data Provider
So, why there are so many approaches to access a database? Why can't they just provide a single
Chapter 11 That's
provider? - Stored
theProcedures and Views
pity and beauty of software development. Users are never satisfied. No matter how
Chapter 12 - Oracle, SQLXML, and
good a product you develop, you'llOther .NETfind
always Data Providers somewhere complaining about it. It may be a
somebody
Chapter 13 - Developing
performance a Custom
issue, it may Data Provider
lack features, or it may contain bugs.
Chapter 14 - Developing Database Web Applications using ASP.NET
By having
Chapter 15 -the ODBC
Using and OleDb
ADO.NET in Xmldata
Webproviders,
Services you can leverage the existing ODBC and OLE DB
technologies
Chapter satisfactory
16 - ASP.NET to Controls
Server developers
and working with Oracle database. However, data access using OLE
Data Binding
DB and17
Chapter ODBC isn't satisfactory
- Building to developers.
Real-World Web ApplicationsFor example, when you compare the performance of the
OleDb data provider to the performance of the Sql provider.
Chapter 18 - Object-Relational Mapping in .NET
Chapter 19 - Mapped
The OleDB Objects:
data provider Performance
provides Considerations
data access anddata
for generic Datasources
Binding and isn't designed to work with a
Chapter 20 - COM Interoperability and ADO.NET
specific database. OLE DB is a COM library, so the OleDb data provider uses COM Interop services
Chapter 21 to
internally - Messaging
provide connectivity with Oracle databases, which causes a performance hit for each use
Chapter
because of- moving
22 SQL Server and ADO.NET:
between Notesand
the managed on Performance
unmanaged spaces. On the other hand, the Oracle data
Appendix
providerAworks
- Relational Databases:
with Oracle Someonly.
databases BasicNot
Concepts
only that, the Oracle data provider skips COM Interop
servicesBand
Appendix provides database
- Commonly connectivity by directly using the Oracle Call Interface (OCI) as provided
Used SQL Statements
by Oracle
Appendix C -client software.
ADO.NET Frequently Asked Questions
Index
Note A recent survey, published in an article on MSDN
List of Figures
(www.microsoft.com/indonesia/msdn/ManProOracPerf.asp ), claims that the Oracle data provider
List of Tables
could be lot faster than the OleDb data provider.
List of Listings
List of Sidebars
Microsoft's Oracle data provider is free and is included as part of Visual Studio .NET (VS .NET) 2003. If
you're running VS .NET 1.0, you need to install it separately. You can download it from the Microsoft's
download section (http://microsoft.com/downloads/). The ODP.NET provider from Oracle
Corporation is also free. You can download it from Oracle's Web site at
http://otn.oracle.com/tech/windows/odpnet/content.html. OraDirect.NET currently costs
$99 and is available at www.crlab.com/products.html.
Caution There may be some changes in these URLs. See the C# Corner (www.c-sharpcorner.com)
Downloads section for the latest links.
Table of Contents
Applied ADO.NETBuilding Data-Driven Solutions
Introduction
Chapter 1 - ADO.NET Basics
Chapter 2 - Data Components in Visual Studio .NET
Chapter 3 - ADO.NET in Disconnected Environments
Chapter 4 - ADO.NET in Connected Environments
Chapter 5 - Handling ADO.NET Events
Chapter 6 - Integrating XML with ADO.NET
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
Chapter 8 - Constraints and Data Relations
Chapter 9 - ADO.NET Exception Handling
Chapter 10 - Working with the ODBC .NET Data Provider
Chapter 11 - Stored Procedures and Views
Figure
Chapter 12 - 12-1:
Oracle,Adding a reference
SQLXML, and Otherto.NET
System.Data.OracleClient.dll
Data Providers
Chapter 13 - Developing a Custom Data Provider
Note In Microsoft VS .NET 2003, the System.Data.OracleClient namespace is already
Chapter 14 - Developing Database Web Applications using ASP.NET
available without adding a reference to the System.Data.OracleClient.dll.
Chapter 15 - Using ADO.NET in Xml Web Services
Chapter
Adding16 - ASP.NETto
a reference Server Controls and Data Binding
System.Data.OracleClient.dll adds the System.Data.OracleClient
Chapter
namespace to your project. To Web
17 - Building Real-World Applications
use the Oracle data provider classes, you must add the following line to
Chapter 18 - Object-Relational Mapping in .NET
your project:
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
Chapter
Imports20 -System.Data.OracleClient
COM Interoperability and ADO.NET
Chapter 21 - Messaging
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Appendix A - Relational Databases: Some Basic Concepts
Appendix B - Commonly Used SQL Statements
Using the Oracle .NET Data Provider Classes
Appendix C - ADO.NET Frequently Asked Questions
Index
The Oracle data provider class hierarchy model is similar to other data providers. As with other data
List of Figures
providers, it also has classes for Connection,Command,DataAdapter,DataReader,Transaction,
List of Tables and so on. Table 12-1 describes the Oracle data provider common classes briefly.
Parameter,
List of Listings
Table
List 12-1: Oracle Data Provider Classes
of Sidebars
CLASS DESCRIPTION
Applied ADO.NET: Building Data-Driven Solutions
by Mahesh Chand and David Talbot ISBN:1590590732
OracleConnection Connection class
Apress 2003 (928 pages)
OracleCommand Command
This text provides extensive class
coverage of ADO.NET technology
including ADO.NET internals, namespaces, classes, and
OracleCommandBuilder CommandBuilder
interfaces, and takes a comprehensive look atclass
XML
namespaces and classes, and how to integrate both with
OracleDataAdapter
ADO.NET. DataAdapter class
OracleDataReader DataReader class
Table of Contents
OracleParameter Parameter class
Applied ADO.NETBuilding Data-Driven Solutions
OracleParameterCollection
Introduction ParameterCollection class
Chapter 1 - ADO.NET Basics
OracleTransaction Transaction class
Chapter 2 - Data Components in Visual Studio .NET
OraclePermission
Chapter Permission class
3 - ADO.NET in Disconnected Environments
Chapter 4 - ADO.NET in Connected Environments
OracleException Exception class
Chapter 5 - Handling ADO.NET Events
OracleBFile
Chapter 6
RepresentsOracleBFile objects designed to work with
- Integrating XML with ADO.NET
the Oracle Binary File BFILE data type
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
Chapter 8 - Constraints and Data Relations
OracleLob Represents a Large Object Binary (LOB) data type
Chapter 9 - ADO.NET Exception Handling
Chapter 10 - Working with the ODBC .NET Data Provider
Creating
Chapter the Connection:
11 - Stored Procedures and The
Views First Step
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
The first step to access a database is to create a connection. The OracleConnection class of the
Chapter 13 - Developing a Custom Data Provider
Oracle data provider is responsible for opening and closing a connection with the database.
Chapter 14 - Developing Database Web Applications using ASP.NET
Chapter 15 - Using ADO.NET class
TheOracleConnection in Xmlhas
Web Services
four properties: ConnectionString,DataSource,
Chapter 16 - ASP.NET Server Controls and Data Binding
ServerVersion, and State. The ConnectionString represents a connection string, which can
Chapter
contain17 - Building
data source Real-World Web Applications
or server name, security type, user ID, and password. Like the other data provider
connection
Chapter 18 - classes, the OracleConnection
Object-Relational Mapping in .NET provides Open,Close,BeginTransaction,
Chapter 19 - Mappedand
CreateCommand, Dispose
Objects: methods.
Performance Considerations and Data Binding
Chapter 20 - COM Interoperability and ADO.NET
A typical connection string looks like the following:
Chapter 21 - Messaging
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
"Data ASource=Oracle8i;Integrated
Appendix Security=yes"
- Relational Databases: Some Basic Concepts
Appendix B - Commonly Used SQL Statements
Appendix C - ADO.NET Frequently Asked Questions
where Oracle8i is the default Oracle database server instance.
Index
List ofNote
Figures
The Oracle .NET data provider works for Oracle 8i and later versions of Oracle.
List of Tables
The following is another version of connection string with the user ID systemand password manager for
List of Listings
the database server instance MYDB:
List of Sidebars
Listing 12-1 creates an OracleConnection, opens the connection, reads data, and closes the
connection.
On the form's load event handler, you call the method FillDataGrid, which fills data from a database
to the DataGrid control. Listing 12-2 shows the form's load event handler and the FillDataGrid
method.
The next step is to execute a SQL query using OracleCommand. The method ExecuteSqlQuery,
shown in Listing 12-3, executes a SQL query. As you can see, the code opens a connection, creates an
OracleCommand object, sets its connection, CommandText, and CommandType properties, and then
calls ExecuteNonQuery method.
Table of Contents
Catch exp As Exception
Applied ADO.NETBuilding Data-Driven Solutions
MessageBox.Show(exp.Message)
Introduction
Finally
Chapter 1 -If
ADO.NET Basics
(conn.State = ConnectionState.Open) Then
Chapter 2 -conn.Close()
Data Components in Visual Studio .NET
Chapter 3 -End If in Disconnected Environments
ADO.NET
ChapterEnd
4 -Try
ADO.NET in Connected Environments
End Sub
Chapter 5 - Handling ADO.NET Events
Chapter 6 - Integrating XML with ADO.NET
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
Chapter 8 - Constraints and Data Relations
Now let's write the code for InsertCmdBtn,UpdateCmdBtn, and DeleteCmdBtnand construct SQL
Chapter 9 - ADO.NET Exception Handling
INSERT,UPDATE, and DELETE queues. Once the queries are constructed, you need to call
Chapter 10 - Working with the ODBC .NET Data Provider
ExecuteSqlQuery.Listing 12-4 shows the code for all three buttons.
Chapter 11 - Stored Procedures and Views
Chapter
Listing12 - Oracle,
12-4: SQLXML, and
Constructing SQLOther .NET UPDATE,
INSERT, Data Providers
and DELETE Queries
Chapter 13 - Developing a Custom Data Provider
Chapter 14 - Developing Database Web Applications using ASP.NET
Private Sub InsertCmdBtn_Click(ByVal sender As System.Object, _
Chapter
ByVal15e -AsUsing ADO.NET in Xml Web Services
System.EventArgs) Handles InsertCmdBtn.Click
Chaptersql
16 -=ASP.NET Server
"INSERT Controls
INTO " and Data Binding
Chaptersql
17 -+=
Building Real-World Web Applications
" STDTABLE(STDNAME, STDADDRESS, STDSRN) "
Chaptersql
18 -+=
Object-Relational Mapping in'Some
"VALUES('AName', .NET Address', 3583)"
ChapterExecuteSqlQuery(sql)
19 - Mapped Objects: Performance Considerations and Data Binding
ChapterFillDataGrid()
20 - COM Interoperability and ADO.NET
End Sub
Chapter 21 - Messaging
Private
Chapter 22 -Sub UpdateCmdBtn_Click(ByVal
SQL Server sender As System.Object, _
and ADO.NET: Notes on Performance
ByVal Ae -As
Appendix System.EventArgs)
Relational Handles
Databases: Some Basic UpdateCmdBtn.Click
Concepts
sql
Appendix B -=Commonly
"UPDATEUsed
STDTABLE SET STDADDRESS = " & _
SQL Statements
"'New
Appendix Address'
C - ADO.NET WHERE
Frequently STDNAME
Asked = 'AName' "
Questions
Index
ExecuteSqlQuery(sql)
FillDataGrid()
List of Figures
End Sub
List of Tables
Private Sub DeleteCmdBtn_Click(ByVal sender As System.Object, _
List of Listings
ByVal e As System.EventArgs) Handles DeleteCmdBtn.Click
List of Sidebars
sql = "DELETE STDTABLE WHERE STDNAME = 'AName' "
ExecuteSqlQuery(sql)
FillDataGrid()
End Sub
Note You may also notice that you call the FillDataGrid method to update the DataGrid once a
query is executed.
Listing 12-5 used the generic data methods, but the code in Listing 12-6 demonstrates using the Oracle-
specific DataReader methods. As you can see, the code uses the GetOracleString,
GetOracleNumber, and GetOracleDateTime methods to read data in Oracle data types.
Listing 12-6: Using the Oracle-Specific DataReader Methods
Applied ADO.NET: Building Data-Driven Solutions
by Mahesh Chand and David Talbot ISBN:1590590732
While (reader.Read())
Apress 2003 (928 pages)
Dim oraStr As OracleString
This text provides extensive coverage of ADO.NET technology
oraStr = reader.GetOracleString(0)
including ADO.NET internals, namespaces, classes, and
Dim str As String
interfaces,=and
oraStr.ToString()
takes a comprehensive look at XML
namespaces and classes, and how to integrate both with
oraStr = reader.GetOracleString(1)
Dim oraDtTime ADO.NET.
As OracleDateTime = _
reader.GetOracleDateTime(2)
Dim
Table of oraNum
Contents As OracleNumber = _
reader.GetOracleNumber(3)
Applied ADO.NETBuilding Data-Driven Solutions
End While
Introduction
Chapter 1 - ADO.NET Basics
Chapter 2 - Data Components in Visual Studio .NET
Chapter 3
Reading- ADO.NET
in Disconnected Environments
and Writing Data Using a DataAdapter
Chapter 4 - ADO.NET in Connected Environments
Chapter 5 - Handling ADO.NET
TheOracleDataAdapter Events
class represents the DataAdapter for the Oracle data provider. Like the
Chapter 6 -provider's
other data Integrating XML with ADO.NET
DataAdapter classes, this class also defines the Fill and Update methods. The
Fill method
Chapter fillsBinding
7 - Data a DataSet from a data
and Windows Formssource, and the
Data-Bound Update method saves the changes made to a
Controls
DataSet
Chapter 8 -back to the database.
Constraints and Data Relations
Chapter 9 - ADO.NET Exception Handling
Listing 12-7 creates an OracleDataAdapter object from a command. After that, code fills a DataSet,
Chapter 10 - Working with the ODBC .NET Data Provider
adds a row by using the Update method, and displays the updated data in a DataGrid control. To test
Chapter 11 - Stored Procedures and Views
this code, create a Windows application, add a DataGrid control, and add this code on the form load or a
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
button click event handler.
Chapter 13 - Developing a Custom Data Provider
Chapter
Listing14 - Developing
12-7: ReadingDatabase Web Data
and Writing Applications
Using using ASP.NET
OracleDataAdapter
Chapter 15 - Using ADO.NET in Xml Web Services
Chapter 16 - ASP.NET Server Controls and Data Binding
Dim connectionString As String = _
Chapter 17 - Building Real-World Web Applications
"Data Source=MYDB;User ID=system;Password=manager;"
Chapter 18 Dim- Object-Relational Mapping in .NET
conn As OracleConnection = _
Chapter 19 New- Mapped Objects: Performance Considerations and Data Binding
OracleConnection(connectionString)
Chapter 20 Dim- COMsql
Interoperability
As String and
= ADO.NET
"SELECT * FROM STDTABLE"
Chapter 21 Try- Messaging
Chapter 22 - SQL'Server
Openand ADO.NET:
the Notes on Performance
connection
Appendix A - Relational Databases: Some
If (conn.State Basic Concepts
= ConnectionState.Closed) Then
conn.Open()
Appendix B - Commonly Used SQL Statements
Appendix C - ADO.NETEnd Frequently
If Asked Questions
Index ' Create a command with SELECT query
List of Figures Dim cmd As OracleCommand = New OracleCommand(sql)
List of Tables cmd.Connection = conn
List of Listings
' Create a data adapter
Dim adapter As OracleDataAdapter = _
List of Sidebars
New OracleDataAdapter(cmd)
Dim builder1 As OracleCommandBuilder = _
New OracleCommandBuilder()
builder1.DataAdapter = adapter
' Create and fill a DataSet
Dim ds As DataSet = New DataSet()
adapter.Fill(ds, "STDTABLE")
Dim stdTable As DataTable = ds.Tables("STDTABLE")
' Add a row
Dim row As DataRow = ds.Tables(0).NewRow()
row(0) = "New Name"
row(1) = "New Address"
row(2) = DateTime.Today
Applied ADO.NET:
row(3) = "1234"Building Data-Driven Solutions
by Mahesh Chand and David Talbot
stdTable.Rows.Add(row) ISBN:1590590732
Apress 2003 (928 pages)
adapter.Update(ds, "STDTABLE")
'This text provides
Bind DataSet extensive
with coverage of ADO.NET technology
DataGrid
including ADO.NET internals, namespaces,
DataGrid1.DataSource = ds.Tables(0) classes, and
interfaces, and takes a comprehensive look at XML
Catch exp As namespaces
Exception and classes, and how to integrate both with
MessageBox.Show(exp.Message)
ADO.NET.
Finally
' Close the connection
Table of Contents If (conn.State = ConnectionState.Open) Then
Applied ADO.NETBuilding Data-Driven Solutions
conn.Close()
Introduction End If
Chapter 1 -EndADO.NET
Try Basics
Chapter 2 - Data Components in Visual Studio .NET
Chapter 3 - ADO.NET in Disconnected Environments
Chapter 4 - ADO.NET in Connected Environments
Caution
Chapter When itADO.NET
5 - Handling comes toEvents
performance, the DataReader should be your first choice over a
Chapter 6 DataSet XML
- Integrating when reading
with data from a database. Don't forget to close a DataReader when
ADO.NET
Chapter 7 you're
- Data doneand
Binding accessing
Windowsdata.
Forms Data-Bound Controls
Chapter 8 - Constraints and Data Relations
Reading- ADO.NET
Chapter 9
BFILEsException
and LOBsHandling
Chapter
Reading10Binary
- Working
File with the and
(BFILE) ODBC .NET Object
Large Data Provider
Binary (LOB) data types are two more tasks that Oracle
Chapter 11 - Stored Procedures and Views
developers don't encounter with other databases. The Oracle .NET data provider handles both of these
Chapter 12 -wisely
data types Oracle,with
SQLXML, andofOther
the help .NET Data Providers
the OracleBFile and OracleLob classes.
Chapter 13 - Developing a Custom Data Provider
TheOracleLob
Chapter class provides
14 - Developing Database access to three Oracle
Web Applications data types: Blob,Clob, and NClob. The Blob
using ASP.NET
data type
Chapter 15 contains binary data
- Using ADO.NET up Web
in Xml to 4GB in the form of an array of bytes. The Clob data type contains
Services
character data up to 4GB in the form of a string. The NClob data type contains the character data based
Chapter 16 - ASP.NET Server Controls and Data Binding
on the national character set of the server with up to 4GB.
Chapter 17 - Building Real-World Web Applications
Chapter 18 - Object-Relational
TheGetOracleBFile Mapping
method in .NET
of OracleDataReader returns an OracleBFile object. This code
Chapter 19 BFILE
reads the - Mapped Objects:
data Performance
type from an OracleConsiderations
database: and Data Binding
Chapter 20 - COM Interoperability and ADO.NET
Chapter 21 - Messaging
Dim bf As OracleBFile = reader.GetOracleBFile(1)
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Appendix A - Relational Databases: Some Basic Concepts
TheGetOracleLob
Appendix B - Commonlymethod of OracleDataReader
Used SQL Statements returns an OracleLob object containing data. The
followingCcode
Appendix uses the
- ADO.NET GetOracleLob
Frequently method to read LOB data types:
Asked Questions
Index
List of Figures
reader.Read()
List
Dim of Tables
blb As OracleLob = reader.GetOracleLob(1)
Dim
List buffer() As Byte = New Byte(100) {}
of Listings
buffer(0)
List of Sidebars = 0xCC
buffer(1) = 0xDD
blb.Position = 0
Dim lob As OracleLob = CreateTempLob(cmd,blb.LobType)
Dim actual As Long = blb.CopyTo(lob)
Note If you want to know more about BFILE, LOB, and other data types and related classes, see the
documentation of the Oracle .NET data provider.
We could easily write more pages discussing other classes of Oracle data provider, but luckily, the
documentation that comes with the Oracle data provider is full of samples. You shouldn't have to go
anywhere else to find the solution for your problems.
Applied ADO.NET: Building Data-Driven Solutions
by Mahesh Chand and David Talbot ISBN:1590590732
Apress 2003 (928 pages)
This text provides extensive coverage of ADO.NET technology
including ADO.NET internals, namespaces, classes, and
interfaces, and takes a comprehensive look at XML
namespaces and classes, and how to integrate both with
ADO.NET.
Table of Contents
Applied ADO.NETBuilding Data-Driven Solutions
Introduction
Chapter 1 - ADO.NET Basics
Chapter 2 - Data Components in Visual Studio .NET
Chapter 3 - ADO.NET in Disconnected Environments
Chapter 4 - ADO.NET in Connected Environments
Chapter 5 - Handling ADO.NET Events
Chapter 6 - Integrating XML with ADO.NET
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
Chapter 8 - Constraints and Data Relations
Chapter 9 - ADO.NET Exception Handling
Chapter 10 - Working with the ODBC .NET Data Provider
Chapter 11 - Stored Procedures and Views
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Chapter 13 - Developing a Custom Data Provider
Chapter 14 - Developing Database Web Applications using ASP.NET
Chapter 15 - Using ADO.NET in Xml Web Services
Chapter 16 - ASP.NET Server Controls and Data Binding
Chapter 17 - Building Real-World Web Applications
Chapter 18 - Object-Relational Mapping in .NET
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
Chapter 20 - COM Interoperability and ADO.NET
Chapter 21 - Messaging
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Appendix A - Relational Databases: Some Basic Concepts
Appendix B - Commonly Used SQL Statements
Appendix C - ADO.NET Frequently Asked Questions
Index
List of Figures
List of Tables
List of Listings
List of Sidebars
Using the SQLXML and Building
Applied ADO.NET: SQL XML .NETSolutions
Data-Driven Data Providers
by Mahesh Chand and David Talbot ISBN:1590590732
Chapter 6 discussed themajor
Apress XML
2003 (928 .NET-related classes found in the System.Xml namespace to read
pages)
and write XML documents. We also discussed XML integration
This text provides extensive coverage of ADO.NETwith ADO.NET. The .NET Framework
technology
Library also provides an XML .NET data provider to work with SQL
including ADO.NET internals, namespaces, classes, and Server 2000 and XML documents.
interfaces, and takes a comprehensive look at XML
The .NET supportnamespaces and classes,
was introduced and how to
in the SQLXML 2.0integrate both with
library, which includes two data providers that can
ADO.NET.
be used to read XML data and write XML from and into SQL Server 2000 databases. These two data
providers are the following:
Table of Contents
The SQLXMLOLEDB provider, which is an OLE DB data provider that exposes SQLXML 2.0
Applied ADO.NETBuilding
functionality through Data-Driven
ADO Solutions
Introduction
The
Chapter 1 SQLXML managed
- ADO.NET Basics classes (the SQL XML .NET data provider) expose SQLXML 2.0 functionality
through
Chapter ADO.NET
2 - Data Components in Visual Studio .NET
Chapter 3 - ADO.NET in Disconnected Environments
Note Currently, SQLXML 3.0 is available for download with Service Pack 1. This chapter uses
Chapter 4 - ADO.NET in Connected Environments
SQLXML 3.0, which by default copies to the C:\\Program Files\SQLXML 3.0\Bin folder.
Chapter 5 - Handling ADO.NET Events
Chapter 6 - Integrating
In this chapter, XML withonly
we concentrate ADO.NET
on the SQL XML .NET data provider.
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
Note
Chapter 8 To get the latest
- Constraints and updates and downloads for SQLXML, visit http://msdn.microsoft.com/sqlxml/.
Data Relations
Chapter 9 - ADO.NET Exception Handling
The SXDP is an add-on; you can download and install it from Microsoft's site
Chapter 10 - Working with the ODBC .NET Data Provider
(http://msdn.microsoft.com/sqlxml/). Installing SXDP copies the
Chapter 11 - Stored Procedures and Views
Microsoft.Data.SqlXml.dll library, which you should add to an application before you start using it
Chapter 12 - Oracle,
in an application. InSQLXML, and
VS .NET, youOther
can .NET
add aData Providers
reference to SXDP by using the Add Reference menu option
Chapter 13 - Developing
and selecting a Custom
the Browse button.Data
The Provider
default path of SXDP is the C:\\Program Files\SQLXML
Chapter
3.0\Bin14 -folder
Developing Database
(see Figure Web Applications using ASP.NET
12-2).
Chapter 15 - Using ADO.NET in Xml Web Services
Chapter 16 - ASP.NET Server Controls and Data Binding
Chapter 17 - Building Real-World Web Applications
Chapter 18 - Object-Relational Mapping in .NET
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
Chapter 20 - COM Interoperability and ADO.NET
Chapter 21 - Messaging
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Appendix A - Relational Databases: Some Basic Concepts
Appendix B - Commonly Used SQL Statements
Appendix C - ADO.NET Frequently Asked Questions
Index
List of Figures
List of Tables
List of Listings
List ofFigure 12-2: Adding a reference to Microsoft.Data.SqlXml.dll
Sidebars
Adding a reference to this library adds the Microsoft.Data.SqlXml namespace to the project.
Obviously you include this namespace in your application to access the classes provided by the SXDP:
imports Microsoft.Data.SqlXml
Unlike other data providers, the SQLXMLDP model consists of only three classes: SqlXmlCommand,
SqlXmlParameter, and SqlXmlAdapter.
where mode specifies the XML mode. It can be RAW, AUTO, or EXPLICIT. XMLDATAspecifies that an
Table of Contents
XML-Data schema should be returned. If ELEMENTS is specified, it produces columns as subelements;
Applied ADO.NETBuilding Data-Driven Solutions
otherwise columns are mapped as XML attributes. This option is available for AUTO mode only. The
Introduction
choice of which to use is yours, as both options produce valid XML; however, using subelements is more
Chapter 1 - ADO.NET Basics
like XML and may be especially useful if you need to share data across systems that may not have XML
Chapter
parsers2that
- Data Components
understand in Visual
attributes. TheStudio
BINARY.NET BASE64 option specifies that any binary data retuned by
Chapter 3 will
the query - ADO.NET in Disconnected
be in 64-bit Environments
encoded format.
Chapter 4 - ADO.NET in Connected Environments
The following
Chapter examples
5 - Handling use this
ADO.NET syntax.
Events
Chapter 6 - Integrating XML with ADO.NET
Using7 the
Chapter SqlXmlAdapter
- Data Object
Binding and Windows Forms Data-Bound Controls
Chapter 8- Constraints and Data Relations
TheSqlXmlAdapter object represents a partial DataAdapter. We said partial because unlike other
Chapter 9 - ADO.NET
data providers' Exception Handling
DataAdapter object, it only provides two methods: Fill and Update.
Chapter 10 - Working with the ODBC .NET Data Provider
You can
Chapter 11create a SqlXmlAdapter
- Stored from an XML document with arguments of a connection string and
Procedures and Views
command
Chapter 12 -type. These
Oracle, are two
SQLXML, andoverloaded
Other .NET forms of the SqlXmlAdapter constructor:
Data Providers
Chapter 13 - Developing a Custom Data Provider
Chapter 14 - Developing
Dim adapter As NewDatabase Web Applications using ASP.NET _
SqlXmlAdapter(commandText,
Chapter 15 - Using ADO.NET in
SqlXmlCommandType, Xml Web Services
connectionString)
Dim adapter
Chapter As Server
16 - ASP.NET New SqlXmlAdapter(commandStream,
Controls and Data Binding _
SqlXmlCommandType,
Chapter connectionString)
17 - Building Real-World Web Applications
Chapter 18 - Object-Relational Mapping in .NET
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
The connection string for a SqlXmlAdapter is a standard OleDb connection string; however, the provider
Chapter 20 - COM Interoperability and ADO.NET
must be SQLOLEDB, the SQL Server provider. You can also create a SqlXmlAdapter from a
Chapter 21 - Messaging
SqlXmlCommand:
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Appendix A - Relational Databases: Some Basic Concepts
Dim adapter As New SqlXmlAdapter(SqlXmlCommand)
Appendix B - Commonly Used SQL Statements
Appendix C - ADO.NET Frequently Asked Questions
Index
You can also specify the command string and command type later using the CommandText and
List of Figures
CommandType properties. You can use the SchemaPath property to read an XML document.
List of Tables
List of Listings
cmd.CommandText = "EmployeeElement"
List of Sidebars
cmd.CommandType = SqlXmlCommandType.XPath
cmd.SchemaPath = "xmlDoc.xml"
TheFill method takes a DataSet as an argument and fills it with the data specified in the SELECT
command, and the Update method sends a DataSet to save the changes to a data source.
Listing 12-8 uses a SqlXmlAdapter to fill a DataSet and view data in a DataGridcontrol. The code
also uses the Update method to add a new row to the database.
where connectionString is the ADO or OLEDB connection string identifying the server, database, and
the login information. A typical connection string looks like following:
You can use the ExecuteStream and ExecuteToStream methods to write to streams. The
Table of Contents method returns a new Stream object, and the ExecuteToStream method writes the
ExecuteStream
query results
Applied to an existing
ADO.NETBuilding stream. Solutions
Data-Driven
Introduction
TheExecuteXmlReader method executes a query and returns results in an XmlReader object.
Chapter 1 - ADO.NET Basics
Chapter 2 To
Note - Data
useComponents
System.Xml in Visual
in yourStudio .NET you need to add a reference to the System.Xml
application,
Chapter 3 namespace.
- ADO.NET in Disconnected Environments
Chapter 4 - ADO.NET in Connected Environments
TheCreateParameter
Chapter method
5 - Handling ADO.NET creates a parameter for SXDP, which can be used by
Events
SqlXmlCommand.
Chapter YouXML
6 - Integrating can with
set values for the Name and Value parameters of this object. The
ADO.NET
ClearParameter
Chapter method
7 - Data Binding and removes
Windows all parameters
Forms associated
Data-Bound Controls with a Command object.
Chapter 8 - Constraints and Data Relations
Using the
Chapter 9
SqlXmlCommand Properties
- ADO.NET Exception Handling
Chapter 10 - Working with
TheSqlXmlCommand the ODBC
object .NETmany
supports Data properties,
Provider which are defined in Table 12-2.
Chapter 11 - Stored Procedures and Views
Chapter 12 - Oracle,
Table 12-2: SQLXML, and Other
The SqlXmlCommand .NET Data Providers
Properties
Chapter 13 - Developing a Custom Data Provider
ClientSideXml
Chapter When setWeb
14 - Developing Database to True, conversion
Applications using of the rowset to XML occurs on the client
ASP.NET
instead
Chapter 15 - Using ADO.NET of on
in Xml Webthe server. This is useful when you want to move the
Services
performance load to the middle tier. This property also allows you to wrap
Chapter 16 - ASP.NET Server Controls and Data Binding
the existing stored procedures with FOR XML to get XML output.
Chapter 17 - Building Real-World Web Applications
Chapter 18 - Object-Relational
SchemaPath This isMapping in .NET
the name of the mapping schema along with the directory path (for
example,
Chapter 19 - Mapped Objects: C:\x\y\MySchema.xml).
Performance ThisBinding
Considerations and Data property specifies a mapping
schema for
Chapter 20 - COM Interoperability andXPath queries. The path specified can be absolute or relative. If
ADO.NET
Chapter 21 - Messaging the path specified is relative, the base path specified in BasePath resolves
Chapter 22 - SQL Server the
and relative
ADO.NET:path. If the
Notes on base path isn't specified, the relative path is relative
Performance
to the current
Appendix A - Relational Databases: Some directory.
Basic Concepts
Appendix
XslPathB - Commonly Used
This SQL
is theStatements
name of the XSL file along with the directory path. The path
Appendix C - ADO.NET Frequently
specifiedAsked Questions
can be absolute or relative. If the path specified is relative, the
Index base path specified in BasePath resolves the relative path. If the base path
List of Figures isn't specified, the relative path is relative to the current directory.
List of Tables
BasePath This is the base path (a directory path). The value of this property resolves
List of Listings
relative paths specified for the XSL file (using the XslPathproperty), the
List of Sidebars
mapping schema file (using the SchemaPathproperty), or an external
schema reference in an XML template (specified using mapping-schema
attribute).
OutputEncoding This specifies the requested encoding for the stream returned by the
command execution. Some commonly used encodings are UTF-8, ANSI,
and Unicode. UTF-8 is the default encoding.
Namespaces XPath queries can include namespaces. If the schema elements are
namespace-qualified (use a target namespace), the XPath queries against
the schema must specify the namespace. This member enables the
execution of XPath queries that use namespaces.
RootTag This
Applied providesBuilding
ADO.NET: the singleData-Driven
root elementSolutions
for the XML generated by the
command
by Mahesh Chand execution. A valid XML document
and David Talbot requires a single root-level tag.
ISBN:1590590732
If the command
Apress 2003 (928 pages) executed generates an XML fragment (without a single top-
level element), you can optionally specify the root element for the returning
This text provides extensive coverage of ADO.NET technology
XML.
including ADO.NET internals, namespaces, classes, and
interfaces, and takes a comprehensive look at XML
CommandText namespaces
This isand
theclasses,
text of the
andcommand to execute.
how to integrate both with
ADO.NET.
CommandStream This is the command stream to execute. This property is useful if you want
to execute a command from a file (for example, an XML template). When
Table of Contents usingCommandStream, only Template,UpdateGram, and DiffGram
CommandType
Applied ADO.NETBuilding values are supported
Data-Driven Solutions
Introduction
CommandType This identifies the type of command being executed. This property is of type
Chapter 1 - ADO.NET Basics
SqlXmlCommandType.
Chapter 2 - Data Components in Visual Studio .NET
Chapter 3 - describes
Table 12-3 ADO.NET inthe
Disconnected Environments property.
SqlXmlCommandType
Chapter 4 - ADO.NET in Connected Environments
Chapter 5 - Handling
Table 12-3: ADO.NET Events
The SqlXmlCommandType Members
Chapter 6 - Integrating XML with ADO.NET
COMMANDTYPE DESCRIPTION
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
Chapter
Sql 8 - Constraints and Dataan
Executes Relations
SQL command (for example, SELECT * FROM Employees
Chapter 9 - ADO.NET Exception
FOR XMLHandling
AUTO).
Chapter 10 - Working with the ODBC .NET Data Provider
XPath Executes an XPath command (for example,
Chapter 11 - Stored Procedures and Views
Employees[@EmployeeID=1]).
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
13 - DevelopingExecutes
Template
Chapter a Customan XML
Data template.
Provider
Chapter 14 - Developing Database Web Applications using ASP.NET
UpdateGram Executes an updategram.
Chapter 15 - Using ADO.NET in Xml Web Services
DiffGram
Chapter Executes
16 - ASP.NET Server a DiffGram.
Controls and Data Binding
Chapter 17 - Building Real-World Web Applications
TemplateFile Executes a template file. This allows you to execute updategrams and
Chapter 18 - Object-Relational Mapping in .NET
DiffGrams.
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
Chapter 20 - COM Interoperability and ADO.NET
Seeing
Chapter 21 SqlXmlCommand
- Messaging in Action
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Listing 12-9
Appendix uses different
A - Relational methods
Databases: andBasic
Some properties of SqlXmlCommand to execute SQL queries.
Concepts
Appendix B - Commonly Used SQL Statements
Listing 12-9: UsingSqlXmlCommand to Execute Commands
Appendix C - ADO.NET Frequently Asked Questions
Index
Imports
List System
of Figures
Imports
List of TablesSystem.IO
Imports
List System.Xml
of Listings
Imports Microsoft.Data.SqlXml
List of Sidebars
Module Module1
Sub Main()
ExecuteStreamMethod()
ExecuteToStreamMethod()
SqlParamExecuteMethod()
ExecuteNonQueryMethod()
End Sub
Table of Contents
Using the OLEDB.NET solution, the MyOLDDB provider
Applied ADO.NETBuilding Data-Driven Solutions
To see more details about these interfaces, samples, links, and other resources, visit
Introduction
www.mysql.com/articles/dotnet/.
Chapter 1 - ADO.NET Basics
Chapter 2 - Data Components in Visual Studio .NET
Chapter 3 - ADO.NET in Disconnected Environments
Chapter 4 - ADO.NET in Connected Environments
Chapter 5 - Handling ADO.NET Events
Chapter 6 - Integrating XML with ADO.NET
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
Chapter 8 - Constraints and Data Relations
Chapter 9 - ADO.NET Exception Handling
Chapter 10 - Working with the ODBC .NET Data Provider
Chapter 11 - Stored Procedures and Views
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Chapter 13 - Developing a Custom Data Provider
Chapter 14 - Developing Database Web Applications using ASP.NET
Chapter 15 - Using ADO.NET in Xml Web Services
Chapter 16 - ASP.NET Server Controls and Data Binding
Chapter 17 - Building Real-World Web Applications
Chapter 18 - Object-Relational Mapping in .NET
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
Chapter 20 - COM Interoperability and ADO.NET
Chapter 21 - Messaging
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Appendix A - Relational Databases: Some Basic Concepts
Appendix B - Commonly Used SQL Statements
Appendix C - ADO.NET Frequently Asked Questions
Index
List of Figures
List of Tables
List of Listings
List of Sidebars
Summary Applied ADO.NET: Building Data-Driven Solutions
by Mahesh Chand and David Talbot ISBN:1590590732
In this chapter, you added
Apress more
2003 (928data providers to your data provider list. You learned about various data
pages)
providers to access Oracle databases. We discussed
This text provides extensive theADO.NET
coverage of Oracle .NET data provider in detail and showed
technology
you how you can including
access Oracle databases.
ADO.NET internals, namespaces, classes, and
interfaces, and takes a comprehensive look at XML
The SQLXML .NET namespaces and classes,
data provider providesand howand
a fast to integrate
optimizedboth
waywith
to communicate between SQL Server
ADO.NET.
and XML. In this chapter, you saw how to install and work with the XML .NET data provider.
In the next chapter, you'll put all the data providerrelated pieces together and work with some data
Table of Contents
provider internals. You'll also learn how to build your own custom data provider.
Applied ADO.NETBuilding Data-Driven Solutions
Introduction
Chapter 1 - ADO.NET Basics
Chapter 2 - Data Components in Visual Studio .NET
Chapter 3 - ADO.NET in Disconnected Environments
Chapter 4 - ADO.NET in Connected Environments
Chapter 5 - Handling ADO.NET Events
Chapter 6 - Integrating XML with ADO.NET
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
Chapter 8 - Constraints and Data Relations
Chapter 9 - ADO.NET Exception Handling
Chapter 10 - Working with the ODBC .NET Data Provider
Chapter 11 - Stored Procedures and Views
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Chapter 13 - Developing a Custom Data Provider
Chapter 14 - Developing Database Web Applications using ASP.NET
Chapter 15 - Using ADO.NET in Xml Web Services
Chapter 16 - ASP.NET Server Controls and Data Binding
Chapter 17 - Building Real-World Web Applications
Chapter 18 - Object-Relational Mapping in .NET
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
Chapter 20 - COM Interoperability and ADO.NET
Chapter 21 - Messaging
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Appendix A - Relational Databases: Some Basic Concepts
Appendix B - Commonly Used SQL Statements
Appendix C - ADO.NET Frequently Asked Questions
Index
List of Figures
List of Tables
List of Listings
List of Sidebars
Chapter Applied
13: Developing a Custom
by Mahesh Chand and David Talbot
Data Provider
ADO.NET: Building Data-Driven Solutions
ISBN:1590590732
Apress 2003 (928 pages)
Highlights This text provides extensive coverage of ADO.NET technology
including ADO.NET internals, namespaces, classes, and
ADO.NET allowsinterfaces,
developers astakes
and mucha flexibility in creating
comprehensive look custom
at XML data providers as Microsoft had
namespaces
developing the SqlClient and and classes,
OleDb data and how to In
providers. integrate both with
other words, you can create data providers for
ADO.NET.
virtually any source of data you can think of, from file formats to Web services.
Think about some of the possibilities this presents. If you needed to create a database application that
Table of Contents
works on top of a number of different databases such as Microsoft SQL Server and IBM DB2, you could
Applied ADO.NETBuilding Data-Driven Solutions
build a Web service that does the actual database access while your custom data provider provides the
Introduction
front end. Figure 13-1 shows such an application would work.
Chapter 1 - ADO.NET Basics
Chapter 2 - Data Components in Visual Studio .NET
Chapter 3 - ADO.NET in Disconnected Environments
Chapter 4 - ADO.NET in Connected Environments
Chapter 5 - Handling ADO.NET Events
Chapter 6 - Integrating XML with ADO.NET
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
Chapter 8 - Constraints and Data Relations
Figure
Chapter 9 - 13-1: A Web-service-based
ADO.NET Exception Handling data provider that accesses a Relational Database Management
System
Chapter (RDBMS)
10 - Working with the ODBC .NET Data Provider
Chapter 11 - Stored Procedures and Views
Using an architecture like the one shown in Figure 13-1, you can have focused teams develop
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
compatibility to the Web service you've created for data access. Your data provider only needs to know
Chapter 13 - Developing a Custom Data Provider
how to access the Web service, and you can build your application using the same Application
Chapter 14 - Developing Database Web Applications using ASP.NET
Programming Interface (API) as you would for direct database calls.
Chapter 15 - Using ADO.NET in Xml Web Services
The advantage
Chapter of building
16 - ASP.NET ServeraControls
system and
like Data
this isBinding
obvious-you can start building your application on top of the
ADO.NET
Chapter 17 -interfaces while the data
Building Real-World provider, Web service architecture, and individual database
Web Applications
compatibility
Chapter gets worked out.Mapping
18 - Object-Relational This is more
in .NETthan a little helpful if you're working on a large project requiring
cross-database
Chapter compatibility.
19 - Mapped Objects: Performance Considerations and Data Binding
Chapter 20 - COM Interoperability and ADO.NET
This example highlights why the ability to write a custom data provider is truly beneficial; it's a way to
Chapter 21 - Messaging
provide standard access to a nonstandard source of data. In other words, this provides a way to normalize
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
the way you work with data regardless of the source.
Appendix A - Relational Databases: Some Basic Concepts
In this chapter
Appendix you'll build
B - Commonly Useda SQL
data Statements
provider that allows access to data in pipe-delimited format, and you'll
provide aC standard
Appendix - ADO.NET.NET API by Asked
Frequently implementing the Microsoft interfaces to create a custom data provider.
Questions
The pipe-delimited format is common, especially to Unix systems, as a way to move data between
Index
systems.
List Many large Enterprise Resource Planning (ERP) systems support the ability to export data in this
of Figures
format.
List Another popular format you could build support for is the Comma Separated Values (CSV) format,
of Tables
which
List is more popular on Windows systems. This chapter begins with an overview of the data provider
of Listings
interfaces.
List of Sidebars
Overview ofApplied
the Data Provider
ADO.NET: Interfaces
Building Data-Driven Solutions
by Mahesh Chand and David Talbot ISBN:1590590732
Figure 13-2 shows a custom
Apress 2003data provider's interfaces, grouped by function, and shows how they use
(928 pages)
each other. As you can see, the custom datacoverage
This text provides extensive providerofhas four objects:
ADO.NET Connection,Command,Reader,
technology
andAdapter. The following sections discuss these objects and how
including ADO.NET internals, namespaces, classes, and they work.
interfaces, and takes a comprehensive look at XML
namespaces and classes, and how to integrate both with
ADO.NET.
Table of Contents
Applied ADO.NETBuilding Data-Driven Solutions
Introduction
Chapter 1 - ADO.NET Basics
Chapter 2 - Data Components in Visual Studio .NET
Chapter 3 - ADO.NET in Disconnected Environments
Figure 13-2: A custom data provider at a high level
Chapter 4 - ADO.NET in Connected Environments
Chapter 5 - Handling ADO.NET Events
Chapter 6
- Integrating XML with ADO.NET
Understanding
Chapter 7
the Connection Object
- Data Binding and Windows Forms Data-Bound Controls
Chapter 8 - Constraints
AConnection and
object is anData Relations
individual session with a source of data. If it's a database connection, it's likely
Chapter
an open9 Transfer
- ADO.NET Exception
Control Handling
Protocol/Internet Protocol (TCP/IP) channel back to the server on a particular
Chapter 10has
port that - Working with the ODBC
been authenticated as.NET Data
having Provider
access to the database. If your data source is a file, it's likely a
Chapter 11 -on
file handle Stored Procedures
the file andread
that will be Views
from. To fully understand how generic this interface is, take a look at
the IDbConnection
Chapter interface's
12 - Oracle, SQLXML, andproperties in Table
Other .NET 13-1 and methods in Table 13-2.
Data Providers
Chapter 13 - Developing a Custom Data Provider
Table 13-1:
Chapter The Properties
14 - Developing of the
Database Applications using Interface
WebIDbConnection ASP.NET
Chapter 15 - Using ADO.NET in Xml Web Services
PROPERTY DESCRIPTION
Chapter 16 - ASP.NET Server Controls and Data Binding
ConnectionString
Chapter This
17 - Building Real-World property
Web represents how the data provider can find its data
Applications
Chapter 18 - Object-Relational source.
MappingIn
in the case of a file-based source, this could be the path to the
.NET
file. If it's a Web
Chapter 19 - Mapped Objects: Performance service, it could
Considerations be aBinding
and Data Uniform Resource Indicator
(URI).
Chapter 20 - COM Interoperability and ADO.NET
Chapter 21 - Messaging
ConnectionTimeout This property represents the amount of time the object should try to
Chapter 22 - SQL Server and ADO.NET: Notes on
connect before Performance
giving up.
Appendix A - Relational Databases: Some Basic Concepts
Database If connecting
Appendix B - Commonly Used SQL to a multiple data source such as an RDBMS, this is the
Statements
name of the database to which it's connected. If connecting to an
Appendix C - ADO.NET Frequently Asked Questions
Extensible Markup Language (XML) file, it could potentially represent a
Index
section of the document.
List of Figures
ListState
of Tables This property represents the current state of the connection such as
List of Listings Open or Closed.
List of Sidebars
Using Visual Basic .NET, you'll find that creating the Reader object includes far more typing than actually
Table of Contents
thinking through the problem because of the level of verboseness required to implement an interface.
Applied ADO.NETBuilding Data-Driven Solutions
Because the IDataRecordinterface includes strongly typed methods to get a column's value, you have
Introduction
to create an implementation for each and every GetXXX method. Table 13-7 describes the
Chapter 1 - ADO.NET Basics
IDataRecord interface's properties, and Table 13-8 describes its methods.
Chapter 2 - Data Components in Visual Studio .NET
Chapter 3 - ADO.NET
Table 13-7: in Disconnected
The Properties Environments Interface
of the IDataRecord
Chapter 4 - ADO.NET in Connected Environments
PROPERTY
Chapter DESCRIPTION
5 - Handling ADO.NET Events
Chapter 6- Integrating XML with ADO.NET
FieldCount The number of columns in the current row
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
A collection
Item8 - Constraints
Chapter and DataofRelations
objects that represents the current row
Chapter 9 - ADO.NET Exception Handling
Chapter 10 - Working with the ODBC .NET Data Provider
Table 13-8:
Chapter The Methods
11 - Stored of and
Procedures the Views
IDataRecord Interface
Chapter
METHOD12 - Oracle, SQLXML, and Other .NET Data Providers
DESCRIPTION
Chapter 13 - Developing a Custom Data Provider
GetBoolean()
Chapter GetsWeb
14 - Developing Database a Boolean valueusing
Applications for the specified column
ASP.NET
Chapter 15 - Using ADO.NET in Xml Web Services
GetByte() Gets a byte value for the specified column
Chapter 16 - ASP.NET Server Controls and Data Binding
GetBytes()
Chapter Gets
17 - Building Real-World anApplications
Web array of bytes for the specified column
Chapter 18 - Object-Relational Gets
GetChar() Mapping in .NET for the specified column
a character
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
GetChars()
Chapter Gets
20 - COM Interoperability anADO.NET
and array of characters for the specified column
Chapter 21 - Messaging
GetData() Gets an IDataReader for the specified column, which is useful for
Chapter 22 - SQL Server and ADO.NET: Notes on of
nested structures Performance
data
Appendix A - Relational Databases: Some Basic Concepts
GetDataTypeName() Gets a string that represents the data type for the specified column
Appendix B - Commonly Used SQL Statements
Appendix C - ADO.NET Frequently
GetDateTime() GetsAsked Questionsobject for the specified column
a DateTime
Index
GetDecimal() Gets a decimal for the specified column
List of Figures
ListGetDouble()
of Tables Gets a double for the specified column
List of Listings
GetFieldType() Gets a Type object for the specified column
List of Sidebars
GetFloat() Gets a Float object for the specified column
GetGuid() Gets a globally unique identifier for the specified column
GetInt16() Gets a 16-bit integer for the specified column
GetInt32() Gets a 32-bit integer for the specified column
GetInt64() Gets a 64-bit integer for the specified column
GetName() Gets a text name for the specified column
GetOrdinal() Gets the column number of the column of a specified name
Gets a string
GetString() Applied ADO.NET: for the
Building specified column
Data-Driven Solutions
GetValue() by Mahesh Chand and
Gets an Davidfor
object Talbot ISBN:1590590732
the specified column
Apress 2003 (928 pages)
Gets an
GetValues() This text provides array ofcoverage
extensive objects for the specified
of ADO.NET column
technology
including ADO.NET internals, namespaces, classes, and
Returns
IsDBNull() interfaces, and True if the current column is null
takes a comprehensive look at XML
namespaces and classes, and how to integrate both with
ADO.NET.
Table of Contents
Applied ADO.NETBuilding Data-Driven Solutions
Introduction
Chapter 1 - ADO.NET Basics
Chapter 2 - Data Components in Visual Studio .NET
Chapter 3 - ADO.NET in Disconnected Environments
Chapter 4 - 13-3:
Figure ADO.NET in from
Data Connected Environmentsin Notepad
pipeddata.txt
Chapter 5 - Handling ADO.NET Events
Chapter
As you 6can- Integrating XML with
see from Figure ADO.NET
13-3, a piped format file is basically a series of columns separated by the pipe symbol
(|). There's
Chapter 7 - no data
Data typing-or
Binding even theForms
and Windows suggestion of dataControls
Data-Bound typing-other than what can be guessed from the strings
between
Chapter 8 each pipe. Forand
- Constraints thisData
reason, the object you'll implement will only support string data and not attempt to
Relations
make a9guess
Chapter that the
- ADO.NET first column
Exception in the figure should be an integer.
Handling
Chapter 10 - Working with the ODBC .NET Data Provider
Creating the PipedDataConnection Object
Chapter 11 - Stored Procedures and Views
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Because
Chapter 13 the data provider
- Developing you'reData
a Custom creating needs to access a file system object, the connection implemented in
Provider
Listing 14
Chapter 13-2 manages the
- Developing file handle
Database Web for the file provided
Applications to the object.
using ASP.NET
Chapter 15 - Using ADO.NET in Xml Web Services
Listing 13-2: The PipedDataConnection Object
Chapter 16 - ASP.NET Server Controls and Data Binding
Chapter 17 - Building Real-World Web Applications
Imports
Chapter 18 -System
Object-Relational Mapping in .NET
Imports
Chapter 19 -System.Data
Mapped Objects: Performance Considerations and Data Binding
Imports System.IO
Chapter 20 - COM Interoperability and ADO.NET
Chapter 21 - Messaging
Namespace AppliedADO.DataProvider
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Appendix A - Relational Databases: Some Basic Concepts
Public Class PipedDataConnection
Appendix B - Commonly Used SQL Statements
Implements System.Data.IDbConnection
Appendix C - ADO.NET Frequently Asked Questions
Index Public FileName As String
List of Figures
Friend file As System.IO.StreamReader
List of Tables
List of Listings
List of Sidebars
Public Sub New(ByVal fn As String)
Me.FileName = fn
file = New StreamReader(New FileStream(Me.FileName, FileMode.Open))
_State = ConnectionState.Open
'The constructor for this connection opens a file handle
End Sub
Imports System
Imports System.Data
Namespace AppliedADO.DataProvider
Private _CommandTimeout = 0
Table of Contents
Public Property CommandTimeout()_
Applied ADO.NETBuilding
As Integer ImplementsData-Driven Solutions
IDbCommand.CommandTimeout
Introduction Get
Chapter 1 - ADO.NET Basics
Return _CommandTimeout
Chapter 2 - Data End
Components
Get in Visual Studio .NET
Chapter 3 Set(ByVal
- ADO.NET ValueEnvironments
in Disconnected As Integer)
Chapter 4 - ADO.NET in_CommandTimeout = Value
Connected Environments
Chapter 5 EndADO.NET
- Handling Set Events
Chapter 6 -End Property
Integrating XML with ADO.NET
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
Chapter 8
Private _CommandType As CommandType
- Constraints and Data Relations
Chapter 9 - ADO.NET Exception Handling
Public Property CommandType() As CommandType _
Chapter 10 - Working with the ODBC .NET Data Provider
Implements IDbCommand.CommandType
Chapter 11 - Stored Procedures and Views
Get
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Return _CommandType
Chapter 13 - Developing
End Get a Custom Data Provider
Chapter 14 - Developing Database
Set(ByVal Value Web Applications using ASP.NET
As CommandType)
Chapter 15 - Using ADO.NET in Xml Web Services
If (Value <> CommandType.Text) Then
Chapter 16 - ASP.NET Server Controls and Data Binding
NotSupported()
Chapter 17 - Building Real-World
End If Web Applications
Chapter 18 - Object-Relational Mapping in .NET
_CommandType = Value
EndObjects:
Chapter 19 - Mapped Set Performance Considerations and Data Binding
Chapter 20 -End
COM Property
Interoperability and ADO.NET
Chapter 21 - Messaging
Chapter 22 -Private
SQL Server_Connection As IDbConnection
and ADO.NET: Notes on Performance
Appendix A - Relational Databases: Some Basic Concepts
Public Property Connection() As IDbConnection _
Appendix B - Commonly Used SQL Statements
Implements IDbCommand.Connection
Appendix C - ADO.NET Frequently Asked Questions
Get
Index
Return _Connection
List of Figures
End Get
List of Tables
Set(ByVal Value As IDbConnection)
List of Listings _Connection = Value
List of Sidebars End Set
End Property
Namespace AppliedADO.DataProvider
Table of Contents
Public Function GetBoolean(ByVal i As Integer) _
Applied ADO.NETBuilding
As Boolean ImplementsData-Driven Solutions
IDataReader.GetBoolean
Introduction Return CType(_cols(i), Integer)
Chapter 1 -End
ADO.NET Basics
Function
Chapter 2 - Data Components in Visual Studio .NET
Chapter 3 -Public
ADO.NET Function GetByte(ByVal
in Disconnected Environments i As Integer) _
As Byte
Chapter 4 -Implements IDataReader.GetByte
ADO.NET in Connected Environments
Chapter 5 Return
- Handling CType(_cols(i),
ADO.NET Events Byte)
Chapter 6 -End Function
Integrating XML with ADO.NET
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
Chapter 8
Public Function GetBytes(ByVal i As Integer, ByVal _
- Constraints and Data Relations
fieldoffset As Long, ByVal bytes()_
Chapter 9 - ADO.NET Exception Handling
As Byte, ByVal length As Integer, ByVal bufferoffset As Integer) _
Chapter 10 - Working with the ODBC .NET Data Provider
As Long Implements IDataReader.GetBytes
Chapter 11 - Stored Procedures and Views
NotSupported()
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Return Nothing
Chapter 13 -End
Developing a Custom Data Provider
Function
Chapter 14 - Developing Database Web Applications using ASP.NET
Chapter 15 -Public
Using ADO.NET in Xml GetChar(ByVal
Function Web Services i As Integer) _
Chapter 16 - ASP.NET Server Controls and Data Binding
As Char Implements IDataReader.GetChar
Chapter 17 - Building Real-World
Return Web Applications Char)
CType(_cols(i),
Chapter 18 -End
Object-Relational
Function Mapping in .NET
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
Chapter 20 -Public Function and
COM Interoperability GetChars(ByVal
ADO.NET i As Integer, ByVal fieldoffset As Long, _
ByVal21buffer
Chapter As Char(), ByVal length As Integer, ByVal bufferoffset As Integer) _
- Messaging
As Long
Chapter 22 -Implements
SQL Server andIDataReader.GetChars
ADO.NET: Notes on Performance
NotSupported()
Appendix A - Relational Databases: Some Basic Concepts
Return Nothing
Appendix B - Commonly Used SQL Statements
End Function
Appendix C - ADO.NET Frequently Asked Questions
Index
Public Function GetData(ByVal i As Integer) As _
List of Figures
IDataReader Implements IDataReader.GetData
List of Tables
NotSupported()
List of Listings Return Nothing
List of Sidebars
End Function
Public Function GetDataTypeName(ByVal i As Integer) _
As String Implements IDataReader.GetDataTypeName
Return GetType(String).ToString()
End Function
End Class
End Namespace
There are portions of the object
Applied that Building
ADO.NET: are hard-coded such as
Data-Driven the type of data supported. Because piped format
Solutions
contains no meta-data as to the data types of
by Mahesh Chand and David Talbot
each column, you have to assume that they're all strings. Also,
ISBN:1590590732
because there's no meta-data, the columns are not actually named, so the PipedDataReader has to invent a
Apress 2003 (928 pages)
column name for each column based on its position.
This text provides extensive coverage of ADO.NET technology
including ADO.NET internals, namespaces, classes, and
The final item of interest in the PipedDataReader object is the IEnumerableinterface and its related
interfaces, and takes a comprehensive look at XML
implementation. By implementing
namespaces this interface,
and classes, and howyou
to allow yourboth
integrate PipedDataReader
with to be bound directly to Web
page and Windows Forms controls. In situations where performance is an absolute requirement down to the last
ADO.NET.
processor cycle, Microsoft's tests show the DataReader to far outperform working with DataSets and
XMLReaders.
Table of Contents
The real
Applied joy of this is the Data-Driven
ADO.NETBuilding simplicity of Solutions
this implementation. All you have to do is implement the GetEnumerator()
method and return a DbEnumerator object. Because you're implementing a standard .NET interface, there's a
Introduction
related1object
Chapter that knows
- ADO.NET how to work with it; therefore, there's no reason for you to implement a custom
Basics
enumerator
Chapter for your
2 - Data data provider.
Components in Visual Studio .NET
Chapter 3 - ADO.NET in Disconnected Environments
Creating
Chapter 4 the PipedDataAdapter
- ADO.NET in Connected Environments Object
Chapter 5 - Handling ADO.NET Events
Finally,6the- PipedDataAdapter
Chapter object is where it all comes together. This object provides the layer between the
Integrating XML with ADO.NET
data source
Chapter and Binding
7 - Data the DataSet. This object
and Windows Formsalso defines what
Data-Bound operation should be performed to fill the DataSet
Controls
with data
Chapter 8 and how to goand
- Constraints about updating
Data the data source to reflect changes made to the DataSet in your data
Relations
source.9
Chapter - ADO.NET Exception Handling
Chapter 10 - inherits
This object WorkingDbDataAdapter
with the ODBC .NETto Data Provider
get the utility of methods such as Fill(). It also implements the
Chapter 11 - Stored Procedures and Views
IDbDataAdapter interface to define what IDbCommands (the interface that defines a single operation on the
Chapter 12 - Oracle,
data source) performSQLXML, and Other
operations on the.NET Data Providers
DataSet.
Chapter 13 - Developing a Custom Data Provider
The four
Chapter 14main points ofDatabase
- Developing interest in thisApplications
Web implementation
using are the SelectCommand,InsertCommand,
ASP.NET
UpdateCommand,
Chapter and DeleteCommand
15 - Using ADO.NET properties. You'll probably recall the names of these commands from
in Xml Web Services
the first16
Chapter few chaptersServer
- ASP.NET of this Controls
book. Each of these
and Data commands, once defined, allows any alteration made in the data
Binding
source or DataSet to be reflected in the other. Listing 13-5 shows the PipedDataAdapter object.
Chapter 17 - Building Real-World Web Applications
Chapter 18 - Object-Relational Mapping in .NET
Listing 13-5: The PipedDataAdapter Object
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
Chapter 20 - COM Interoperability and ADO.NET
Imports System
Chapter 21 - Messaging
Imports System.Data
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Imports System.Data.Common
Appendix A - Relational Databases: Some Basic Concepts
Imports System.IO
Appendix B - Commonly Used SQL Statements
Imports PipedDataProvider
Appendix C - ADO.NET Frequently Asked Questions
Index
Namespace AppliedADO.DataProvider
List of Figures
Public Class PipedDataAdapter
List of TablesInherits DbDataAdapter
List of Listings
Implements IDbDataAdapter
List of Sidebars
Public Sub New()
End Sub
Table of Contents
Protected Overrides Sub OnRowUpdated(ByVal value As RowUpdatedEventArgs)
Applied ADO.NETBuilding Data-Driven Solutions
Introduction End Sub
Chapter 1 -Protected
ADO.NET Basics
Overrides Sub OnRowUpdating(ByVal e As RowUpdatingEventArgs)
Chapter 2 -EndData Sub
Components in Visual Studio .NET
Chapter 3 - ADO.NET in Disconnected Environments
Chapter 4 -Private
ADO.NET in_SelectCommand As IDbCommand
Connected Environments
Chapter 5 -Private _InsertCommand
Handling ADO.NET Events As IDbCommand
Chapter 6 -Private
Integrating_UpdateCommand
XML with ADO.NET As IDbCommand
Chapter 7 -Private _DeleteCommand
Data Binding and Windows FormsAs IDbCommand
Data-Bound Controls
Chapter 8 - Constraints and Data Relations
Public Property SelectCommand() As IDbCommand Implements _
Chapter 9 - ADO.NET Exception Handling
IDbDataAdapter.SelectCommand
Chapter 10 - Working with the ODBC .NET Data Provider
Get
Chapter 11 - Stored Procedures and Views
Return _SelectCommand
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
End Get
Chapter 13 - Developing a Custom
Set(ByVal Data Provider
Value As IDbCommand)
Chapter 14 - Developing_SelectCommand
Database Web Applications
= Valueusing ASP.NET
Chapter 15 - UsingEnd
ADO.NET
Set in Xml Web Services
Chapter 16 -End
ASP.NET Server Controls and Data Binding
Property
Chapter 17 - Building Real-World Web Applications
Chapter 18 -Public
Object-Relational
Property Mapping in .NET
InsertCommand() As IDbCommand Implements _
IDbDataAdapter.InsertCommand
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
Chapter 20 - COM Get
Interoperability and ADO.NET
Chapter 21 - Messaging Return _InsertCommand
End Get
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Set(ByVal
Appendix A - Relational Value
Databases: Some As IDbCommand)
Basic Concepts
_InsertCommand = Value
Appendix B - Commonly Used SQL Statements
End Set
Appendix C - ADO.NET Frequently Asked Questions
End Property
Index
Public Property UpdateCommand() As IDbCommand Implements _
List of Figures
IDbDataAdapter.UpdateCommand
List of Tables
Get
List of Listings Return _UpdateCommand
List of Sidebars End Get
Set(ByVal Value As IDbCommand)
_UpdateCommand = Value
End Set
End Property
using ASP.NET
Apress 2003 (928 pages)
This text provides extensive coverage of ADO.NET technology
As the programmingincluding
worldADO.NET internals,
moves toward thenamespaces, classes,
Internet these days, and
it's becoming important for developers
interfaces, and takes a comprehensive look at XML
to be able to create Web applications and Web services. The Microsoft
namespaces and classes, and how to integrate both with
.NET Framework enables you to
develop, maintain, and deploy
ADO.NET. reliable and high-performance Web applications and Web services.
This chapter starts with an overview of ASP.NET and how to install it, followed by a simple Web
application
Table development using Visual Studio .NET (VS .NET). After that it discusses the Web Forms
of Contents
controls
Applied and how to use them.
ADO.NETBuilding The Web
Data-Driven Forms' DataGrid control is a useful control to develop Web-
Solutions
based database applications. You can bind a DataSet to the DataGrid control as did for a Windows
Introduction
Forms'DataGrid
Chapter control.
1 - ADO.NET BasicsThis chapter also discusses how to fill data to a DataGrid and how to develop
powerful Web-based
Chapter 2
database applications using the DataGrid control. It also discusses how to enable
- Data Components in Visual Studio .NET
paging in a DataGrid control. At the end of the chapter you'll see how to develop a guest book for your
Chapter 3 - ADO.NET in Disconnected Environments
Web site using ASP.NET.
Chapter 4 - ADO.NET in Connected Environments
Chapter 5 - Handling ADO.NET Events
Introducing
Chapter 6 ASP.NET
- Integrating XML with ADO.NET
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
Writing database Web applications using ADO.NET in VS .NET is similar to writing Windows applications.
Chapter 8 - Constraints and Data Relations
The Microsoft .NET Class Library provides a set of server-side controls, which you can treat as Windows
Chapter 9 - ADO.NET Exception Handling
controls. To create a Web application, all you have to do is create a simple project, drag server-side
Chapter 10 - Working with the ODBC .NET Data Provider
controls onto a Web form, set their properties, and write event handlers. In this chapter, you'll first develop
Chapter 11Web
a simple - Stored Procedures
application and and
see Views
how the ASP.NET model works with Visual Basic .NET (VB .NET) and
Chapter
other .NET languages. After thatOther
12 - Oracle, SQLXML, and you'll.NET Data Providers
concentrate on ASP.NET and see how to write some real-world
Chapter 13 Web
database - Developing a Custom
applications usingData Providerand VB .NET.
ADO.NET
Chapter 14 - Developing Database Web Applications using ASP.NET
Chapter 15 - Using ADO.NET in Xml Web Services
ASP.NET Platform Requirements
Chapter 16 - ASP.NET Server Controls and Data Binding
Chapter 17 - Building
The following Real-World
operating systemsWeb Applications
support ASP.NET: Windows XP, Windows 2000 Server, and Windows
Chapter 18 - Object-Relational
NT 4 (running Mapping
Service Pack 6a) in .NET Information Services (IIS) 4 or later. Also, you must have the
with Internet
Chapter 19 - Mapped
.NET Software Objects: Performance
Development Considerations
Kit (SDK) installed and Data Binding
on the server.
Chapter 20 - COM Interoperability and ADO.NET
Chapter 21 - Messaging
ASP.NET Language Support
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Appendix
You canAuse- Relational Databases: Some
any .NET-supported Basic to
language Concepts
write ASP.NET applications, including C#, VB .NET, and
JScript. B
Appendix As- this book isUsed
Commonly aboutSQL
VBStatements
.NET, the other languages are beyond the scope of this book.
Appendix C - ADO.NET Frequently Asked Questions
Installing ASP.NET
Index
List of Figures
You
List of can develop and run ASP.NET applications on Windows 2000 or Windows XP operating systems.
Tables
ASP.NET
List ships with VS .NET. For developers who don't have VS .NET, ASP.NET comes in a separate
of Listings
package,
List which can be downloaded from the Microsoft's Web site (www.microsoft.com). If you want to
of Sidebars
develop ASP.NET mobile-enabled applications for Pocket PC or cellular phones, you need to install
ASP.NET Mobile Internet Toolkit, which you can also download from Microsoft Web site.
ASP.NET Editors
We'll be using VS .NET to develop the applications in this chapter. However, like most languages in the
.NET family, you can develop ASP.NET applications using any text editor and command-line compiler.
After compiling, you copy your file manually to IIS to deploy the application. The advantage of using VS
.NET is that it provides you with a visual Integrated Development Environment (IDE) to drag and drop
controls onto a page and view the Hypertext Markup Language (HTML) code in an HTML editor. Other
features are IntelliSense and syntax checking. In summary, you can use VS .NET to compile, debug, and
deploy your application.
Applied ADO.NET: Building Data-Driven Solutions
Note ASP.NETby Mahesh
editors, Chand andVS
including David Talbot
.NET, provide What-You-See-Is-What-You-Get
ISBN:1590590732 (WYSIWYG)
supportApress
for developing
2003 (928Graphical
pages) User Interface (GUI) applications by dropping controls on the
Web Forms pages.
This text provides extensive coverage of ADO.NET technology
including ADO.NET internals, namespaces, classes, and
Microsoft has alsointerfaces,
releasedand takes a comprehensive
a lightweight, easy-to-use,look
and at XML
free ASP.NET development tool (including
editor) for non-VSnamespaces and classes,
.NET developers. and how
You can to integrate
find more detailsboth with
about this tool on the www.asp.net Web
ADO.NET.
site.
Similar to Windows applications and services, you can also write Web applications and services. A Web
application is a distributed application, which allows you to work and distribute functionality over the Web
and provides user interfaces. Using Web Forms controls, you can write Web GUI applications similar to
Windows applications.
ASP.NET's Web Forms provide you with the ability to build Web-based GUI applications. Web Forms
include Web pages (also called ASP.NET pages or Web Forms pages) and GUI components (sometimes
calledserver controls) such as a TextBox,Button,ListBox,DataGrid, and so on. ASP.NET
Applied ADO.NET: Building Data-Driven Solutions
provides the flexibility to add these controls to an ASP.NET page at runtime as well as at design-time. VS
by Maheshfeatures
.NET provides design-time Chand and David Talbot
to develop ISBN:1590590732
applications in no time. You add controls to a page by
Apress 2003 (928 pages)
dragging controls from the Toolbox to the page and then setting the controls' properties and events. Web
Forms also provideThis a text provides
method extensive
for using coverage of ADO.NET
the Codebehind directivetechnology
to separate your data from the code. In
including ADO.NET internals, namespaces, classes, and
other words, you can write code in a separate file from the controls.
interfaces, and takes a comprehensive look at XML
namespaces and classes, and how to integrate both with
Web services areADO.NET.
applications that perform a certain task; they can be used by a single application as well
as distributed on the Web. However, Web services don't usually have a user interface like a normal
application would. Chapter 15 covers Web services.
Table of Contents
Applied ADO.NETBuilding Data-Driven Solutions
Introduction
Chapter 1 - ADO.NET Basics
Chapter 2 - Data Components in Visual Studio .NET
Chapter 3 - ADO.NET in Disconnected Environments
Chapter 4 - ADO.NET in Connected Environments
Chapter 5 - Handling ADO.NET Events
Chapter 6 - Integrating XML with ADO.NET
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
Chapter 8 - Constraints and Data Relations
Chapter 9 - ADO.NET Exception Handling
Chapter 10 - Working with the ODBC .NET Data Provider
Chapter 11 - Stored Procedures and Views
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Chapter 13 - Developing a Custom Data Provider
Chapter 14 - Developing Database Web Applications using ASP.NET
Chapter 15 - Using ADO.NET in Xml Web Services
Chapter 16 - ASP.NET Server Controls and Data Binding
Chapter 17 - Building Real-World Web Applications
Chapter 18 - Object-Relational Mapping in .NET
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
Chapter 20 - COM Interoperability and ADO.NET
Chapter 21 - Messaging
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Appendix A - Relational Databases: Some Basic Concepts
Appendix B - Commonly Used SQL Statements
Appendix C - ADO.NET Frequently Asked Questions
Index
List of Figures
List of Tables
List of Listings
List of Sidebars
DevelopingApplied
YourADO.NET:
First ASP.NET Web Application
Building Data-Driven Solutions
by Mahesh Chand and David Talbot ISBN:1590590732
Before discussingApress
the ASP.NET
2003 (928model
pages) in more depth, we'll show you how to develop your first ASP.NET
application using This
VS .NET.
text providesexample,
In this extensive you'll create
coverage a simple technology
of ADO.NET Web application using VS .NET. You'll
add a Button, aincluding
TextBox, and a ListBox control to a Web page
ADO.NET internals, namespaces, classes, and and then add the TextBox contents
to the ListBox on interfaces, andclick
the button takes a comprehensive look at XML
event.
namespaces and classes, and how to integrate both with
ADO.NET.
Creating a Web Application Project
Table of Contents
Creating a new ASP.NET Web application using VS .NET is simple. First create a new project using File
New ADO.NETBuilding
Applied Project Visual Basic
Data-Driven Solutions
Projects and then select the ASP.NET Web Application template (see
Figure 14-1).
Introduction
Chapter 1 - ADO.NET Basics
Chapter 2 - Data Components in Visual Studio .NET
Chapter 3 - ADO.NET in Disconnected Environments
Chapter 4 - ADO.NET in Connected Environments
Chapter 5 - Handling ADO.NET Events
Chapter 6 - Integrating XML with ADO.NET
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
Chapter 8 - Constraints and Data Relations
Chapter 9 - ADO.NET Exception Handling
Chapter 10 - Working with the ODBC .NET Data Provider
Chapter 11 - Stored Procedures and Views
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Chapter 13 - Developing a Custom Data Provider
Chapter 14 - Developing Database Web Applications using ASP.NET
Chapter 15 - Using ADO.NET in Xml Web Services
Chapter 16 - ASP.NET Server Controls and Data Binding
Chapter 17 - Building Real-World Web Applications
Figure 14-1: The FirstWebApplication project
Chapter 18 - Object-Relational Mapping in .NET
Chapter
As you 19
see- in
Mapped
FigureObjects: Performance
14-1, the Considerations
Location box anddefault
shows you the Data Binding
option of http://localhost and the
Chapter 20 - name.
application COM Interoperability
Here, localhostand ADO.NET
represents the default IIS server running on your local machine. The
default 21
Chapter virtual directory for localhost is C:\Inetpub\wwwroot.
- Messaging
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Clicking the OK button creates a new directory, FirstWebApplication, in the server's virtual directory.
Appendix A - Relational Databases: Some Basic Concepts
It also creates a new Web application and sends you to the default WebForm1.aspx page, as shown in
Appendix B - Commonly Used SQL Statements
Figure 14-2.
Appendix C - ADO.NET Frequently Asked Questions
Index
List of Figures
List of Tables
List of Listings
List of Sidebars
Applied ADO.NET: Building Data-Driven Solutions
by Mahesh Chand and David Talbot ISBN:1590590732
Apress 2003 (928 pages)
This text provides extensive coverage of ADO.NET technology
including ADO.NET internals, namespaces, classes, and
interfaces, and takes a comprehensive look at XML
namespaces and classes, and how to integrate both with
ADO.NET.
Table of Contents
Applied ADO.NETBuilding Data-Driven Solutions
Introduction
Chapter 1 - ADO.NET Basics
Chapter 2 - Data Components in Visual Studio .NET
Chapter 3 - ADO.NET in Disconnected Environments
Chapter 4 - ADO.NET in Connected Environments
Figure 14-2: DefaultWebForm1.aspx page
Chapter 5 - Handling ADO.NET Events
Chapter 6 - Integrating XML with ADO.NET
From here
Chapter 7 - you
Datacan edit your
Binding page's HTML.
and Windows FormsAs you see inControls
Data-Bound the left-bottom corner of Figure 14-2, there are
two modes
Chapter 8 - available:
ConstraintsDesign andRelations
and Data HTML. Click the HTML button to edit the code, as shown in Figure 14-3.
Chapter 9 - ADO.NET Exception Handling
Chapter 10 - Working with the ODBC .NET Data Provider
Chapter 11 - Stored Procedures and Views
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Chapter 13 - Developing a Custom Data Provider
Chapter 14 - Developing Database Web Applications using ASP.NET
Chapter 15 - Using ADO.NET in Xml Web Services
Chapter 16 - ASP.NET Server Controls and Data Binding
Chapter 17 - Building Real-World Web Applications
Chapter 18 - Object-Relational Mapping in .NET
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
Chapter 20 - COM Interoperability and ADO.NET
Chapter 21 - Messaging
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Appendix A - Relational Databases: Some Basic Concepts
Figure 14-3: HTML view of WebForm1.aspx
Appendix B - Commonly Used SQL Statements
Appendix C - ADO.NET Frequently Asked Questions
The HTML view shows you the HTML code of a page, its controls, and control properties. The HTML editor
Index
also
List of let you edit the HTML manually.
Figures
List of Tables
Now, if you switch to the design mode and right-click the page, you'll get several options: View HTML
List of Listings
Source, Build Style, View in Browser, View Code, Synchronize Document Outline, and so on (see Figure
List of Sidebars
14-4).
Applied ADO.NET: Building Data-Driven Solutions
by Mahesh Chand and David Talbot ISBN:1590590732
Apress 2003 (928 pages)
This text provides extensive coverage of ADO.NET technology
including ADO.NET internals, namespaces, classes, and
interfaces, and takes a comprehensive look at XML
namespaces and classes, and how to integrate both with
ADO.NET.
Table of Contents
Applied ADO.NETBuilding Data-Driven Solutions
Introduction
Chapter 1 - ADO.NET Basics
Chapter 2 - Data Components in Visual Studio .NET
Chapter 3 - ADO.NET in Disconnected Environments
Chapter 4 - ADO.NET in Connected Environments
Chapter 5 - Handling ADO.NET Events
Chapter 6 - Integrating XML with ADO.NET
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
Chapter 8 - Constraints and Data Relations
Chapter 9 - ADO.NET Exception Handling
Chapter 10 - 14-4:
Figure Working
Anwith the ODBC
ASP.NET .NETright-click
page's Data Provider
options
Chapter 11 - Stored Procedures and Views
You can
Chapter 12set a page's
- Oracle, properties
SQLXML, and by selecting
Other Properties
.NET Data from the right-click menu. The Properties menu
Providers
opens the
Chapter 13 -Document
DevelopingProperty
a CustomPages window. As you can see from Figure 14-5, there are three tabs
Data Provider
available
Chapter 14 in the Properties
- Developing window:
Database WebGeneral, Colorusing
Applications and ASP.NET
Margins, and Keywords. Most of the properties are
self-explanatory.
Chapter 15 - Using On the General
ADO.NET in Xml tab,
Webone merits explanation. The Page Layout property has two options,
Services
GridLayout
Chapter 16 - and FlowLayout.
ASP.NET GridLayout
Server Controls is when
and Data you want drop controls to the page and reposition them. If
Binding
you want
Chapter 17 to add textReal-World
- Building to the page,
WebyouApplications
should set the page layout to FlowLayout; otherwise you won't be
able to add text to the page. After setting the Page Layout property to FlowLayout, the editor works as a
Chapter 18 - Object-Relational Mapping in .NET
text editor.
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
Chapter 20 - COM Interoperability and ADO.NET
Chapter 21 - Messaging
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Appendix A - Relational Databases: Some Basic Concepts
Appendix B - Commonly Used SQL Statements
Appendix C - ADO.NET Frequently Asked Questions
Index
List of Figures
List of Tables
List of Listings
List of Sidebars
Table of Contents
Applied ADO.NETBuilding Data-Driven Solutions
Introduction
Chapter 1 - ADO.NET Basics
Chapter 2 - Data Components in Visual Studio .NET
Chapter 3 - ADO.NET in Disconnected Environments
Chapter 4 - ADO.NET in Connected Environments
Chapter 5 - Handling ADO.NET Events
Chapter 6 - Integrating XML with ADO.NET
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
Chapter 8 - Constraints and Data Relations
Chapter 9 - ADO.NET Exception Handling
Chapter 10 - Working with the ODBC .NET Data Provider
Chapter 11 - Stored Procedures and Views
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Chapter 13 - Developing a Custom Data Provider
Chapter 14 - Developing Database Web Applications using ASP.NET
Chapter 15 - Using ADO.NET in Xml Web Services
Chapter 16 - ASP.NET Server Controls and Data Binding
Chapter 17 - Building Real-World Web Applications
Chapter 18 - Object-Relational Mapping in .NET
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
Chapter 20 - COM Interoperability and ADO.NET
Chapter 21 - Messaging
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Figure
Appendix A - 14-6: WebDatabases:
Relational Forms controls
Some Basic Concepts
Appendix B - Commonly Used SQL Statements
For the applications in this chapter, we'll be using the Web Forms controls.
Appendix C - ADO.NET Frequently Asked Questions
Index
OK, now you can switch the page back to the design mode and GridLayout mode (if you changed its
List of Figures
modes) and add a Button, a TextBox, and a ListBox to the form by dragging these controls from the
List
Web Tables
of Forms toolbox to WebForm1.aspx. The page should now look like Figure 14-7.
List of Listings
List of Sidebars
Applied ADO.NET: Building Data-Driven Solutions
by Mahesh Chand and David Talbot ISBN:1590590732
Apress 2003 (928 pages)
This text provides extensive coverage of ADO.NET technology
including ADO.NET internals, namespaces, classes, and
interfaces, and takes a comprehensive look at XML
namespaces and classes, and how to integrate both with
ADO.NET.
Table of Contents
Applied ADO.NETBuilding Data-Driven Solutions
Introduction
Figure
Chapter 1 - 14-7: WebForms1.aspx
ADO.NET Basics Design mode after adding Web Forms controls
Chapter 2 - Data Components in Visual Studio .NET
Chapter 3 - ADO.NET in Disconnected Environments
Setting- ADO.NET
Chapter 4 Control Properties
in Connected Environments
Chapter 5 - Handling ADO.NET Events
The next
Chapter 6 step is to add XML
- Integrating some textADO.NET
with to the page and change some of the controls' properties. To add text to
the page, first
Chapter 7
you need to change the page layout to FlowLayout in the Properties window, which you
- Data Binding and Windows Forms Data-Bound Controls
open by right-clicking the page and selecting Properties. Now add a heading to the page. For this
Chapter 8 - Constraints and Data Relations
example, add two lines to the page and set different fonts and font sizes of these lines. You can also set
Chapter 9 - ADO.NET Exception Handling
some of the Button control's properties (see Figure 14-8).
Chapter 10 - Working with the ODBC .NET Data Provider
Chapter 11 - Stored Procedures and Views
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Chapter 13 - Developing a Custom Data Provider
Chapter 14 - Developing Database Web Applications using ASP.NET
Chapter 15 - Using ADO.NET in Xml Web Services
Chapter 16 - ASP.NET Server Controls and Data Binding
Chapter 17 - Building Real-World Web Applications
Chapter 18 - Object-Relational Mapping in .NET
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
Chapter 20 - COM Interoperability and ADO.NET
Chapter 21 - Messaging
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Appendix A - Relational Databases: Some Basic Concepts
Appendix B - Commonly Used SQL Statements
Appendix C - ADO.NET Frequently Asked Questions
Index
List of Figures
List of Tables
Figure 14-8: Properties window for the Web controls
List of Listings
List of Sidebars
Specifically, we changed the border, background color, font, and foreground color of these controls. As
you can see, changing these properties is similar to changing them for Windows applications. The final
page with these properties looks like Figure 14-9.
Applied ADO.NET: Building Data-Driven Solutions
by Mahesh Chand and David Talbot ISBN:1590590732
Apress 2003 (928 pages)
This text provides extensive coverage of ADO.NET technology
including ADO.NET internals, namespaces, classes, and
interfaces, and takes a comprehensive look at XML
namespaces and classes, and how to integrate both with
ADO.NET.
Table of Contents
Applied ADO.NETBuilding Data-Driven Solutions
Introduction
Chapter 1 - ADO.NET Basics
Chapter 2 - Data Components in Visual Studio .NET
Chapter 3 - ADO.NET in Disconnected Environments
Figure
Chapter 4 - 14-9: Final
ADO.NET in page of theEnvironments
Connected Web application after changing some control properties
Chapter 5 - Handling ADO.NET Events
Chapter 6 - Integrating XML with ADO.NET
Using Document
Chapter 7 Outline
- Data Binding and Windows Forms Data-Bound Controls
Chapter 8 - Constraints and Data Relations
Another nice feature of the VS .NET IDE is that you can synchronize a Web page's controls with its
Chapter 9 - ADO.NET Exception Handling
contents in the Document Outline viewer. This is useful when you're developing a Web application with
Chapter 10 - Working with the ODBC .NET Data Provider
hundreds of controls; it can be hard to keep track of all the controls, HTML tags, and other page contents.
Chapter 11 - Stored
The Document Procedures
Outline viewerand Viewsyou to manage a page's contents in a tree format. The tree format
enables
Chapter 12 - Oracle, SQLXML, and Other
displays all the page elements in the order .NET they're
Data Providers
called in the page. You can open the Document Outline
Chapter
viewer 13 - Developing aa Custom
by right-clicking page andData ProviderSynchronize Document Outline. Clicking this menu item
selecting
Chapter
launches14 the
- Developing
Document Database
Outline Web
viewerApplications
in the left using
pane ASP.NET
(see Figure 14-10). As you can see, the tree view
Chapter
displays15the- Using
page ADO.NET
contents,inincluding
Xml Webthe Services
form, button, text box, and paragraph. If you click a control in the
Document
Chapter 16 -Outline
ASP.NET viewer,
ServeritControls
selects and
the corresponding
Data Binding control in the form. And, vice versa, if you select a
control17
Chapter in the form, the
- Building viewer selects
Real-World that control in the tree view.
Web Applications
Chapter 18 - Object-Relational Mapping in .NET
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
Chapter 20 - COM Interoperability and ADO.NET
Chapter 21 - Messaging
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Appendix A - Relational Databases: Some Basic Concepts
Appendix B - Commonly Used SQL Statements
Appendix C - ADO.NET Frequently Asked Questions
Index
List of Figures
List of Tables
List of Listings
List of Sidebars
Figure 14-10: Document Outline viewer
You can also use the Document Outline viewer's right-click menu to cut, paste, delete, view the code, and
view the properties of these controls. The right-click menu's View Code option displays the code of the
page.
Not only that, but now you'll see one more thing. Select the HTML view of your page, and you can move to
specific HTML tags using the Document Outline viewer. As you can see from Figure 14-11, the tree view
displays all the code of an HTML page in a nested structure as they're organized in the original code.
Applied ADO.NET: Building Data-Driven Solutions
by Mahesh Chand and David Talbot ISBN:1590590732
Apress 2003 (928 pages)
This text provides extensive coverage of ADO.NET technology
including ADO.NET internals, namespaces, classes, and
interfaces, and takes a comprehensive look at XML
namespaces and classes, and how to integrate both with
ADO.NET.
Table of Contents
Applied ADO.NETBuilding Data-Driven Solutions
Introduction
Figure 14-11: HTML view of the Document Outline viewer
Chapter 1 - ADO.NET Basics
Chapter
So, the2point
- Data Components
is that in Visual
you can find Studio .NET
and organize your HTML code and controls from the Document Outline
viewer 3instead
Chapter of looking
- ADO.NET for a tag in the
in Disconnected file manually.
Environments
Chapter 4 - ADO.NET in Connected Environments
Writing- Handling
Chapter 5 Code ADO.NET
on theEvents
Button Click Event Handler
Chapter 6 - Integrating XML with ADO.NET
The last
Chapter 7 step of this
- Data tutorial
Binding andisWindows
to add an event
Forms handler forControls
Data-Bound the button and write code to add some TextBox
text to the
Chapter 8 -ListBox. You
Constraints andadd a control
Data event similar to Windows applications. You can just double-click
Relations
the button
Chapter 9 -toADO.NET
add a button click Handling
Exception event handler.
Chapter 10 - Working with the ODBC .NET Data Provider
This action adds the Button1_Click method to the WebForm1.aspx.vb class, which hosts the code
Chapter 11 - Stored Procedures and Views
for the page controls and events. Now write a line of code to add the TextBox contents to the list box.
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Specifically, add the bold line in the following section to the Button1_Click method:
Chapter 13 - Developing a Custom Data Provider
Chapter 14 - Developing Database Web Applications using ASP.NET
Private Sub Button1_Click(ByVal sender As System.Object, _
Chapter 15 - Using ADO.NET in Xml Web Services
ByVal e As System.EventArgs) Handles Button1.Click
Chapter 16 - ASP.NET Server Controls and Data Binding
ListBox1.Items.Add(TextBox1.Text.ToString())
Chapter 17 - Building Real-World Web Applications
End Sub
Chapter 18 - Object-Relational Mapping in .NET
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
Chapter 20 - COM Interoperability and ADO.NET
Note
Chapter 21 You can also see the code using the View Code option of the page's right-click menu.
- Messaging
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Now compile and run the project. The output of the program looks like Figure 14-12. Clicking the Add
Appendix A - Relational Databases: Some Basic Concepts
button adds the TextBox contents to the list box.
Appendix B - Commonly Used SQL Statements
Appendix C - ADO.NET Frequently Asked Questions
Index
List of Figures
List of Tables
List of Listings
List of Sidebars
Table of Contents
Applied ADO.NETBuilding Data-Driven Solutions
Introduction
Chapter 1 - ADO.NET Basics
Chapter 2 - Data Components in Visual Studio .NET
Chapter 3 - ADO.NET in Disconnected Environments
Chapter 4 - ADO.NET in Connected Environments
Chapter 5 - Handling ADO.NET Events
Chapter 6 - Integrating XML with ADO.NET
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
Chapter 8 - Constraints and Data Relations
Chapter 9 - ADO.NET Exception Handling
Chapter 10 - Working with the ODBC .NET Data Provider
Chapter 11 - Stored Procedures and Views
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Chapter 13 - Developing a Custom Data Provider
Chapter 14 - Developing Database Web Applications using ASP.NET
Chapter 15 - Using ADO.NET in Xml Web Services
Chapter 16 - ASP.NET Server Controls and Data Binding
Chapter 17 - Building Real-World Web Applications
Chapter 18 - Object-Relational Mapping in .NET
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
Chapter 20 - COM Interoperability and ADO.NET
Chapter 21 - Messaging
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Appendix A - Relational Databases: Some Basic Concepts
Appendix B - Commonly Used SQL Statements
Appendix C - ADO.NET Frequently Asked Questions
Index
List of Figures
List of Tables
List of Listings
List of Sidebars
Creating Your First
Applied ADO.NET
ADO.NET: Web Application
Building Data-Driven Solutions
by Mahesh Chand and David Talbot ISBN:1590590732
You've already seen how
Apress to develop
2003 an ASP.NET application using VS .NET. Now you'll see how to
(928 pages)
develop databaseThis applications using ADO.NET
text provides extensive and ASP.NET.
coverage of ADO.NET Totechnology
start creating your first ADO.NET
application, you'llincluding
create a ADO.NET
Web Application project as you did in the
internals, namespaces, classes, and previous tutorial. In this example, you'll
read data from the interfaces, and Northwind
SQL Server takes a comprehensive
database and look at XML
view data in few data-bound controls. After
namespacesadd
creating a Web application, andaclasses,
ListBoxand
andhow to integrate
a DataGrid bothtowith
control the Web page. In this application,
ADO.NET.
you'll fill these controls with data from the database.
After dragging these controls from the Web Forms control Toolbox and dropping it on the page, you write
Table of Contents
the code in Listing 14-1 on the Page_Load event. You can add a Page_Load event by typing the code
Applied ADO.NETBuilding Data-Driven Solutions
directly into the Codebehind.vb file or by double-clicking on the page.
Introduction
Chapter
Listing114-1:
- ADO.NET
Filling Basics
Data from a Database to Data-Bound Controls
Chapter 2 - Data Components in Visual Studio .NET
Chapter 3 - ADO.NET in Disconnected Environments
Private Sub Page_Load(ByVal sender As System.Object, _
Chapter 4 - ADO.NET in Connected Environments
ByVal e As System.EventArgs) Handles MyBase.Load
Chapter 5 - Handling ADO.NET Events
Dim ConnectionString As String = "user id=sa;password=;" & _
Chapter 6 "Initial
- Integrating XML with ADO.NET
Catalog=Northwind;" & _
Chapter 7 "Data
- Data Source=MCB;"
Binding and Windows Forms Data-Bound Controls
ChapterDim8 -conn
Constraints and Data Relations = New SqlConnection(ConnectionString)
As SqlConnection
Chapter'9 Open- ADO.NET Exception Handling
the connection
ChapterIf 10 (conn.State
- Working with the<>ODBC .NET Data Provider
ConnectionState.Open) Then
Chapter 11 - Stored Procedures and Views
conn.Open()
ChapterEnd12 -IfOracle, SQLXML, and Other .NET Data Providers
Chapter 13 - DevelopingAs
Dim adapter SqlDataAdapter
a Custom Data Provider = New SqlDataAdapter _
("SELECT EmployeeID,
Chapter 14 - Developing Database Web LastName,
ApplicationsFirstName
using ASP.NETFROM Employees", conn)
Dim ds As DataSet = New DataSet()
Chapter 15 - Using ADO.NET in Xml Web Services
Chapteradapter.Fill(ds, "Employees")
16 - ASP.NET Server Controls and Data Binding
' Bind data set to the control
Chapter 17 - Building Real-World Web Applications
' Set DataSource property of ListBox as DataSet's DefaultView
Chapter 18 - Object-Relational Mapping in .NET
ListBox1.DataSource = ds
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
ListBox1.SelectedIndex = 0
Chapter 20 - COM Interoperability and ADO.NET
' Set Field Name you want to get data from
Chapter 21 - Messaging
ListBox1.DataTextField = "FirstName"
Chapter'DataGrid1.DataSource
22 - SQL Server and ADO.NET:= Notes on Performance
ds.DefaultViewManager
Appendix A - Relational Databases:
DataGrid1.DataSource = ds Some Basic Concepts
Appendix' BDataGrid1.DataBind()
- Commonly Used SQL Statements
Appendix C - ADO.NET Frequently Asked Questions
DataBind()
Index ' Close the connection
List of Figures
If (conn.State = ConnectionState.Open) Then
conn.Close()
List of Tables
End If
List of Listings
End Sub
List of Sidebars
Note We're using a SQL Server database and the SqlClient data provider, which means we import the
System.Data.SqlClient namespace to the application.
As you can see, this code looks familiar. First you create a Connection object with the Northwind
database. After that you create a DataAdapter and select the EmployeeID, FirstName, and LastName
columns from the Employees table. Then you create a DataSet object and fill it using the
DataAdapter'sFill method. Once you have a DataSet, you set the DataSet as the ListBox's
DataSource property and set SelectIndex as 0. The SelectIndex property represents the index of
the column from a DataSet you want to display in the control. The field name of the column is FirstName.
You also set the DataSource property of DataGrid control as DataSet. At the end you call the
DataBind method Applied
of theADO.NET:
ListBox.Building Data-Driven
This method binds theSolutions
data to the data-bound controls.
by Mahesh Chand and David Talbot ISBN:1590590732
The output looks Apress
like Figure
200314-13. As you can see, the ListBox control displays data from the
(928 pages)
FirstName column of text
This the Employees table, and
provides extensive DataGrid
coverage displays
of ADO.NET all three columns.
technology
including ADO.NET internals, namespaces, classes, and
interfaces, and takes a comprehensive look at XML
namespaces and classes, and how to integrate both with
ADO.NET.
Table of Contents
Applied ADO.NETBuilding Data-Driven Solutions
Introduction
Chapter 1 - ADO.NET Basics
Chapter 2 - Data Components in Visual Studio .NET
Chapter 3 - ADO.NET in Disconnected Environments
Chapter 4 - ADO.NET in Connected Environments
Chapter 5 - Handling ADO.NET Events
Chapter 6 - Integrating XML with ADO.NET
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
Chapter 8 - Constraints and Data Relations
Chapter 9
Figure- 14-13:
ADO.NET Exception Handling
Your first ADO.NET Web application
Chapter 10 - Working with the ODBC .NET Data Provider
Chapter 11 - Stored Procedures and Views
In Figure
Chapter 1214-13, youSQLXML,
- Oracle, may notice
and the .NET Dataformat
DataGrid
Other looks different. You can set a DataGrid format by
Providers
using the
Chapter 13 Auto Format option
- Developing of the
a Custom Properties
Data Provider window.
Chapter 14 - Developing Database Web Applications using ASP.NET
Chapter 15 - Using ADO.NET in Xml Web Services
Chapter 16 - ASP.NET Server Controls and Data Binding
Chapter 17 - Building Real-World Web Applications
Chapter 18 - Object-Relational Mapping in .NET
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
Chapter 20 - COM Interoperability and ADO.NET
Chapter 21 - Messaging
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Appendix A - Relational Databases: Some Basic Concepts
Appendix B - Commonly Used SQL Statements
Appendix C - ADO.NET Frequently Asked Questions
Index
List of Figures
List of Tables
List of Listings
List of Sidebars
Using ASP.NET
AppliedServer-Side Controls
ADO.NET: Building Data-Driven Solutions
by Mahesh Chand and David Talbot ISBN:1590590732
The Microsoft .NET Framework
Apress provides
2003 (928 pages) a rich set of server-side controls for developing Web
applications. YouThis
cantext
addprovides
these controls to Web
extensive Forms
coverage pages just
of ADO.NET as you add Windows controls to a
technology
form. Server-sideincluding
controls ADO.NET
are ofteninternals,
called servercontrols or Web Forms
namespaces, classes, and controls. There are four types of
interfaces,
server controls: HTML and
server takes a Web
controls, comprehensive look atvalidation
server controls, XML controls, and user controls.
namespaces and classes, and how to integrate both with
ADO.NET.
HTML Server Controls
Table
HTML of developers
Contents will be familiar with old HTML controls, which they use to write GUI applications in
Applied
HTML.ADO.NETBuilding Data-Driven
These controls are Solutions
the same HTML controls; you can run these controls on the server by defining
therunat="Server" attribute. Note that if you do not set this attribute, the HTML control acts as a
Introduction
normal1HTML
Chapter control.Basics
- ADO.NET You may prefer this in some situations, as the HTML controls work without requiring
a round-trip
Chapter to theComponents
2 - Data server. These control
in Visual names
Studio start with Html.Table 14-1 defines some of these
.NET
controls.
Chapter 3 - ADO.NET in Disconnected Environments
Chapter 4 - ADO.NET in Connected Environments
Table 14-1:
Chapter HTML Server
5 - Handling Controls
ADO.NET Events
Chapter 6 - Integrating XML with ADO.NET
CONTROL DESCRIPTION
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
HtmlForm
Chapter Creates an HTML form control, used as a placeholder of other
8 - Constraints and Data Relations
Chapter 9 controls
- ADO.NET Exception Handling
Chapter 10 - Working with the ODBC
HtmlInputText .NET Data
Creates Provider
an input TextBox control used to get input from user
Chapter 11 - Stored Procedures and Views
HtmltextArea Creates a multiline TextBox control
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Chapter 13 - Developing a Custom Data
HtmlAnchor Provider
Creates Web navigation
Chapter 14 - Developing Database Web Applications using ASP.NET
HtmlButton Creates a Button control
Chapter 15 - Using ADO.NET in Xml Web Services
Chapter 16 - ASP.NET Server Controls
HtmlImage and Data
Creates Bindingcontrol that is used to display an image
an Image
Chapter 17 - Building Real-World Web Applications
HtmlInputCheckBox Creates a CheckBox control
Chapter 18 - Object-Relational Mapping in .NET
Chapter Creates Considerations
19 - Mapped Objects: Performance
HtmlInputRadioButton a RadioButton andcontrol
Data Binding
Chapter 20 - COM Interoperability and ADO.NET
HtmlTable Creates a Table control
Chapter 21 - Messaging
HtmlTableRow
Chapter Creates
22 - SQL Server and ADO.NET: a row
Notes within a table
on Performance
Appendix A - Relational Databases: Some Basic Concepts
HtmlTableCell Creates a cell within a row
Appendix B - Commonly Used SQL Statements
Appendix C - ADO.NET Frequently Asked Questions
Web server controls are more powerful than HTML controls because they provide more functionality and
Index
are easier to use. Besides some of the basic controls such as Button,TextBox,Label, and
List of Figures ASP.NET provides some more powerful controls such as DataGrid, DataList, and
CheckBox,
List of Tables You'll use these controls throughout this chapter. Table 14-2 describes some of these
Calendar.
List of Listings
controls.
List of Sidebars
Table 14-2: Web Server Controls
CONTROL DESCRIPTION
Applied ADO.NET: Building Data-Driven Solutions
by Mahesh Chand and David Talbot ISBN:1590590732
Label Represents a label
Apress 2003 (928 pages)
ListBox This text Represents a list box
provides extensive coverage of ADO.NET technology
including ADO.NET internals, namespaces, classes, and
CheckBox Represents
interfaces, and takes aacomprehensive
check box look at XML
namespaces and classes, and how to integrate both with
Calender ADO.NET.Represents a calendar
This line creates a TextBox server control. Every control has a unique ID. In this sample the ID is
TextBox1. The runat="Server" attribute represents that the control will run on the server.
Applied ADO.NET: Building Data-Driven Solutions
by shows
The following code Maheshyou
Chand
canand David
write Talbot code without
the same the closing tag:
ISBN:1590590732
Apress 2003 (928 pages)
<asp:textbox This text provides extensive
id=Textbox1 coverage of />
runat="Server" ADO.NET technology
including ADO.NET internals, namespaces, classes, and
interfaces, and takes a comprehensive look at XML
namespaces and classes, and how to integrate both with
OK, now let's getADO.NET.
back to the first sample. Remember, you created your first application and added a
TextBox, a Button, and a ListBox control to the Web page. Listing 14-2 shows the ASP.NET version
of your first ASP.NET application (from Figure 14-12). You can see the ASP.NET version by using the
Table
HTML of mode
Contents
of the designer.
Applied ADO.NETBuilding Data-Driven Solutions
Listing 14-2: ASP.NET Version of Your First ASP.NET Application
Introduction
Chapter 1 - ADO.NET Basics
Chapter 2 - Data
<%@ Page Components in AutoEventWireup="false"
Language="vb" Visual Studio .NET Codebehind="WebForm1.aspx.vb"
Chapter 3 - ADO.NET in Disconnected Environments
Inherits="FirstWebApplication.WebForm1"%>
<!DOCTYPE
Chapter HTML PUBLIC
4 - ADO.NET "-//W3C//DTD
in Connected Environments HTML 4.0 Transitional//EN">
<HTML>
Chapter 5 - Handling ADO.NET Events
<HEAD>
Chapter 6 - Integrating XML with ADO.NET
<title>First
Chapter ASP.NET
7 - Data Binding Web Application</title>
and Windows Forms Data-Bound Controls
<meta8 name="GENERATOR"
Chapter - Constraints and Datacontent="Microsoft
Relations Visual Studio.NET 7.0">
<meta name="CODE_LANGUAGE"
Chapter 9 - ADO.NET Exception Handling
content="Visual Basic 7.0">
<meta name="vs_defaultClientScript" content="JavaScript">
Chapter 10 - Working with the ODBC .NET Data Provider
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/
Chapter 11 - Stored Procedures and Views
intellisense/ie5">
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
</HEAD>
Chapter 13 - Developing a Custom Data Provider
<body>
Chapter
<form14id="Form1"
- Developing Database Web Applications
method="post" using ASP.NET
runat="server">
Chapter
<P> 15 - Using ADO.NET in Xml Web Services
Chapter 16 - ASP.NET
<asp:TextBox Server Controls and
id="TextBox1" Data Binding
style="Z-INDEX: 101; LEFT: 16px;
Chapter 17 - Building Real-World Web Applications
POSITION: absolute; TOP: 80px" runat="server"></asp:TextBox>
Chapter 18 - Object-Relational
<asp:Button id="Button1" Mapping in .NET
style="Z-INDEX: 102; LEFT: 188px;
Chapter
POSITION:19 - Mapped Objects:TOP:
absolute; Performance
79px"Considerations
runat="server"and DataText="Add"
Binding
Width="106px"
Chapter Height="27px"
20 - COM Interoperability Font-Names="Verdana"
and ADO.NET
ForeColor="Yellow"
Chapter 21 - Messaging BackColor="#0000C0"></asp:Button>
<asp:ListBox
Chapter id="ListBox1"
22 - SQL Server and ADO.NET: style="Z-INDEX:
Notes on Performance 103; LEFT:
14px; APOSITION:
Appendix absolute;
- Relational Databases: TOP:
Some 121px"
Basic Conceptsrunat="server"
Width="284px" Height="170px"></asp:ListBox><FONT
Appendix B - Commonly Used SQL Statements face="Verdana"
size="4">My First ASP.NET Web
Appendix C - ADO.NET Frequently Asked Questions
Application</FONT></P>
<P><FONT face="Verdana" size="2">Click Add button to add TextBox
Index
contents to ListBox</FONT></P>
List of Figures
<P><FONT face="Verdana" size="2"></FONT> </P>
List of Tables
</form>
List of Listings
</body>
List of Sidebars
</HTML>
As you saw in Listing 14-2,asp:Button,asp:TextBox, and asp:ListBox are three server controls
added using ASP.NET. In Listing 14-2, you probably noticed some unfamiliar keywords such as <%@Page,
Language, and codebehind. The <%@Page Language is a page directive, which defines the language
you're using in the page. You can use any .NET-supported language such as C# or VB .NET. The
Codebehind directive separates code from the ASP.NET page. You can define a C# or VB .NET page as
Codebehind, which hosts the code for ASP.NET controls for the page. As you can see from Listing 14-2,
theWebForm1.aspx.vb file is a VB class, which hosts code for WebForm1 page.
Understanding
AppliedData Binding
ADO.NET: Buildingin ASP.NET
Data-Driven Solutions
by Mahesh Chand and David Talbot ISBN:1590590732
Web Forms provide many
Apress controls
2003 that support data binding. You can connect these controls to ADO.NET
(928 pages)
components suchThis as a DataView, a DataSet,
text provides extensive or a DataViewManager
coverage of ADO.NET technology at design-time as well as at runtime.
Data binding in Web Forms works in the same way as it does
including ADO.NET internals, namespaces, classes, and in the Windows Forms with a few exceptions. For
example, to bind interfaces,
a DataSet andto takes a comprehensive
a DataGrid, you call look at XML
the DataBind method of the DataGrid control. We
discuss all this in namespaces and classes,
a moment. First let's seeand howbasics
some to integrate both withcontrols.
of data-bound
ADO.NET.
The following sections discuss data binding and how it works in ASP.NET.
Table of Contents
Data-Bound Controls
Applied ADO.NETBuilding Data-Driven Solutions
Introduction
ASP.NET
Chapter 1 -provides
ADO.NET a Basics
rich set of data-bound server-side controls. These controls are easy to use and provide a
Rapid Application
Chapter 2
Development (RAD) Web development. You can categorize these controls in two groups:
- Data Components in Visual Studio .NET
single-item data-bound controls and multi-item data-bound controls.
Chapter 3 - ADO.NET in Disconnected Environments
Chapter
You use4 the
- ADO.NET in Connected
single-item Environments
data-bound controls to display the value of a single item of a database table. These
Chapter 5 - Handling ADO.NET Events
controls don't provide direct binding with the data source. The highlighted part of Figure 14-14 shows an item
Chapter 6 - Integrating
of a database XML
table. You usewith
theADO.NET
Text,Caption, or Value property of these controls to show the data of a
Chapter
field. 7 - Data Binding and Windows Forms Data-Bound Controls
Chapter 8 - Constraints and Data Relations
Chapter 9 - ADO.NET Exception Handling
Chapter 10 - Working with the ODBC .NET Data Provider
Chapter 11 - Stored Procedures and Views
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Chapter 13 - Developing a Custom Data Provider
Chapter 14 - Developing Database Web Applications using ASP.NET
Figure 14-14: An item
Chapter 15 - Using ADO.NET in Xml Web Services
Chapter 16 -ofASP.NET
Examples Server
single-item Controls and
data-bound Data Binding
controls are a TextBox,Button,Label,Image, and so on.
Chapter 17 - Building Real-World Web Applications
You use
Chapter 18the multi-item data-bound
- Object-Relational controls
Mapping in .NETto display the entire table or a partial table. These controls provide
direct binding
Chapter to the Objects:
19 - Mapped data source. You useConsiderations
Performance the DataSource property
and Data of these controls to bind a database
Binding
table to20
Chapter these controls
- COM (see Figure
Interoperability and14-15).
ADO.NET
Chapter 21 - Messaging
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Appendix A - Relational Databases: Some Basic Concepts
Appendix B - Commonly Used SQL Statements
Appendix C - ADO.NET Frequently Asked Questions
Index
List of Figures
Figure 14-15: Multi-item controls
List of Tables
List
Someof Listings
examples of multi-item data-bound controls are DataGrid, ListBox, DataList, DropDownList, and so on.
List of Sidebars
Figure 14-16 shows some of the data-bound controls.
Applied ADO.NET: Building Data-Driven Solutions
by Mahesh Chand and David Talbot ISBN:1590590732
Apress 2003 (928 pages)
This text provides extensive coverage of ADO.NET technology
including ADO.NET internals, namespaces, classes, and
interfaces, and takes a comprehensive look at XML
namespaces and classes, and how to integrate both with
ADO.NET.
Table of Contents
Applied ADO.NETBuilding
Figure Data-Driven
14-16: Data-bound Solutions
controls
Introduction
Chapter 1 - ADO.NET Basics
In ASP.NET, you create these controls using an <asp:controlName> tag. Table 14-4 describes some
Chapter 2 - Data Components in Visual Studio .NET
common data-bound server-side controls.
Chapter 3 - ADO.NET in Disconnected Environments
Chapter 4 - ADO.NET in Connected Environments
Table 14-4: ASP.NET Data-Bound Controls
Chapter 5 - Handling ADO.NET Events
CONTROL
Chapter 6 - IntegratingASP.NET CODE
XML with ADO.NET DESCRIPTION
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
DataGrid <asp:DataGrid> This control displays a database (through ADO.NET)
Chapter 8 - Constraints and Data Relations
in a scrollable grid format and supports selection,
Chapter 9 - ADO.NET Exception Handling adding, updating, sorting, and paging.
Chapter 10 - Working with the ODBC .NET Data Provider
DataList
Chapter <asp:DataList>
11 - Stored Procedures and Views This control displays data in templates and style
format.
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Chapter 13 - Developing<asp:ListBox>
ListBox a Custom Data Provider This control can be associated to ADO.NET data
Chapter 14 - Developing Database Web Applications using
fieldsASP.NET
to display data in a list format.
Chapter 15 - Using ADO.NET in Xml Web Services
DropDownList <asp:DropDownList> This control displays ADO.NET data source data in a
Chapter 16 - ASP.NET Server Controls and Data Binding
drop-down combo box format.
Chapter 17 - Building Real-World Web Applications
CheckBox
Chapter <asp:CheckBox>
18 - Object-Relational Mapping in .NET This can be connected to an item of the ADO.NET
data source.
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
Chapter 20 - COM Interoperability and ADO.NET
CheckBoxList <asp:CheckBoxList> This control can be connected to the ADO.NET data
Chapter 21 - Messaging
source.
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Repeater
Appendix A - Relational <asp:Repeater> A templated data-bound list.
Databases: Some Basic Concepts
Appendix
TextBoxB - Commonly<asp:TextBox>
Used SQL Statements This control displays ADO.NET using its Text
Appendix C - ADO.NET Frequently Asked Questions property.
Index
List of Figures
List of Tables
DataGrid and DataList Controls
List of Listings
List of Sidebarscontrol is one of the most powerful Web controls. By using just a DataGrid control, you can
ADataGrid
write full-fledged Web applications for your Web site. In this section, you'll learn all about the DataGrid
methods and properties. The following examples are heavily based on this control.
You can use a DataGrid control to display tabular data. It also provides the ability to insert, update, sort, and
scroll the data. Using and binding a DataGrid control is easy with the help of the ADO.NET DataSets. This
grid is capable of auto-generating the columns and rows depending on which data you're connecting.
Another control worth mentioning is the DataList control. A DataList control provides a list view of the
data from a data source. These controls work similarly.
DataGrid and DataList controls have similar properties. Table 14-5 describes some of the common
DataGrid properties.
Table 14-5: DataGrid
AppliedControl Properties
ADO.NET: Building Data-Driven Solutions
by Mahesh Chand and David Talbot ISBN:1590590732
PROPERTY DESCRIPTION
Apress 2003 (928 pages)
AllowPaging,This text provides extensive
Booleancoverage
valuesof ADO.NET
indicate technology
whether paging or custom paging are
including ADO.NET internals,
AllowCustomPaging namespaces,
allowed in the grid. classes, and
interfaces, and takes a comprehensive look at XML
SYNTAX
namespaces and classes, AllowPaging="true"
and how to integrate both with
ADO.NET.
AllowSorting Boolean value indicates whether sorting is allowed in the grid.
SYNTAX AllowSorting="true"
Table of Contents
AutoGenerateColumns
Applied Gets or sets a value that indicates whether columns will
ADO.NETBuilding Data-Driven Solutions
Introduction automatically be created for each bound data field.
Chapter 1 - ADO.NET Basics SYNTAX AutoGenerateColumns="true"
Chapter 2 - Data Components in Visual Studio .NET
BackColor,ForeColor,Font Sets the background, foreground color, and font of the grid
Chapter 3 - ADO.NET in Disconnected Environments
control.
Chapter 4 - ADO.NET in Connected Environments
Chapter 5 - Handling ADO.NET Events SYNTAX BorderColor="black"; ForeColor="green";
Chapter 6
Font-Name="Verdana";Font-Size="10pt"
- Integrating XML with ADO.NET
Chapter 7 - Data Binding and Windows Forms
BackImageUrl Gets orData-Bound Controls
sets the URL of an image to display in the background of
Chapter 8 - Constraints and Data Relations
theDataGrid.
Chapter 9 - ADO.NET Exception Handling
BorderColor,BorderStyle, Sets the border properties of the control.
Chapter 10 - Working with the ODBC .NET Data Provider
BorderWidth SYNTAX BorderColor="black";BorderWidth="1"
Chapter 11 - Stored Procedures and Views
Chapter 12 - Oracle,
CellPadding, SQLXML, and Other Sets
CellSpacing .NETthe
Data Providers
cell spacing and padding.
Chapter 13 - Developing a Custom Data Provider
SYNTAX CellPadding="10";CellSpacing="5"
Chapter 14 - Developing Database Web Applications using ASP.NET
15 - Using ADO.NET in Xml WebGets
Columns
Chapter a collection of column controls in the DataGrid.
Services
Chapter 16 - ASP.NET Server Controls and Data Binding
CurrentPageIndex Index of the currently displayed page.
Chapter 17 - Building Real-World Web Applications
DataKeyField
Chapter Primary
18 - Object-Relational Mapping in .NET key field in the data source.
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
DataSource Fills the grid with the data.
Chapter 20 - COM Interoperability and ADO.NET
SYNTAX DataGrid1.DataSource =
Chapter 21 - Messaging
ds.Tables["Student"].DefaultView;
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Appendix A - Relational Databases: SomeIndex
EditItemIndex Basic of
Concepts
the item to be edited.
Appendix B - Commonly Used SQL Statements
EditItemStyle Style of the item to be edited.
Appendix C - ADO.NET Frequently Asked Questions
HeaderStyle,FooterStyle
Index Header and footer styles.
List of Figures SYNTAX HeaderStyle-BackColor="#00aaaa";
List of Tables FooterStyle-BackColor="#00aaaa"
List of Listings
GridLines
List of Sidebars
Gets or sets the grid line style.
SYNTAX GridLines="Vertical"
Height,Width Width and height of the control.
ID ID of the control.
Page Returns the Page object that contains the current control.
SYNTAX Page.DataBind();
PageCount,PageSize Returns the total number of pages and number of items in a
page to be displayed.
SYNTAX NumPages = ItemsGrid.PageCount;Items=
ItemsGrid.PageCount
SelectedIndex Index ofData-Driven
Applied ADO.NET: Building the currently Solutions
selected item.
SelectedItemby Mahesh Chand andReturns
David Talbot ISBN:1590590732
the selected item in the DataGrid.
Apress 2003 (928 pages)
ShowFooter,ShowHeader Showscoverage
This text provides extensive header and footers. technology
of ADO.NET
including ADO.NET internals,
SYNTAX namespaces, classes, and
ShowFooter="true";; ShowHeader="true";
interfaces, and takes a comprehensive look at XML
UniqueID namespaces and classes, and how
Returns the to integrate
unique both
ID for with
a control.
ADO.NET.
VirtualItemCount Total number of items on the page when AllowCustomPaging
is true.
Table of Contents
Applied ADO.NETBuilding Data-Driven Solutions
Introduction
Setting DataGrid Control Properties at Design-Time
Chapter 1 - ADO.NET Basics
In VS .NET,
Chapter you can
2 - Data set the DataGrid
Components control's
in Visual Studio properties at design-time by right-clicking the control and
.NET
selecting
Chapter 3 the Properties
- ADO.NET menu item. This
in Disconnected displays the Properties window (see Figure 14-17).
Environments
Chapter 4 - ADO.NET in Connected Environments
Chapter 5 - Handling ADO.NET Events
Chapter 6 - Integrating XML with ADO.NET
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
Chapter 8 - Constraints and Data Relations
Chapter 9 - ADO.NET Exception Handling
Chapter 10 - Working with the ODBC .NET Data Provider
Chapter 11 - Stored Procedures and Views
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Chapter 13 - Developing a Custom Data Provider
Chapter 14 - Developing Database Web Applications using ASP.NET
Chapter 15 - Using ADO.NET in Xml Web Services
Chapter 16 - ASP.NET Server Controls and Data Binding
Chapter 17 - Building Real-World Web Applications
Chapter 18 - Object-Relational Mapping in .NET
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
Chapter 20 - COM Interoperability and ADO.NET
Chapter 21 - Messaging
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Appendix A - Relational Databases: Some Basic Concepts
Appendix B - Commonly Used SQL Statements
Appendix C - ADO.NET Frequently Asked Questions
Index
List of Figures
List of Tables
List of Listings
List of Sidebars
Most of these properties should look familiar to you by now. You can set the DataSource property to a
DataView,DataSet,DataViewManager, or a DataReader. The DataMember property represents a
column of a data table if you want to display only one column in the control.
AutoFormat
Besides the general properties of a DataGrid, in Figure 14-17, you see two links: Auto Format and Property
Builder. The Auto Format option provides you with predefined formats for rows, columns, headers, footers,
and so on (see Figure 14-18).
Applied ADO.NET: Building Data-Driven Solutions
by Mahesh Chand and David Talbot ISBN:1590590732
Apress 2003 (928 pages)
This text provides extensive coverage of ADO.NET technology
including ADO.NET internals, namespaces, classes, and
interfaces, and takes a comprehensive look at XML
namespaces and classes, and how to integrate both with
ADO.NET.
Table of Contents
Applied ADO.NETBuilding Data-Driven Solutions
Introduction
Chapter 1 - ADO.NET Basics
Chapter 2 - Data Components in Visual Studio .NET
Figure
Chapter 3 - 14-18:
ADO.NETDataGrid's AutoEnvironments
in Disconnected Format dialog box
Chapter 4 - ADO.NET in Connected Environments
Chapter 5
Property- Handling
BuilderADO.NET Events
Chapter 6 - Integrating XML with ADO.NET
The Property
Chapter Builder
7 - Data option
Binding and launches the Properties
Windows Forms dialog
Data-Bound box. Before setting the DataGrid properties, let's
Controls
do one8thing.
Chapter Drag a SqlDataAdapter
- Constraints and Data Relations from the Toolbox's Data tab to the Web page, which launches the
DataAdapter
Chapter Configuration
9 - ADO.NET Wizard.
Exception Follow the steps and build a SQL query using SQL Query tool. Select
Handling
EmployeeID,
Chapter LastName,
10 - Working FirstName,
with the andData
ODBC .NET TitleProvider
from Employees table.
Chapter 11 - Stored Procedures and Views
After completing this step, generate a DataSet from the DataAdapter. You can right-click and select the
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Generate DataSet option to generate a DataSet from a DataAdapter. The Generate DataSet option asks
Chapter 13 - Developing a Custom Data Provider
you to use an existing DataSet or create a new DataSet.
Chapter 14 - Developing Database Web Applications using ASP.NET
This action
Chapter 15 - asks
Usingthe
ADO.NET name
in Xml
DataSet Weband adds the DataSet11 DataSet object with a DataSet1 class
Services
derived16
Chapter from DataSet
- ASP.NET and Controls
Server DataSet1.xsd XML schema to the project.
and Data Binding
Chapter 17 - Building Real-World Web Applications
Next, drop a DataView on the page and set DataSet11.Employees as its Table property. All these steps
Chapter 18 - Object-Relational Mapping in .NET
are explained in Chapter 2. Now you're all set to use the DataGrid Property Builder.
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
Chapter 20property
The first - COM Interoperability andThis
page is General. ADO.NET
page lets you set a DataSource name at design-time. All available
Chapter 21 -DataView,
DataSet, Messaging and other data-bindable objects are available in the drop-down combo list. In this case,
Chapter
we have22DataSet11
- SQL Serverand
andDataView1.
ADO.NET: Notes
Youoncan
Performance
also set the DataMember and DataKeyField properties
Appendix A - Relational Databases: Some Basic Concepts
from this page. In this case, select DataSet11 as the DataSource option, Employees as the DataMember
option (the
Appendix B - only available
Commonly Usedoption; if you have multiple tables in a DataSet, you'll have all tables listed here),
SQL Statements
and EmployeeID
Appendix as the
C - ADO.NET Data Key
Frequently FieldQuestions
Asked option. If you want to add headers and footers to the DataGrid
control, you can set them by checking the Show Header and Show Footer check boxes on this page. The
Index
Allow
List Sorting check box enables sorting in a DataGrid control. Check all of these options as shown in Figure
of Figures
14-19.
List of Tables
List of Listings
List of Sidebars
Applied ADO.NET: Building Data-Driven Solutions
by Mahesh Chand and David Talbot ISBN:1590590732
Apress 2003 (928 pages)
This text provides extensive coverage of ADO.NET technology
including ADO.NET internals, namespaces, classes, and
interfaces, and takes a comprehensive look at XML
namespaces and classes, and how to integrate both with
ADO.NET.
Table of Contents
Applied ADO.NETBuilding Data-Driven Solutions
Introduction
Chapter 1 - ADO.NET Basics
Chapter 2 - Data Components in Visual Studio .NET
Chapter 3 - ADO.NET in Disconnected Environments
Chapter 4 - ADO.NET in Connected Environments
Chapter 5 - Handling ADO.NET Events
Figure
Chapter 6 - 14-19: DataGrid
Integrating general
XML with properties
ADO.NET
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
Chapter 8
- Constraints and Data Relations
Columns Property Page
Chapter 9 - ADO.NET Exception Handling
Chapter 10 - aWorking
By default, with the
DataGrid ODBC
control .NET
adds Data Provider
columns at runtime depending upon the DataSource property of the
Chapter
grid. By11 - Stored
using Procedures
the Columns and Views
property page, you can add DataGrid columns at design-time by unchecking the
Chapter
Create 12 - Oracle,
Columns SQLXML, andatOther
Automatically Run .NET
TimeData Providers
check box (as shown in Figure 14-20). We also added four
columns
Chapter 13to- the Selected
Developing Columns
a Custom list:Provider
Data ID, LastName, FirstName, and Title. This page also lets you change the
header14
Chapter text- Developing
and footer text. Not only
Database Webthat, you canusing
Applications also define
ASP.NETwhether a column is read-only. The Header
Image option
Chapter allows
15 - Using you to in
ADO.NET setXml
theWeb
image of a DataGrid header. We selected an image for the column
Services
headers.
Chapter 16 - ASP.NET Server Controls and Data Binding
Chapter 17 - Building Real-World Web Applications
Chapter 18 - Object-Relational Mapping in .NET
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
Chapter 20 - COM Interoperability and ADO.NET
Chapter 21 - Messaging
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Appendix A - Relational Databases: Some Basic Concepts
Appendix B - Commonly Used SQL Statements
Appendix C - ADO.NET Frequently Asked Questions
Index
List of Figures
List of Tables
List of Listings
List of Sidebars
Note If you set the Header image option to some image, the header title will display as the image, not the
text.
If you scroll down your Available Columns list, you can even add DataGrid columns as a button, a hyperlink,
or a template column.
Applied
Paging Property ADO.NET: Building Data-Driven Solutions
Page
by Mahesh Chand and David Talbot ISBN:1590590732
The Paging pageApress
enables the (928
2003 paging feature in the grid control. The Paging page allows you to set the
pages)
number of records pertext
This page in a DataGrid
provides control. For
extensive coverage example,technology
of ADO.NET if DataGrid grid control has 50 records
including
and you set the Page SizeADO.NET
as 5, theinternals,
DataGrid namespaces, classes,
will show all and in 10 pages. The Paging page also
50 records
interfaces,
allows you to navigate to theand
firsttakes a comprehensive
page, look atpage,
next page, previous XML last page, and even to a particular page
namespaces and classes, and how to integrate both with
number. By usingADO.NET.
the Paging property page, you can set the number of pages viewed in a grid and the mode
of navigation for navigating pages. In other words, you can either have previous and next options or have the
number of pages option. As you can see from Figure 14-21, we check the Allow Paging check box and set the
Table
PageofSize
Contents
as 5 rows. We also set the page navigation buttons to include Next and Previous buttons and
changeADO.NETBuilding
Applied the text of buttons. Data-Driven Solutions
Introduction
Chapter 1 - ADO.NET Basics
Chapter 2 - Data Components in Visual Studio .NET
Chapter 3 - ADO.NET in Disconnected Environments
Chapter 4 - ADO.NET in Connected Environments
Chapter 5 - Handling ADO.NET Events
Chapter 6 - Integrating XML with ADO.NET
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
Chapter 8 - Constraints and Data Relations
Chapter 9 - ADO.NET Exception Handling
Chapter 10 - Working with the ODBC .NET Data Provider
Chapter 11 - Stored Procedures and Views
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Chapter 13 - Developing a Custom Data Provider
Chapter 14 - Developing Database Web Applications using ASP.NET
Chapter 15 - Using ADO.NET in Xml Web Services
Chapter 16 - 14-21:
Figure ASP.NET Server Controls
DataGrid Pagingand Data Binding
properties page
Chapter 17 - Building Real-World Web Applications
Chapter 18 - Object-Relational Mapping in .NET
Format
Chapter 19 -Property PagePerformance Considerations and Data Binding
Mapped Objects:
Chapter 20 - COM Interoperability and ADO.NET
If you don't want to use the Auto Format option, you can use the Format page. This page enables you to set
Chapter 21 - Messaging
the color and font of a DataGrid control. In fact, this page allows you control over every part of a DataGrid.
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
You can set colors, fonts, style of the DataGrid, as well as its header and footers, page navigators, individual
Appendix A - Relational Databases: Some Basic Concepts
columns, and even column headers and footers (see Figure 14-22).
Appendix B - Commonly Used SQL Statements
Appendix C - ADO.NET Frequently Asked Questions
Index
List of Figures
List of Tables
List of Listings
List of Sidebars
Table of Contents
Applied ADO.NETBuilding Data-Driven Solutions
Introduction
Chapter 1 - ADO.NET Basics
Chapter 2 - Data Components in Visual Studio .NET
Chapter 3 - ADO.NET in Disconnected Environments
Chapter 4 - ADO.NET in Connected Environments
Chapter 5 - Handling ADO.NET Events
Chapter 6 - Integrating XML with ADO.NET
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
Chapter 8 - Constraints and Data Relations
Chapter 9 - ADO.NET Exception Handling
Chapter 10 - 14-23:
Figure WorkingDataGrid
with the ODBC .NET
Border Data Provider
properties page
Chapter 11 - Stored Procedures and Views
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
The final
Chapter 13DataGrid control
- Developing looks like
a Custom DataFigure 14-24.
Provider
Chapter 14 - Developing Database Web Applications using ASP.NET
Chapter 15 - Using ADO.NET in Xml Web Services
Chapter 16 - ASP.NET Server Controls and Data Binding
Chapter 17 - Building Real-World Web Applications
Chapter 18 - Object-Relational Mapping in .NET
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
Chapter 20 - COM Interoperability and ADO.NET
Chapter 21 - Messaging
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Appendix A - Relational Databases: Some Basic Concepts
Figure
Appendix B - 14-24: TheUsed
Commonly final SQL
DataGrid after setting various properties
Statements
Appendix C - ADO.NET Frequently Asked Questions
Index
Filling a DataSet
List of Figures
List of Tables
You're almost there. Now the only thing you need to do is to call the DataAdapter'sFill method and fill the
List of Listings
DataSet, and you're all set. Call the sqlDataAdapter1.Fill method with DataSet11 as the only
argument
List on the Page_Load event and then call the DataGrid1.DataBind or Page.DataBind method to
of Sidebars
bind the DataGrid with the data. Listing 14-3 shows how do to this.
Table of Contents
Applied ADO.NETBuilding Data-Driven Solutions
Introduction
Chapter 1 - ADO.NET Basics
Chapter 2 - Data Components in Visual Studio .NET
Chapter 3 - ADO.NET in Disconnected Environments
Chapter 4 - ADO.NET in Connected Environments
Chapter 5 - Handling ADO.NET Events
Figure 14-25: Viewing data in a DataGrid using the design-time data binding method
Chapter 6 - Integrating XML with ADO.NET
Chapter
As you 7can- Data Binding
see from thisand Windows
sample, Forms only
by writing Data-Bound Controls
two lines of code, you've developed a database application.
Chapter 8 -the
Don't click Constraints
Next Page and Data
link justRelations
yetit won't work right now. You need to add few lines of code for that.
Chapter 9 - ADO.NET Exception Handling
Chapter 10 - Working with the ODBC .NET Data Provider
Paging in the DataGrid Control
Chapter 11 - Stored Procedures and Views
Chapter 12 - Oracle,
As discussed earlierSQLXML, and Other
in the "Paging .NET Data
Property Providers
Page" section (Figure 14-24), using the Paging page of the
Property
Chapter 13Builder for a DataGrid
- Developing a Customcontrolyou can set paging options of a DataGrid at design-time as well as at
Data Provider
runtime.
Chapter 14 - Developing Database Web Applications using ASP.NET
Chapter 15 - Using ADO.NET in Xml Web Services
After enabling paging in a DataGrid, there's one more small addition you need to do to make the paging
Chapter 16 - ASP.NET Server Controls and Data Binding
work. You need to write the PageIndexChanged event handler, which allows you to jump to a specific page
Chapter 17 - Building Real-World Web Applications
by the page index. The easiest way to write a PageIndexChanged event handler is to set a method to the
Chapter 18 - Object-Relational Mapping in .NET
OnPageIndexChanged value, which you can do in the ASP.NET page itself. Add the bold part of the
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
following line to <asp:DataGrid>
Chapter 20 - COM Interoperability and ADO.NET
Chapter 21 - Messaging
<asp:DataGrid id="DataGrid1" OnPageIndexChanged="Grid_Change" ..... >
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Appendix A - Relational Databases: Some Basic Concepts
Appendix B -the
Now write Commonly Used SQL
Grid_Change Statements
method as shown in Listing 14-4. As you can see, we set
Appendix C - ADO.NET Frequently Asked
DataGrid.CurrentPageIndex as Questions
DataGridPageChangedEventArgs'sNewPageIndex and call the
DataGrid1.DataBind method.
Index
List of Figures
Listing
List 14-4: The PageIndexChanged Handler of the DataGrid Control
of Tables
List of Listings
List
Sub of Sidebars
Grid_Change(ByVal sender As Object, _
ByVal e As DataGridPageChangedEventArgs)
DataGrid1.CurrentPageIndex = e.NewPageIndex
DataGrid1.DataBind()
End Sub
Now, if you run the application, you'll find paging working for you. The first page of looks like Figure 14-26, and
if you click the Next Page link, DataGrid loads the data, which after the first five records looks like Figure 14-
26.
Applied ADO.NET: Building Data-Driven Solutions
by Mahesh Chand and David Talbot ISBN:1590590732
Apress 2003 (928 pages)
This text provides extensive coverage of ADO.NET technology
including ADO.NET internals, namespaces, classes, and
interfaces, and takes a comprehensive look at XML
namespaces and classes, and how to integrate both with
ADO.NET.
Table of Contents
Applied ADO.NETBuilding Data-Driven Solutions
Introduction
Figure
Chapter 1 - 14-26:
ADO.NETPaging
Basicsoption in a DataGrid
Chapter 2 - Data Components in Visual Studio .NET
Now if you click the Previous Page link, the DataGrid loads the old data again.
Chapter 3 - ADO.NET in Disconnected Environments
Chapter 4 - ADO.NET in Connected Environments
Enabling
Chapter 5 Paging
- Handling Programmatically
ADO.NET Events
Chapter 6 - Integrating XML with ADO.NET
You can also enable paging programmatically from your .aspx file. Listing 14-5 shows the HTML code for a
Chapter 7
DataGrid- control
Data Binding and Windows Forms Data-Bound Controls
and its properties.
Chapter 8 - Constraints and Data Relations
Chapter
Listing914-5:
- ADO.NET Exception
HTML View Handling
of asp:DataGrid
Chapter 10 - Working with the ODBC .NET Data Provider
Chapter 11 - Stored Procedures and Views
<asp:DataGrid id="DataGrid1" style="Z-INDEX: 101; LEFT: 204px;
Chapter 12 - Oracle,
POSITION: SQLXML, TOP:
absolute; and Other .NET Data
174px" Providers
runat="server" Width="279px"
Chapter 13 - Developing
Height="212px" a Custom Data Provider BorderWidth="1px"
BorderStyle="None"
Chapter 14 - Developing Database
BorderColor="#CC9966" Web Applications using ASP.NET
BackColor="White" CellPadding="4"
Chapter 15 - Using ADO.NET
PageSize="5" in Xml Web Services
AllowPaging="True">
Chapter 16 - ASP.NET
<FooterStyle Server Controls and Data Binding
ForeColor="#330099" BackColor="#FFFFCC"></FooterStyle>
Chapter 17 - Building
<HeaderStyle Real-World Web Applications
Font-Bold="True" ForeColor="#FFFFCC"
BackColor="#990000"></HeaderStyle>
Chapter 18 - Object-Relational Mapping in .NET
<PagerStyle
Chapter HorizontalAlign="Center"
19 - Mapped ForeColor="#330099"
Objects: Performance Considerations and Data Binding
BackColor="#FFFFCC"></PagerStyle>
Chapter 20 - COM Interoperability and ADO.NET
<SelectedItemStyle
Chapter 21 - Messaging Font-Bold="True" ForeColor="#663399"
BackColor="#FFCC66"></SelectedItemStyle>
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
<ItemStyle ForeColor="#330099" BackColor="White"></ItemStyle>
Appendix A - Relational Databases: Some Basic Concepts
</asp:DataGrid>
Appendix B - Commonly Used SQL Statements
Appendix C - ADO.NET Frequently Asked Questions
Index
List
The of General
Figures paging properties include AllowPaging and PageSize. Both are pretty self-explanatory. Basically,
List of Tables
AllowPaging enables paging, and PageSize sets the number of pages in a page. You can set these
List of Listings
properties programmatically, as shown in Listing 14-6.
List of Sidebars
Listing 14-6: Setting the AllowPaging,PageSize, and AllowSorting Properties
DataGrid1.AllowPaging = True
DataGrid1.PageSize = 5
DataGrid1.AllowSorting = True
Like in the Property Builder, you can choose to have either the numeric page mode or the previous/next page
mode. The numeric mode option shows you the number of pages to move to the previous or next pages (1, 2,
and so on), and the previous/next mode displays angle brackets (< and >) to move to the previous and next
pages.Listing 14-7 shows how to set the DataGrid control's page style modes to the Numeric and
NextPrev styles.Applied ADO.NET: Building Data-Driven Solutions
by Mahesh Chand and David Talbot ISBN:1590590732
Apress
Listing 14-7: Setting DataGrid's PageStyle Modes
2003 (928 pages)
This text provides extensive coverage of ADO.NET technology
including ADO.NET internals, namespaces, classes, and
DataGrid1.PagerStyle.Mode
interfaces, and takes=a PagerMode.NumericPages
comprehensive look at XML
DataGrid1.PagerStyle.Mode = PagerMode.NextPrev
namespaces and classes, and how to integrate both with
ADO.NET.
Table of Contents
You can even change the text of your previous/next mode from angle brackets to the text you want (see Listing
Applied ADO.NETBuilding Data-Driven Solutions
14-8).
Introduction
Listing114-8:
Chapter SettingBasics
- ADO.NET the DataGrid Control's PageStyle Text
Chapter 2 - Data Components in Visual Studio .NET
Chapter 3 - ADO.NET in Disconnected Environments
DataGrid1.PagerStyle.NextPageText = "Go to Next Page"
Chapter 4 - ADO.NET in Connected Environments= "Go to Previous Page"
DataGrid1.PagerStyle.PrevPageText
Chapter 5 - Handling ADO.NET Events
Chapter 6 - Integrating XML with ADO.NET
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
If you want
Chapter 8 - to use your and
Constraints own Data
images for the Next and Previous buttons, you can do that as well. Just use the
Relations
simple HTML <IMG> tag (see Listing
Chapter 9 - ADO.NET Exception Handling 14-9).
Chapter 10 - Working with the ODBC .NET Data Provider
Listing 14-9: Setting an Image as the DataGrid Control's Next and Previous Page Text
Chapter 11 - Stored Procedures and Views
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
DataGrid1.PagerStyle.NextPageText
Chapter 13 - Developing a Custom Data Provider = "<img srv=next.gif>"
DataGrid1.PagerStyle.PrevPageText
Chapter = using
14 - Developing Database Web Applications "<img srv=prev.gif>"
ASP.NET
Chapter 15 - Using ADO.NET in Xml Web Services
Chapter 16 - ASP.NET Server Controls and Data Binding
Chapter 17 - Building Real-World Web Applications
Adding, Editing, and Deleting Data in Web Forms
Chapter 18 - Object-Relational Mapping in .NET
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
You'll now
Chapter 20 -add
COMmore functionality
Interoperability to ADO.NET
and your application. In this application, you'll add options to add, delete, and
update21
Chapter data. There are two ways you can add these options. One way is to use SQL statements and execute
- Messaging
them with the help of SqlCommand, and other way is to do add, edit, and delete operations on a DataSet
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
through DataTable objects. In this sample, you'll use the SqlCommand option. In the next chapter, you'll see
Appendix A - Relational Databases: Some Basic Concepts
theDataSet option to add, edit, and delete data in a DataGrid control.
Appendix B - Commonly Used SQL Statements
Appendix C - ADO.NET Frequently Asked Questions
Adding Web Forms Controls
Index
List
To of Figuresadd, edit, and delete options, you add four TextBox, three Label, and three Button controls, as
provide
List of Tables
shown in Figure 14-27.
List of Listings
List of Sidebars
Applied ADO.NET: Building Data-Driven Solutions
by Mahesh Chand and David Talbot ISBN:1590590732
Apress 2003 (928 pages)
This text provides extensive coverage of ADO.NET technology
including ADO.NET internals, namespaces, classes, and
interfaces, and takes a comprehensive look at XML
namespaces and classes, and how to integrate both with
ADO.NET.
Table of Contents
Applied ADO.NETBuilding Data-Driven Solutions
Introduction
Chapter 1 - ADO.NET Basics
Chapter 2 - Data Components in Visual Studio .NET
Chapter 3 - 14-27:
Figure ADO.NET in Disconnected
Adding, Environments
editing, and deleting pages
Chapter 4 - ADO.NET in Connected Environments
Chapter 5 - Handling ADO.NET Events
The Add button
Chapter 6
click adds data entered in the text boxes to the database. The Delete button click deletes the
- Integrating XML with ADO.NET
data based on the ID entered in the ID text box. The Update button updates the data of a record in the
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
database based on the ID value.
Chapter 8 - Constraints and Data Relations
Chapter 9- ADO.NET Exception Handling
The FillDataGrid Method
Chapter 10 - Working with the ODBC .NET Data Provider
Before 11
Chapter writing any code
- Stored to add,
Procedures update,
and Views or delete data, let's write a method that will refresh the DataGrid
contents.
Chapter 12Listing 14-10
- Oracle, showsand
SQLXML, theOther
FillDataGrid method. As you can see from the code, this method just
.NET Data Providers
fills the13
Chapter DataSet from athe
- Developing DataAdapter
Custom and binds data to the DataGrid.
Data Provider
Chapter 14 - Developing Database Web Applications using ASP.NET
Listing 14-10: The FillDataGrid Method
Chapter 15 - Using ADO.NET in Xml Web Services
Chapter 16 - ASP.NET Server Controls and Data Binding
' Refresh
Chapter DataGrid
17 - Building Real-World Web Applications
Private
Chapter 18 -Sub FillDataGrid()
Object-Relational Mapping in .NET
ChapterSqlDataAdapter1.Fill(DataSet11)
19 - Mapped Objects: Performance Considerations and Data Binding
ChapterDataGrid1.DataBind()
20 - COM Interoperability and ADO.NET
End Sub
Chapter 21 - Messaging
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Appendix A - Relational Databases: Some Basic Concepts
Appendix B - Commonly Used SQL Statements
Executing SQL Queries
Appendix C - ADO.NET Frequently Asked Questions
Index
As discussed in Chapter 4, you can use the SqlCommand object's Execute and ExecuteNonQuery
List of Figures
methods to execute SQL queries. If you want to add, update, or delete data from a database, executing SQL
List of
queriesTables
is one of the easiest ways to do so. It's fast and requires a minimum of code to write.
List of Listings
You
List of use the SqlCommand object to execute a SQL command. The Execute and ExecuteNonQuery
Sidebars
methods of SqlCommand execute a SQL query. The SqlCommand.Execute method executes the
CommandText property and returns data in the SqlDataReader object. The
SqlCommand.ExecuteNonQuery method executes CommandText and doesn't return any data. The logical
time to use this method is when you're writing to the database or executing SQL statements that don't return
any data, which works in this case when you need to add, update, and delete data from a database.
In this example, we've used the SqlCommand.ExecuteNonQuery() method to execute the INSERT,
UPDATE, and DELETE SQL queries as obviously we don't need to return any data. This ExecuteSQL method
wraps the execution of a SQL query, as shown in Listing 14-11.
Table of Contents
Applied ADO.NETBuilding Data-Driven Solutions
Introduction
Chapter 1 - ADO.NET Basics
Chapter 2 - Data Components in Visual Studio .NET
Chapter 3 - 14-28:
Figure ADO.NET in Disconnected
Adding Environments
a new record in the Web application
Chapter 4 - ADO.NET in Connected Environments
Chapter 5 - Handling ADO.NET Events
Updating
Chapter 6 Data XML with ADO.NET
- Integrating
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
The Update
Chapter button updates
8 - Constraints a record
and Data corresponding to an ID. This is where you build an UPDATE...SET SQL
Relations
Chapter 9 - ADO.NET Exception HandlingExecuteSQL method, as shown in Listing 14-13.
statement and execute it by calling the
Chapter 10 - Working with the ODBC .NET Data Provider
Listing 14-13: Updating Data on the Update Button Click
Chapter 11 - Stored Procedures and Views
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Private
Chapter 13 -Sub UpdateBtn_Click(ByVal
Developing a Custom Data Provider sender As System.Object, _
ByVal14e -As
Chapter System.EventArgs)
Developing Handlesusing
Database Web Applications UpdateBtn.Click
ASP.NET
' Build a SQL Statement
Chapter 15 - Using ADO.NET in Xml Web Services
Dim SQL As String = _
Chapter 16 - ASP.NET Server Controls and Data Binding
"UPDATE Employees SET FirstName='" & _
Chapter 17 - Building Real-World Web Applications
TextBox2.Text + "',LastName='" + TextBox3.Text + _
Chapter 18 - Object-Relational Mapping in .NET
"',Title='" + TextBox4.Text & _ "' WHERE EmployeeID=" + TextBox1.Text
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
' Execute SQL and refresh the data grid
ChapterExecuteSQL(SQL)
20 - COM Interoperability and ADO.NET
ChapterFillDataGrid()
21 - Messaging
Chapter
End22Sub- SQL Server and ADO.NET: Notes on Performance
Appendix A - Relational Databases: Some Basic Concepts
Appendix B - Commonly Used SQL Statements
Appendix C - ADO.NET Frequently Asked Questions
Now to test the code, enter "Mel," "0Tel," and "Marketing Rep," in the First Name, Last Name, and Title text
Index
boxes
List (respectively) and ID = 26 and then click the Updated button. The result updates the row with ID=26,
of Figures
andofthe
List output looks like Figure 14-29. As you can see, that record is updated as Mel Tel.
Tables
List of Listings
List of Sidebars
Applied ADO.NET: Building Data-Driven Solutions
by Mahesh Chand and David Talbot ISBN:1590590732
Apress 2003 (928 pages)
This text provides extensive coverage of ADO.NET technology
including ADO.NET internals, namespaces, classes, and
interfaces, and takes a comprehensive look at XML
namespaces and classes, and how to integrate both with
ADO.NET.
Table of Contents
Applied ADO.NETBuilding Data-Driven Solutions
Introduction
Chapter 1 - ADO.NET Basics
Chapter 2 - Data Components in Visual Studio .NET
Chapter 3 - ADO.NET in Disconnected Environments
Figure- 14-29:
Chapter 4
Updating records in a Web application
ADO.NET in Connected Environments
Chapter 5 - Handling ADO.NET Events
Chapter 6 - Integrating XML with ADO.NET
Deleting
Chapter 7 Data
- Data Binding and Windows Forms Data-Bound Controls
Chapter 8
The Delete- button
Constraints and Data Relations
deletes a record corresponding with the ID from the database. You then build a DELETE
Chapter 9 - ADO.NET
SQL statement Exception
and execute Handling
it by calling the ExecuteSQL method, as shown in Listing 14-14.
Chapter 10 - Working with the ODBC .NET Data Provider
Chapter
Listing11 - Stored
14-14: Procedures
Deleting Data and Views
on the Delete Button Click
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Chapter
Private13 -Sub
Developing a Custom Data Provider sender As System.Object, _
DeleteBtn_Click(ByVal
Chapter 14 - Developing Database
ByVal e As System.EventArgs) Web Applications
Handlesusing ASP.NET
DeleteBtn.Click
Chapter 15 - Using
' Build a SQL ADO.NET in Xml Web Services
Statement
Chapter
Dim SQL16 -As
ASP.NET Server
String = Controls
"DELETE and* Data
FROMBinding
Employees WHERE EmployeeID= " + TextBox1.Text
Chapter 17 - Building Real-World Web Applications
' Execute SQL and refresh the data grid
Chapter 18 - Object-Relational Mapping in .NET
ExecuteSQL(SQL)
FillDataGrid()
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
End Sub
Chapter 20 - COM Interoperability and ADO.NET
Chapter 21 - Messaging
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Appendix A - Relational Databases: Some Basic Concepts
To delete the newly added record, just enter 26 in the ID field or the ID of the record you want to delete and
Appendix B - Commonly Used SQL Statements
click the Delete button.
Appendix C - ADO.NET Frequently Asked Questions
Index
By using these insert, update, and delete data operations, you can write a full-fledged database application for
List
yourof Web
Figures
site.
List of Tables
List of Listings
List of Sidebars
Creating a Applied
GuestADO.NET:
Book in ASP.NET
Building Data-Driven Solutions
by Mahesh Chand and David Talbot ISBN:1590590732
Today, a guest book is a common
Apress tool used on Web sites to gather information about visitors. In this
2003 (928 pages)
example, you'll see how to create a guest book
This text provides extensive using of
coverage ASP.NET
ADO.NETand VB .NET. In this application, you'll use
technology
a Microsoft Accessincluding ADO.NET internals, namespaces, classes, and visitors. You can use even use a
2000 database to store the data submitted by site
interfaces,
SQL Server database. and takes
The only reason a comprehensive look an
this example uses at XML
Access database is because it's easier to
namespaces
create and use than SQL Server.and classes, and how
The database to integrate
name both with
is GuestBook.mdb. You can create this database
ADO.NET.
in Access 2000. This database has only one table, Guest. Figure 14-30 shows the table schema. As you
can see, ID is a unique auto number field. The Name, Address, Email, and Comments fields represent the
name,
Table of address,
Contentsemail address, and comments of a visitor (respectively).
Applied ADO.NETBuilding Data-Driven Solutions
Introduction
Chapter 1 - ADO.NET Basics
Chapter 2 - Data Components in Visual Studio .NET
Chapter 3 - ADO.NET in Disconnected Environments
Chapter 4 - ADO.NET in Connected Environments
Chapter 5 - Handling ADO.NET Events
Chapter 6 - Integrating XML with ADO.NET
Chapter 7 - 14-30:
Figure Data Binding
Tableand Windows
schema Formstable
of Guest Data-Bound Controls
of GuestBook.mdb
Chapter 8 - Constraints and Data Relations
Chapter 9 - ADO.NET Exception Handling
The following
Chapter sections
10 - Working provide
with a simple
the ODBC tutorial
.NET Data that guide you through creating a guest book for your Web
Provider
site step
Chapter 11by step. Procedures and Views
- Stored
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
To create a guest book, first you create an ASP.NET Web Application project using the Visual Basic
Chapter 13 - Developing
Web Application a Custom
template Data
from the Providertemplates. Name the project MyGuestBook.
available
Chapter 14 - Developing Database Web Applications using ASP.NET
Chapter 15 - Using ADO.NET in Xml Web Services
Default Web Form: MyGuestBook.aspx
Chapter 16 - ASP.NET Server Controls and Data Binding
Chapter 17 -create
When you Building Real-World
a new Web Applications
Web application project, the wizard adds one default Web Form to your project
Chapter 18 - Object-Relational
calledWebForm1.aspx. YouMapping
can seeinthis
.NETpage when you run your application. For this example, rename
Chapter 19 - MappedtoObjects:
WebForm1.aspx Performance Considerations
MyGuestBook.aspx. and Data
You can rename Binding
a page by right-clicking the .aspx file in the
Chapter 20Explorer
Solution - COM Interoperability andRename
and selecting the ADO.NET option.
Chapter 21 - Messaging
Next, add
Chapter 22 -a SQL
few Server
Web controls to the form.
and ADO.NET: NotesFor
on this form, add the controls listed in Table 14-6.
Performance
Appendix A - Relational Databases: Some Basic Concepts
Table 14-6: Web Controls on MyGuestBook.aspx Page
Appendix B - Commonly Used SQL Statements
Appendix
CONTROLC - ADO.NET Frequently
TYPE Asked QuestionsDESCRIPTION
Index
ListNameTextBox
of Figures <asp:TextBox> Name text box
ListAddressTextBox
of Tables <asp:TextBox> Address text box
List of Listings
EmailTextBox
List of Sidebars
<asp:TextBox> Email text box
CommentsTextBox <asp:TextBox> Comments text box
Button1 <asp:Button> Saves data to the database and calls
Thanks.aspx
Button2 <asp:Button> Calls ViewGuestBook.aspx
As you can see from Table 14-6, we added some text to the page, four text boxes, and two buttons and
then renamed them accordingly by setting each one's properties. For example, we set the Comments
TextBox control's TextMode property to Multiple. By changing the properties of the controls,
MyGuestBook.aspx form looks like Figure 14-31.
Applied ADO.NET: Building Data-Driven Solutions
by Mahesh Chand and David Talbot ISBN:1590590732
Apress 2003 (928 pages)
This text provides extensive coverage of ADO.NET technology
including ADO.NET internals, namespaces, classes, and
interfaces, and takes a comprehensive look at XML
namespaces and classes, and how to integrate both with
ADO.NET.
Table of Contents
Applied ADO.NETBuilding Data-Driven Solutions
Introduction
Chapter 1 - ADO.NET Basics
Chapter 2 - Data Components in Visual Studio .NET
Chapter 3 - ADO.NET in Disconnected Environments
Chapter 4 - ADO.NET in Connected Environments
Chapter 5 - Handling ADO.NET Events
Figure
Chapter 6 - 14-31: XML with ADO.NET submission page
MyGuestBook.aspx
Integrating
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
Now double-click the Sign In Guest Book button and write the code in Listing 14-15. Don't forget to import
Chapter 8 - Constraints and Data Relations
System.Data.OleDb namespace in your application.
Chapter 9 - ADO.NET Exception Handling
Chapter
Listing10 - Working
14-15: withGuest
Adding the ODBC
Data.NET Data
to the Provider
Database
Chapter 11 - Stored Procedures and Views
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Private Sub Button1_Click(ByVal sender As System.Object, _
Chapter 13 - Developing a Custom Data Provider
ByVal e As System.EventArgs) Handles Button1.Click
Chapter'14 - Developing
set Access Database
connectionWeb Applications
and selectusingstrings
ASP.NET
ChapterDim
15 -strDSN
Using ADO.NET in Xml Web Services
As String = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
Chapter 16 - ASP.NET
"DataServer Controls and Data Binding
Source=C:\\GuestBook.mdb"
ChapterDim
17 -strSQL
Building Real-World
As String Web=Applications
"INSERT INTO Guest" & _
Chapter 18 - Object-Relational
"(Name, Mapping in .NET Email, Comments)" & _
Address,
Chapter 19 - Mapped Objects: Performance
"VALUES('" Considerations and Data Binding
+ NameTextBox.Text.ToString() + "','" & _
AddressTextBox.Text.ToString()
Chapter 20 - COM Interoperability and ADO.NET + "','" & _
Chapter 21 - Messaging EmailTextBox.Text.ToString() & _
Chapter 22 - SQL Server"','" + CommentsTextBox.Text.ToString()
and ADO.NET: Notes on Performance + "')"
Appendix A - Relational Databases: Some Basic Concepts
' Bcreate
Appendix OleDbDataAdapter
- Commonly Used SQL Statements
Dim conn As OleDbConnection = New OleDbConnection(strDSN)
Appendix C - ADO.NET Frequently Asked Questions
' Create OleDbCommand and call ExecuteNonQuery to execute
Index
' a SQL statement
List of Figures
Dim myCmd As OleDbCommand = New OleDbCommand(strSQL, conn)
List of Tables
Try
List of Listings
conn.Open()
List of Sidebars
myCmd.ExecuteNonQuery()
Catch exp As Exception
Console.WriteLine("Error: {0}", exp.Message)
Finally
conn.Close()
conn.Dispose()
End Try
' Open Thanks.aspx page after adding entries to the guest book
Response.Redirect("Thanks.aspx")
End Sub
As you can see from Listing
Applied 14-15, you
ADO.NET: write the
Building data entered
Data-Driven into the Web Form to an Access database.
Solutions
Our database resides in the C:\ root dir. Obviously,
by Mahesh Chand and David Talbot
if your database is somewhere else, you need to
ISBN:1590590732
change this database path. After writing
Apress 2003 (928 pages) to the database's Guest table we continue the program by
opening the Thanks.aspx page in your browser. (We discuss this page a little bit further in the
This text provides extensive coverage of ADO.NET technology
"Thanks.aspx" section.)
including ADO.NET internals, namespaces, classes, and
interfaces, and takes a comprehensive look at XML
Now, add the code in Listing 14-16
namespaces to the and
and classes, clickhow
event of the View
to integrate Guest
both with Book button. The View Guest Book
click event opensADO.NET.
the ViewGuestBook.aspx page in the browser.
Thanks.aspx
TheThanks.aspx page is merely a confirmation page that the user receives after adding data to the
guest book. It has two buttons and a simple message. The buttons are responsible for navigating you
through the ViewGuestBook.aspx page or to the site home page. Table 14-8 lists the controls for
Thanks.aspx.
Table of Contents
Applied ADO.NETBuilding Data-Driven Solutions
Introduction
Chapter 1 - ADO.NET Basics
Chapter 2 - Data Components in Visual Studio .NET
Chapter 3 - ADO.NET in Disconnected Environments
Chapter 4 - 14-33:
Figure ADO.NET in Connected
Thank you pageEnvironments
Chapter 5 - Handling ADO.NET Events
Listing 614-18
Chapter shows theXML
- Integrating My with
Home Page button and the View Guest Book button-click code. As you can
ADO.NET
see from
Chapter 7 the listing,
- Data the My
Binding andHome Page
Windows button
Forms click callsControls
Data-Bound www.c-sharpcorner.com. Obviously, you can
call your
Chapter 8 Web site's home
- Constraints andpage. The View Guest Book button click calls ViewGuestBook.aspx.
Data Relations
Chapter 9 - ADO.NET Exception Handling
Listing 14-18: My Home Page and View Guest Book Buttons
Chapter 10 - Working with the ODBC .NET Data Provider
Chapter 11 - Stored Procedures and Views
Private
Chapter 12 -Sub Button1_Click(ByVal
Oracle, sender
SQLXML, and Other .NET Data As System.Object, _
Providers
ByVal
Chapter 13 -eDeveloping
As System.EventArgs) Handles Button1.Click
a Custom Data Provider
ChapterResponse.Redirect("http://www.c-sharpcorner.com/")
14 - Developing Database Web Applications using ASP.NET
End Sub
Chapter 15 - Using ADO.NET in Xml Web Services
Chapter 16 - ASP.NET Server Controls and Data Binding
Private Sub Button2_Click(ByVal sender As System.Object, _
Chapter 17 - Building Real-World Web Applications
ByVal e As System.EventArgs) Handles Button2.Click
Chapter 18 - Object-Relational Mapping in .NET
Response.Redirect("ViewGuestBook.aspx")
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
End Sub
Chapter 20 - COM Interoperability and ADO.NET
Chapter 21 - Messaging
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Appendix
NoteA Don't
- Relational
forget Databases: Some Basic
to add a reference Concepts
to the System.Data.OleDb namespace in the
Appendix B ViewGuestBook.aspx
- Commonly Used SQL Statements
and MyGuestBook.aspx pages.
Appendix C - ADO.NET Frequently Asked Questions
Index
Compiling and Running the Guest Book Project
List of Figures
List
Now of you're
Tables all set to compile and run the project. You should be able to do everything you usually do in a
List of Listings
guest book. The output of the program looks like Figure 14-34.
List of Sidebars
Applied ADO.NET: Building Data-Driven Solutions
by Mahesh Chand and David Talbot ISBN:1590590732
Apress 2003 (928 pages)
This text provides extensive coverage of ADO.NET technology
including ADO.NET internals, namespaces, classes, and
interfaces, and takes a comprehensive look at XML
namespaces and classes, and how to integrate both with
ADO.NET.
Table of Contents
Applied ADO.NETBuilding Data-Driven Solutions
Introduction
Chapter 1 - ADO.NET Basics
Chapter 2 - Data Components in Visual Studio .NET
Chapter 3 - ADO.NET in Disconnected Environments
Chapter 4 - ADO.NET in Connected Environments
Chapter 5 - Handling ADO.NET Events
Figure 14-34: Welcome to my guest book
Chapter 6 - Integrating XML with ADO.NET
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
As you 8can- Constraints
Chapter see from Figure 14-34,
and Data we added a new record by filling data in the fields and clicking the Sign
Relations
In Guest Book button. The next page
Chapter 9 - ADO.NET Exception Handling displayed is the Thanks.aspx page, which looks like Figure 14-35.
Chapter 10 - Working with the ODBC .NET Data Provider
Chapter 11 - Stored Procedures and Views
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Chapter 13 - Developing a Custom Data Provider
Chapter 14 - Developing Database Web Applications using ASP.NET
Chapter 15 - Using ADO.NET in Xml Web Services
Chapter 16 - ASP.NET Server Controls and Data Binding
Chapter 17 - Building Real-World Web Applications
Chapter 18 - Object-Relational Mapping in .NET
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
Chapter 20 - COM Interoperability and ADO.NET
Chapter 21 - Messaging
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Appendix A - Relational Databases: Some Basic Concepts
Appendix B - Commonly Used SQL Statements
Figure 14-35: TheThanks.aspx page of the guest book
Appendix C - ADO.NET Frequently Asked Questions
Index
Now, if you view the guest book, it looks like Figure 14-36. As you'll notice, there are a couple of extra
List of Figures
records in this guest book.
List of Tables
List of Listings
List of Sidebars
Applied ADO.NET: Building Data-Driven Solutions
by Mahesh Chand and David Talbot ISBN:1590590732
Apress 2003 (928 pages)
This text provides extensive coverage of ADO.NET technology
including ADO.NET internals, namespaces, classes, and
interfaces, and takes a comprehensive look at XML
namespaces and classes, and how to integrate both with
ADO.NET.
Table of Contents
Applied ADO.NETBuilding Data-Driven Solutions
Introduction
Chapter 1 - ADO.NET Basics
Chapter 2 - Data Components in Visual Studio .NET
Chapter 3 - ADO.NET in Disconnected Environments
Figure
Chapter 4 - 14-36:
ADO.NETMyinguest book entries
Connected Environments
Chapter 5 - Handling ADO.NET Events
Chapter 6 - Integrating XML with ADO.NET
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
Chapter 8 - Constraints and Data Relations
Chapter 9 - ADO.NET Exception Handling
Chapter 10 - Working with the ODBC .NET Data Provider
Chapter 11 - Stored Procedures and Views
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Chapter 13 - Developing a Custom Data Provider
Chapter 14 - Developing Database Web Applications using ASP.NET
Chapter 15 - Using ADO.NET in Xml Web Services
Chapter 16 - ASP.NET Server Controls and Data Binding
Chapter 17 - Building Real-World Web Applications
Chapter 18 - Object-Relational Mapping in .NET
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
Chapter 20 - COM Interoperability and ADO.NET
Chapter 21 - Messaging
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Appendix A - Relational Databases: Some Basic Concepts
Appendix B - Commonly Used SQL Statements
Appendix C - ADO.NET Frequently Asked Questions
Index
List of Figures
List of Tables
List of Listings
List of Sidebars
Summary Applied ADO.NET: Building Data-Driven Solutions
by Mahesh Chand and David Talbot ISBN:1590590732
ASP.NET is a new framework
Apress to write
2003 (928 pages)Web applications for the Microsoft .NET platform. ASP.NET
supports a rich set
This text provides controls.
of Web Forms extensiveYou can use
coverage these controls
of ADO.NET at runtime as well as design-time.
technology
In VS .NET, you can just drag these controls on a Web Form, set
including ADO.NET internals, namespaces, classes, and their properties and methods, and your
interfaces,
application is ready to run onand
thetakes
Web. a comprehensive look at XML
namespaces and classes, and how to integrate both with
You can also useADO.NET.
ADO.NET components in Web Forms in the same way you use them in desktop
applications. All ADO.NET components including the DataReader,DataSet,DataView, and
DataCommand components work in the same way as they would in a desktop application. ASP.NET
Table of Contents
provides many data-bound controls you can directly bind to a data source with the help of DataSet and
Applied ADO.NETBuilding Data-Driven Solutions
DataView. For example, DataGrid and ListBox are two common data-bound controls. You can use
Introduction
theDataSource property of these controls to bind to a DataSet.
Chapter 1 - ADO.NET Basics
Chapter 2 - DataisComponents
TheDataGrid in Visual
the most versatile Studioamong
control .NET all the Web controls. By using the DataGrid, you can
write full-fledge
Chapter database
3 - ADO.NET applications
in Disconnected for your Web sites. The DataTable of the DataSet provides the
Environments
programmer
Chapter with a means
4 - ADO.NET of working
in Connected with the data in these controls. A table is a collection of rows and
Environments
columns.
Chapter 5 A DataTable
- Handling represents
ADO.NET Eventsa database table. With the help of the DataView class, you can bind
a data table
Chapter to a DataGrid
6 - Integrating or other
XML with data-bound controls.
ADO.NET
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
Thenext chapter covers ASP.NET data-bound controls. You'll see some practical uses of these controls.
Chapter 8 - Constraints and Data Relations
Chapter 9 - ADO.NET Exception Handling
Chapter 10 - Working with the ODBC .NET Data Provider
Chapter 11 - Stored Procedures and Views
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Chapter 13 - Developing a Custom Data Provider
Chapter 14 - Developing Database Web Applications using ASP.NET
Chapter 15 - Using ADO.NET in Xml Web Services
Chapter 16 - ASP.NET Server Controls and Data Binding
Chapter 17 - Building Real-World Web Applications
Chapter 18 - Object-Relational Mapping in .NET
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
Chapter 20 - COM Interoperability and ADO.NET
Chapter 21 - Messaging
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Appendix A - Relational Databases: Some Basic Concepts
Appendix B - Commonly Used SQL Statements
Appendix C - ADO.NET Frequently Asked Questions
Index
List of Figures
List of Tables
List of Listings
List of Sidebars
Chapter Applied
15: Using ADO.NET in Xml
ADO.NET: Building Data-Driven Solutions
by Mahesh Chand and David Talbot
Web Services
ISBN:1590590732
Apress 2003 (928 pages)
Overview This text provides extensive coverage of ADO.NET technology
including ADO.NET internals, namespaces, classes, and
Web services provide a wayand
interfaces, to run a service
takes on the Web
a comprehensive and
look at access
XML its methods using standard protocols,
including Simple namespaces
Object AccessandProtocol
classes, (SOAP),
and how to integrate Markup
Extensible both with
Language (XML), Web Service
ADO.NET.
Description Language (WSDL), and Hypertext Transfer Protocol (HTTP). Technically, a Web service is
nothing more than an application that exposes its interface over the Web to a client who wants to access
the service's
Table abilities. The uses of a Web service include validating credit cards, searching for data in a
of Contents
database, inserting
Applied ADO.NETBuildingan order into a shopping
Data-Driven cart, and updating a guest list. The sky is the limit on what you
Solutions
can have your
Introduction
Web service do on your server.
Chapter 1 - ADO.NET
In the past, Basics
JavaBeans, Component Object Model (COM) components, and other, nonstandard service
Chapter 2 - Data
components Components
handled in Visual which
these services, Studiorequired
.NET specialized formats and/or extra specialist
Chapter 3 - ADO.NET
components in Disconnected
to exchange Environments
data with the client. But Web services under .NET run by invoking methods in
Chapter 4 - directly
the service ADO.NET in Connected
through HTTP Environments
or SOAP, so someone wanting to run your Web service from their
Chapter 5 can
computer - Handling
simplyADO.NET Eventscall to your service, passing the parameters in a standard Uniform
send a HTTP
Resource
Chapter 6 -Locator (URL).
Integrating You'll
XML with see how to do this later in the chapter.
ADO.NET
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
Three components make up a Web service:
Chapter 8 - Constraints and Data Relations
Chapter 9 - ADO.NET Exception Handling
Discovery: First, you need to locate the Web service. You locate Web services through the Discovery
Chapter 10 - Working with the ODBC .NET Data Provider
Service Protocol. The discoverable information for a .NET Web service is stored in XML in a .disco
Chapter 11 - Stored Procedures and Views
file. This file contains references to all the Web services under your Web site's virtual directory. Visual
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Studio (VS) can automatically generate this file for you.
Chapter 13 - Developing a Custom Data Provider
Chapter 14 - Developing Database Web Applications using ASP.NET
Description:
Chapter Once you've
15 - Using ADO.NET discovered
in Xml your service, you need a way to tell the client what methods,
Web Services
classes,
Chapter and so Server
16 - ASP.NET on the Controls
Web service has and
and Data what wiring protocol (SOAP, HTTP, and so on) the
Binding
services are using. You do this through WSDL, an XML format. VS provides a tool for generating
Chapter 17 - Building Real-World Web Applications
WSDL files automatically from your services.
Chapter 18 - Object-Relational Mapping in .NET
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
Wiring
Chapter protocol:
20 - COM Web services
Interoperability under .NET use two main protocols: HTTP-post/HTTP-get and
and ADO.NET
SOAP.
Chapter HTTP-post and HTTP-get enable you to send and receive information via a URL by passing
21 - Messaging
and
Chapter 22receiving namevalue
- SQL Server pair strings.
and ADO.NET: NotesUnfortunately,
on PerformanceHTTP can only pass strings that represent
different
Appendix data types.
A - Relational SOAP allows
Databases: Some you toConcepts
Basic pass a richer type of information, such as DataSets. You
can find more details and SOAP specifications at www.w3.org/TR/SOAP/.
Appendix B - Commonly Used SQL Statements
Appendix C - ADO.NET Frequently Asked Questions
Index
List of Figures
List of Tables
List of Listings
List of Sidebars
Exploring Web Services
Applied and the
ADO.NET: Building .NET Framework
Data-Driven Solutions Library
by Mahesh Chand and David Talbot ISBN:1590590732
The .NET Framework
ApressClass
2003Library provides four namespaces that contain Web service classes. These
(928 pages)
namespaces areThis
System.Web.Services, System.Web.Services.Description,
text provides extensive coverage of ADO.NET technology
System.Web.Services.Discovery, and System.Web.Services.Protocol.
including ADO.NET internals, namespaces, classes, and
interfaces, and takes a comprehensive look at XML
TheSystem.Web.Services
namespaces andnamespace provides
classes, and how to classes
integratethat
bothenable
with you to build and use Web
ADO.NET.
services. It has four classes. The WebService class defines the optional base class for Web services,
which provides direct access to an ASP.NET application. Server,Session,User, and Context are
some of its properties. WebMethodAttribute,WebServiceAttribute, and
Table of Contents
WebServiceBindingAttribute are other classes of this namespace.
Applied ADO.NETBuilding Data-Driven Solutions
Introduction
TheSystem.Web.Services.Description namespace provides classes that enable you to describe
Chapter
a WSDL.1 - ADO.NET Basics
Chapter 2 - Data Components in Visual Studio .NET
TheSystem.Web.Services.Discovery
Chapter namespace provides classes that enable Web service
3 - ADO.NET in Disconnected Environments
consumers
Chapter 4 - to locate a
ADO.NET in Web service
Connected through discovery.
Environments
Chapter 5 - Handling ADO.NET Events
TheSystem.Web.Services.Protocols namespace provides classes that define the protocols used
Chapter 6
to transmit- data
Integrating XML with ADO.NET
between a client and a Web service.
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
Chapter 8 - Constraints and Data Relations
Chapter 9 - ADO.NET Exception Handling
Chapter 10 - Working with the ODBC .NET Data Provider
Chapter 11 - Stored Procedures and Views
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Chapter 13 - Developing a Custom Data Provider
Chapter 14 - Developing Database Web Applications using ASP.NET
Chapter 15 - Using ADO.NET in Xml Web Services
Chapter 16 - ASP.NET Server Controls and Data Binding
Chapter 17 - Building Real-World Web Applications
Chapter 18 - Object-Relational Mapping in .NET
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
Chapter 20 - COM Interoperability and ADO.NET
Chapter 21 - Messaging
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Appendix A - Relational Databases: Some Basic Concepts
Appendix B - Commonly Used SQL Statements
Appendix C - ADO.NET Frequently Asked Questions
Index
List of Figures
List of Tables
List of Listings
List of Sidebars
Creating a Applied
Web Service in VS Data-Driven
ADO.NET: Building .NET Solutions
by Mahesh Chand and David Talbot ISBN:1590590732
To understand Web services
Apress 2003 better, you'll build a simple Web service. The Web service will receive an
(928 pages)
order ID and thenThis
query the Northwind database's
text provides extensive coverageOrders table for
of ADO.NET the correct order. It will then return the
technology
order in a DataSet.
including ADO.NET internals, namespaces, classes, and
interfaces, and takes a comprehensive look at XML
namespaces
The first step in creating and classes,
the Web service and
is tohow File New
to integrate
select with
both Project and choose the ASP.NET Web
ADO.NET.
Service template, as shown in Figure 15-1.
Table of Contents
Applied ADO.NETBuilding Data-Driven Solutions
Introduction
Chapter 1 - ADO.NET Basics
Chapter 2 - Data Components in Visual Studio .NET
Chapter 3 - ADO.NET in Disconnected Environments
Chapter 4 - ADO.NET in Connected Environments
Chapter 5 - Handling ADO.NET Events
Chapter 6 - Integrating XML with ADO.NET
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
Chapter 8 - Constraints and Data Relations
Chapter 9 - ADO.NET Exception Handling
Chapter 10 - Working with the ODBC .NET Data Provider
Figure 15-1: Creating a new Web service project
Chapter 11 - Stored Procedures and Views
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
This creates
Chapter a Web service
13 - Developing project
a Custom onProvider
Data the local Web server. By default, localhost is available as a Web
server on
Chapter 14 your development
- Developing machine.
Database Alternatively
Web Applications youASP.NET
using could use another Web server for your
applications.
Chapter AfterADO.NET
15 - Using entering in
a server
Xml Webname, you enter a project name. In this sample, the project name is
Services
OrderRetrievalWebService.
Chapter VS .NETand
16 - ASP.NET Server Controls creates a new folder with the project name on the Web server and
Data Binding
keeps all
Chapter 17 project files
- Building under that
Real-World folder.
Web Applications
Chapter 18Web.config
First, the - Object-Relational
file isMapping
an XMLinfile.NET
containing information on how to run the service under ASP.NET.
Chapter
Second, 19the
- Mapped Objects: Performance
Global.asax Considerations
and Global.asax.vb and
files Data Binding
enable you to handle application-level events for
Chapter 20 - COM
the service. TheseInteroperability
event handlersand ADO.NET
include event handling pairs such as
Chapter 21 - Messaging
Application_Start/Application_End, Session_Start/Session_End, and
Chapter 22 - SQL Server and ADO.NET:
Begin_Request/EndRequest. YouNotes on Performance
can view Global.asax.vb by right-clicking the Global.asax file
in the Solution
Appendix Explorer
A - Relational and choosing
Databases: SomeView
BasicCode. Next, OrderRetrievalWebService.vsdisco is an
Concepts
XML fileBcontaining
Appendix - Commonlyinformation
Used SQLfor discovery of the service. You'll actually need to generate an
Statements
OrderRetrievalWebService.disco
Appendix file for your client to see the service (more on this later).
C - ADO.NET Frequently Asked Questions
Index
Finally, the Service1.asmx file serves as the entry point into the service. The code behind the service,
List of Figures
Service1.asmx.vb, is where you'll place the method for retrieving the order. Right-click the
List of Tables
Service1.asmx file in the Solution Explorer and choose View Code from the pop-up menu. Note that it
List of Listings
looks like any other VB .NET component; it has a constructor, an InitializeComponent method, and
List of Sidebars
aDispose method.
Now you'll add database support to the Web service. Actually, adding database support to a Web service
is quite easy using ADO.NET. You can add ADO.NET data components to a Web service by just dragging
ADO.NET components from the Toolbox's Data tab to Web Forms. Similar to Windows or Web Forms,
you can also use the Server Explorer to add database components to a Web service.
In this example, you'll use the SQL Server Northwind database. You won't use the design-time support for
ADO.NET, for two reasons. Firstly, when you drop a table from the Server Explorer onto a Web page, the
designer adds lots of unwanted code. Secondly, it's hard to understand and modify the designer-added
code. We recommend writing code manually.
Now, the next step is to add a Web method to the project. You can use the Class Wizard to add a method,
or you can add a method manually. If you examine the default code in Service1.asmx.vb, it has a
Applied ADO.NET:
method called HelloWorld, whichBuilding
looks likeData-Driven
following: Solutions
by Mahesh Chand and David Talbot ISBN:1590590732
Apress 2003 (928 pages)
'<WebMethod()> Public Function HelloWorld() As String
This text provides extensive coverage of ADO.NET technology
'HelloWorld =including
"Hello World"
ADO.NET internals, namespaces, classes, and
' End Function
interfaces, and takes a comprehensive look at XML
namespaces and classes, and how to integrate both with
ADO.NET.
As you can see from this code, adding a Web method is simple. You just need to add the
<WebMethod()> attribute in front of a method. Add a method called GetOrderFromDatabase. This
Table of Contents
method reads data from a database and returns the data as a DataSet object. The method takes an
Applied
OrderIDADO.NETBuilding
as an argumentData-Driven Solutions
and returns all records related to that OrderID. Before you add the method,
Introduction
though, you also need to add the variables in the following code to the project:
Chapter 1 - ADO.NET Basics
Chapter 2
Private -ConnectionString
Data Components in Visual Studio .NET
As String = "user id=sa;password=;" & _
Chapter 3 "Initial
- ADO.NET Catalog=Northwind;"
in Disconnected Environments
& _
Chapter 4 "Data
- ADO.NET in Connected Environments
Source=MCB;"
Chapter 5 - Handling
Private conn ADO.NET Events
As SqlConnection = Nothing
Chapter 6 - Integrating XML with ADO.NET
Private adapter As SqlDataAdapter = Nothing
Chapter 7 - Data
Private sqlBinding and Windows
As String Forms Data-Bound Controls
= Nothing
Chapter 8 - Constraints and Data Relations
Chapter 9 - ADO.NET Exception Handling
TheGetOrdersFromDatabase method fills data from the Orders table of the Northwind database and
Chapter 10 - Working with the ODBC .NET Data Provider
returns a DataSet that has records from the Orders table corresponding to an order ID. Listing 15-1
Chapter 11 - Stored Procedures and Views
shows the GetOrdersFromDatabasemethod.
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Chapter
Listing13 - Developing
15-1: a Custom Data Provider Method for Obtaining an Order from an Order ID
The GetOrdersFromDatabase
Chapter 14 - Developing Database Web Applications using ASP.NET
Chapter 15 - Using ADO.NET in Xml Web Services
<WebMethod()> Public Function GetOrderFromDatabase(_
Chapter 16 - ASP.NET Server Controls and Data Binding
ByVal orderID As Integer) As DataSet
Chapter 17 - Building Real-World Web Applications
Dim ds As DataSet = New DataSet()
Chapter 18 - Object-Relational Mapping in .NET
' Create a new connection
Chapterconn
19 - Mapped
= New Objects: Performance Considerations and Data Binding
SqlConnection(ConnectionString)
Chaptersql20 -=COM Interoperability
"SELECT * FROM and ADO.NETWHERE OrderID = " + orderID.ToString()
Orders
Chapter'21 - Messaging
Open the connection
ChapterIf 22 (conn.State
- SQL Server and<> ADO.NET: Notes on Performance Then
ConnectionState.Open)
Appendix A - Relational
conn.Open() Databases: Some Basic Concepts
AppendixEndB -IfCommonly Used SQL Statements
Appendix' C Create
- ADO.NETa DataAdapter
Frequently Asked Questions
Index Dim adapter As SqlDataAdapter = New SqlDataAdapter(sql, conn)
adapter.Fill(ds)
List of Figures
' Tables
List of Close the connection
If (conn.State = ConnectionState.Open) Then
List of Listings
conn.Close()
List of Sidebars
End If
' Return DataSet
Return ds
End Function
As you can see from Listing 15-1, the method receives an order ID from a client and returns a DataSet to
the client. It uses the DataAdapter to fill a DataSet with the row containing that order ID.
Applied
Note You have to addADO.NET: Building
a WHERE clause Data-Driven
onto Solutions to filter the single row of data. Also,
the SelectCommand
by make
you must MaheshallChand
exposedandmethods
David Talbot ISBN:1590590732
in the Web service public, and they must contain a
Apress 2003
[WebMethod] attribute; otherwise, the client won't see them.
(928 pages)
This text provides extensive coverage of ADO.NET technology
including ADO.NET internals, namespaces, classes, and
interfaces, and takes a comprehensive look at XML
namespaces and classes, and how to integrate both with
ADO.NET.
Table of Contents
Applied ADO.NETBuilding Data-Driven Solutions
Introduction
Chapter 1 - ADO.NET Basics
Chapter 2 - Data Components in Visual Studio .NET
Chapter 3 - ADO.NET in Disconnected Environments
Chapter 4 - ADO.NET in Connected Environments
Chapter 5 - Handling ADO.NET Events
Chapter 6 - Integrating XML with ADO.NET
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
Chapter 8 - Constraints and Data Relations
Chapter 9 - ADO.NET Exception Handling
Chapter 10 - Working with the ODBC .NET Data Provider
Chapter 11 - Stored Procedures and Views
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Chapter 13 - Developing a Custom Data Provider
Chapter 14 - Developing Database Web Applications using ASP.NET
Chapter 15 - Using ADO.NET in Xml Web Services
Chapter 16 - ASP.NET Server Controls and Data Binding
Chapter 17 - Building Real-World Web Applications
Chapter 18 - Object-Relational Mapping in .NET
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
Chapter 20 - COM Interoperability and ADO.NET
Chapter 21 - Messaging
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Appendix A - Relational Databases: Some Basic Concepts
Appendix B - Commonly Used SQL Statements
Appendix C - ADO.NET Frequently Asked Questions
Index
List of Figures
List of Tables
List of Listings
List of Sidebars
Testing Your Web
Applied Service
ADO.NET: Building Data-Driven Solutions
by Mahesh Chand and David Talbot ISBN:1590590732
Now you're actually ready
Apress to build
2003 and test your Web service. First, build the service using the Build menu
(928 pages)
option and then start it in Debug mode.
This text provides extensiveThis coverage
brings upofthe Web service's
ADO.NET default page generated by VS
technology
.NET in your browser, as shown in Figure 15-2.
including ADO.NET internals, namespaces, classes, and
interfaces, and takes a comprehensive look at XML
namespaces and classes, and how to integrate both with
ADO.NET.
Table of Contents
Applied ADO.NETBuilding Data-Driven Solutions
Introduction
Chapter 1 - ADO.NET Basics
Chapter 2 - Data Components in Visual Studio .NET
Chapter 3 - ADO.NET in Disconnected Environments
Chapter 4 - ADO.NET in Connected Environments
Chapter 5 - Handling ADO.NET Events
Figure 15-2: Initially running the Web service Service1.asmx
Chapter 6 - Integrating XML with ADO.NET
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
As you 8can- see
Chapter in Figure
Constraints 15-2,
and Dataone method, GetOrderFromDatabase, is available in the browser.
Relations
Chapter 9 - ADO.NET Exception Handling
You can make this screen a bit more descriptive by adding a WebService attribute to the top of the class
Chapter 10 - Working with the ODBC .NET Data Provider
and then adding descriptions to both the WebService attribute and the WebMethod attribute. As you can
Chapter 11 - Stored Procedures and Views
see, Listing 15-2 adds a description to both.
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Chapter
Listing13 - Developing
15-2: a Custom Datato
Adding Descriptions Provider
the WebService and WebMethod Attributes
Chapter 14 - Developing Database Web Applications using ASP.NET
Chapter 15 - Using ADO.NET in Xml Web Services
<WebService(Namespace:="http://tempuri.org/", _
Chapter 16 - ASP.NET Server Controls and Data Binding
Description:="Working with Orders in Northwind")> _
Chapter 17 - Building Real-World Web Applications
Public Class Service1
Chapter 18 - Object-Relational
Inherits Mapping in .NET
System.Web.Services.WebService
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
Chapter 20 -....
COM Interoperability and ADO.NET
Chapter 21 - Messaging
<WebMethod(Description:="Retrieve an order from Northwind ")> _
Chapter
Public22 -Function
SQL Server and ADO.NET: Notes on Performance
GetOrderFromDatabase(_
Appendix
ByValA orderID
- RelationalAs
Databases:
Integer)SomeAs
Basic Concepts
DataSet
Appendix B - Commonly Used SQL Statements
End Function
Appendix C - ADO.NET Frequently Asked Questions
Index
End
List Class
of Figures
List of Tables
List of Listings
List of Sidebars
The service now looks like Figure 15-3.
Applied ADO.NET: Building Data-Driven Solutions
by Mahesh Chand and David Talbot ISBN:1590590732
Apress 2003 (928 pages)
This text provides extensive coverage of ADO.NET technology
including ADO.NET internals, namespaces, classes, and
interfaces, and takes a comprehensive look at XML
namespaces and classes, and how to integrate both with
ADO.NET.
Table of Contents
Applied ADO.NETBuilding
Figure Data-Driven
15-3: The Web Solutions
service after you add attributes
Introduction
Chapter 1 - ADO.NET Basics
If you click the link for the GetOrderFromDatabase method, you'll see a Parameter OrderID text box.
Chapter 2 - Data Components in Visual Studio .NET
Enter 10248 as the OrderID. After you click the Invoke button, the browser returns the XML data
Chapter 3 - ADO.NET in Disconnected Environments
representing the DataSet, which contains the order with the order ID of 10248. Figure 15-4 shows a piece
Chapter 4 - ADO.NET in Connected Environments
of the XML data representing the order and displayed by the browser.
Chapter 5 - Handling ADO.NET Events
Chapter 6 - Integrating XML with ADO.NET
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
Chapter 8 - Constraints and Data Relations
Chapter 9 - ADO.NET Exception Handling
Chapter 10 - Working with the ODBC .NET Data Provider
Chapter 11 - Stored Procedures and Views
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Chapter 13 - Developing a Custom Data Provider
Chapter 14 - Developing Database Web Applications using ASP.NET
Chapter 15 - Using ADO.NET in Xml Web Services
Chapter 16 - ASP.NET Server Controls and Data Binding
Chapter 17 - Building Real-World Web Applications
Chapter 18 - Object-Relational Mapping in .NET
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
Chapter 20 - COM Interoperability and ADO.NET
Figure 15-4: TheOrder DataSet displayed by the browser in XML format
Chapter 21 - Messaging
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Appendix A - Relational
As you can Databases:
see from Figure 15-4,Some Basic Concepts
the default namespace for the DataSet xmlns is
Appendix B - Commonly Used
http://tempuri.org. You
SQLcan use the WebService attribute to specify the namespace and
Statements
description
Appendix C - text for theFrequently
ADO.NET XML WebAsked
service. As you can see, VS .NET doesn't generate this attribute by
Questions
default. You have to write it manually. If you're specifying more than one property, you can separate them
Index
withofaFigures
List comma. For example, the following code sets the namespace and the description properties of the
WebService
List of Tables attribute:
List of Listings
<WebService(Namespace:="http://servername/xmlwebservices/",
List of Sidebars _
Description:="Working with Orders in Northwind")> _
Public Class Service1
Inherits System.Web.Services.WebService
' code here
End Class
Creating the WebADO.NET:
Applied Service Consumer
Building Data-Driven Solutions
by Mahesh Chand and David Talbot ISBN:1590590732
Now that you've created
Apress a2003
Web service,
(928 pages) you should create a client to use it. In this tutorial, you'll create an
ASP.NET Web Form application that accesses
This text provides extensive the Web
coverage service totechnology
of ADO.NET retrieve an order. The client will then
display the order including
in a DataGrid.
ADO.NET internals, namespaces, classes, and
interfaces, and takes a comprehensive look at XML
namespaces
First, create an ASP.NET Weband classes,
project by and how
going to to New both
integrate
File Project
with and choosing the ASP.NET Web
ADO.NET.
Application template. For this example, we'll create the application on the localhost default Web server. If
you're creating your application on a remote server, you may want to use the server name and an
appropriate directory where you have read and write permissions. Call the Web application
Table of Contents
OrderLookupApp.
Applied ADO.NETBuilding Data-Driven Solutions
Introduction
Creating a Web application adds a Web page to the project, which is the default gateway when VS .NET is
Chapter 1 - ADO.NET
done creating BasicsAs you saw in Chapter 14, you can use Web pages as Windows Forms. You
the project.
Chapter
can add2 Web
- Data
andComponents in Visual
HTML controls Studio
to Web .NETby simply dragging controls from Toolbox to the Web
pages
Chapter
page. 3 - ADO.NET in Disconnected Environments
Chapter 4 - ADO.NET in Connected Environments
In this example,
Chapter 5
add a Label, a TextBox, a Button, and a DataGrid control by dragging them from
- Handling ADO.NET Events
the ToolBox's Web Forms tab to the WebForm1.aspx Design View. Next, set the controls' properties.
Chapter 6 - Integrating XML with ADO.NET
Figure 15-5 shows the final page after setting the properties.
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
Chapter 8 - Constraints and Data Relations
Chapter 9 - ADO.NET Exception Handling
Chapter 10 - Working with the ODBC .NET Data Provider
Chapter 11 - Stored Procedures and Views
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Chapter 13 - Developing a Custom Data Provider
Chapter 14 - Developing Database Web Applications using ASP.NET
Chapter 15 - Using ADO.NET in Xml Web Services
Chapter 16 - ASP.NET Server Controls and Data Binding
Chapter 17 - Building Real-World Web Applications
Chapter 18 - Object-Relational Mapping in .NET
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
Chapter 20 - COM Interoperability and ADO.NET
Figure 15-5: Design View for searching for and displaying an order
Chapter 21 - Messaging
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
To use the
Appendix A - Web service
Relational in the client
Databases: Someapplication, you need to add a Web reference to the service. In the
Basic Concepts
SolutionBExplorer,
Appendix right-click
- Commonly Used SQLthe Statements
References option and choose Add Web Reference. This brings up the
Add Web
Appendix C Reference page, as shown
- ADO.NET Frequently Asked in Figure 15-6.
Questions
Index
List of Figures
List of Tables
List of Listings
List of Sidebars
Applied ADO.NET: Building Data-Driven Solutions
by Mahesh Chand and David Talbot ISBN:1590590732
Apress 2003 (928 pages)
This text provides extensive coverage of ADO.NET technology
including ADO.NET internals, namespaces, classes, and
interfaces, and takes a comprehensive look at XML
namespaces and classes, and how to integrate both with
ADO.NET.
Table of Contents
Applied ADO.NETBuilding Data-Driven Solutions
Introduction
Chapter 1 - ADO.NET Basics
Chapter 2 - Data Components in Visual Studio .NET
Chapter 3 - ADO.NET in Disconnected Environments
Figure
Chapter 4 - 15-6: TheinAdd
ADO.NET Web Reference
Connected locator
Environments
Chapter 5 - Handling ADO.NET Events
Chapter 6
As you can- Integrating XML with ADO.NET
see from Figure 15-6, you can choose from any existing Web service. Those Web services can
Chapter
exist on7your
- Data Binding
local and Windows
Web server, Forms Data-Bound
in the Microsoft UniversalControls
Description, Discovery, and Integration (UDDI)
Chapter
Business8 Registry,
- Constraints and Data Relations
or somewhere on the Internet. You just need to provide the URL of the service in the
Chapter
Address9 text
- ADO.NET Exception
box. In this Handling
case, you need to provide the URL of the OrderRetrieval-WebService
Chapter 10.asmx
service's - Working
pagewith
andthe ODBC
then add.NET
?wsdlDataatProvider
the end of URL. You can specify the .asmx file and URL
Chapter 11 - the
path where Stored Procedures
service and Views
entry point is located in the Address field of the wizard. As you can see, Figure 15-7
passes12
Chapter the- URL of SQLXML,
Oracle, the service
andwith .NET Data as
localhost
Other the server. (You need to replace server name if you're
Providers
accessing
Chapter 13 -aDeveloping
remote server.) TheData
a Custom contents of the service looks like Figure 15-7.
Provider
Chapter 14 - Developing Database Web Applications using ASP.NET
Chapter 15 - Using ADO.NET in Xml Web Services
Chapter 16 - ASP.NET Server Controls and Data Binding
Chapter 17 - Building Real-World Web Applications
Chapter 18 - Object-Relational Mapping in .NET
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
Chapter 20 - COM Interoperability and ADO.NET
Chapter 21 - Messaging
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Appendix A - Relational Databases: Some Basic Concepts
Appendix B - Commonly Used SQL Statements
Appendix C - ADO.NET Frequently Asked Questions
Index
List of Figures
List of Tables
List of Listings
List of Sidebars
Figure 15-7: Web services available on the local server
Now you need to click the Add Reference button. To access Web services on the server, you need to use
the server name as a namespace. You can even rename the namespace by right-clicking and choosing
the Rename option. As you can see in Figure 15-8, the Web server name is localhost.
Applied ADO.NET: Building Data-Driven Solutions
by Mahesh Chand and David Talbot ISBN:1590590732
Apress 2003 (928 pages)
This text provides extensive coverage of ADO.NET technology
including ADO.NET internals, namespaces, classes, and
interfaces, and takes a comprehensive look at XML
namespaces and classes, and how to integrate both with
ADO.NET.
Table of Contents
Applied ADO.NETBuilding Data-Driven Solutions
Introduction
Chapter 1 - ADO.NET Basics
Chapter 2 - Data Components in Visual Studio .NET
Chapter 3 - ADO.NET in Disconnected Environments
Chapter 4 - ADO.NET in Connected Environments
Chapter 5 - Handling ADO.NET Events
Chapter 6 - Integrating XML with ADO.NET
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
Chapter 8 - Constraints and Data Relations
Chapter 9 - ADO.NET Exception Handling
Chapter 10 - Working with the ODBC .NET Data Provider
Figure 15-8: Adding Web references
Chapter 11 - Stored Procedures and Views
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Clicking13the
Chapter Add Reference
- Developing button
a Custom causes
Data VS .NET to generate three files for referencing the service:
Provider
Chapter 14 - Developing Database Web Applications using ASP.NET
A discovery file (Service1.disco)
Chapter 15 - Using ADO.NET in Xml Web Services
Chapter 16 - ASP.NET
A WSDL Server Controls and Data Binding
file (Service1.wsdl)
Chapter 17 - Building Real-World Web Applications
A proxy
Chapter file (Service1.vb)
18 - Object-Relational Mapping in .NET
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
As already discussed, the discovery file is an XML file that helps the client to find the service. The WSDL
Chapter 20 - COM Interoperability and ADO.NET
file describes the methods and classes supplied by the service in XML and defines the format that
Chapter 21 - Messaging
messages need to adhere to when exchanging information with the client. The proxy file, although not
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
displayed in the Solution Explorer, is a VB stub file generated so that the programmer can call the
Appendix
methodsAin- the
Relational Databases:
Web service with Some Basicmethod
the same Concepts
names and method parameter structure as the Web
Appendix B - Commonly
service contains. These Used SQL wrap
proxies Statements
the method calls to the Web service so that the convoluted exchange
Appendix C - ADO.NET
of parameter passingFrequently
and method Asked Questions
invocation to the remote service is transparent to the programmer. If
Index
you expand the Web References node, you can see the files belong to a service. You can expand the
List of Figures
server reference to see its files. Some files are hidden by default, but you can use the Show All button of
theofSolution
List Tables Explorer to see all the files (see Figure 15-9).
List of Listings
List of Sidebars
Applied ADO.NET: Building Data-Driven Solutions
by Mahesh Chand and David Talbot ISBN:1590590732
Apress 2003 (928 pages)
This text provides extensive coverage of ADO.NET technology
including ADO.NET internals, namespaces, classes, and
interfaces, and takes a comprehensive look at XML
namespaces and classes, and how to integrate both with
ADO.NET.
Table of Contents
Applied ADO.NETBuilding Data-Driven Solutions
Introduction
Chapter 1 - ADO.NET Basics
Chapter 2 - Data Components in Visual Studio .NET
Chapter 3 - ADO.NET in Disconnected Environments
Chapter 4 - ADO.NET in Connected Environments
Chapter 5 - Handling ADO.NET Events
Chapter 6 - Integrating XML with ADO.NET
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
Chapter 8 - Constraints and Data Relations
Chapter 9 - ADO.NET Exception Handling
Chapter 10 - Working with the ODBC .NET Data Provider
Figure 15-9: Files generated by the Web References Wizard to access the Web service
Chapter 11 - Stored Procedures and Views
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Now, everything
Chapter is all set,
13 - Developing and you're
a Custom Data ready to call the Web service's method. In this sample, you'll call the
Provider
GetOrderFromDatabase
Chapter method
14 - Developing Database Web from the Fill Order
Applications button click. So, double-click the button to write a
using ASP.NET
click event
Chapter 15 - handler for the button.
Using ADO.NET As you
in Xml Web probably noticed, the class in this example is Service1. So,
Services
that's the
Chapter 16 class of which
- ASP.NET you'll
Server be creating
Controls an instance.
and Data Binding
Chapter 17 - Building Real-World Web Applications
Once you have an instance to the service, you can call GetOrderFromDatabase in the service and
Chapter
assign 18
it to- aObject-Relational Mapping
DataSet reference. To in .NET the DataSet in a DataGrid, simply assign the DataSet to
display
Chapter 19 - Mapped
theDataGrid's Objects: Performance
DataSource Considerations
and call DataBind on theand Data Binding
DataGrid. Listing 15-3 shows the code for Fill
Chapter 20 -button-click
the Order COM Interoperability
handler. and ADO.NET
Chapter 21 - Messaging
Listing22
Chapter 15-3: Button-Click
- SQL Event Handler
Server and ADO.NET: That
Notes on Calls the Order Retrieval Web Service
Performance
Appendix A - Relational Databases: Some Basic Concepts
Appendix
Private B -Sub
Commonly Used SQL Statements sender As System.Object, _
Button1_Click(ByVal
Appendix
ByVal C -eADO.NET Frequently Asked Questions
As System.EventArgs) Handles Button1.Click
Index ' construct and call the web service with the order
List of Figures
'id in the textbox
Dim myWebService As localhost.Service1 = New localhost.Service1()
List of Tables
Dim ds As DataSet = myWebService.GetOrderFromDatabase _
List of Listings
(Convert.ToInt32(Me.TextBox1.Text))
List of Sidebars
' bind the data to the grid
DataGrid1.DataSource = ds
DataGrid1.DataBind()
End Sub
As you can see, Listing 15-3 called GetOrderFromDatabase through localhost.Service1, which
returns a DataSet. You use this database and bind to the DataGrid control and call DataGrid's
DataBind method.
Compile and run the Web application. Enter an order ID of 10248 and click the Fill Order button. Figure
15-10 shows the resulting output in Internet Explorer.
Applied ADO.NET: Building Data-Driven Solutions
by Mahesh Chand and David Talbot ISBN:1590590732
Apress 2003 (928 pages)
This text provides extensive coverage of ADO.NET technology
including ADO.NET internals, namespaces, classes, and
interfaces, and takes a comprehensive look at XML
namespaces and classes, and how to integrate both with
ADO.NET.
Table of Contents
Applied ADO.NETBuilding Data-Driven Solutions
Introduction
Chapter 1 - ADO.NET Basics
Chapter 2 - Data Components in Visual Studio .NET
Chapter 3 - ADO.NET in Disconnected Environments
Chapter 4 - ADO.NET in Connected Environments
Figure 15-10: Result of the Fill method in a DataGrid
Chapter 5 - Handling ADO.NET Events
Chapter 6 VS
Actually, - Integrating
.NET takesXML with
away a ADO.NET
lot of the WSDL, proxy, and discovery file coding so that you can
Chapter 7 - Data Binding and Windows
concentrate on what you do best: coding Forms
theData-Bound
service. TheControls
truth is that without knowing anything about
Chapter
SOAP, 8XML,
- Constraints and Data
or even HTTP, you Relations
were able to develop this Web service. In the next section you'll create a
Chapter 9 - ADO.NET
Web service Exception
for entering Handling
an order into the database using this knowledge and what you know about
ADO.NET.
Chapter 10 - Working with the ODBC .NET Data Provider
Chapter 11 - Stored Procedures and Views
Create a Web application project using VS .NET, or you can use the same client you used to test the
GetOrderFromDatabase method. Create a new project called AddOrderClientApp.
The next step is to add a reference to the Web service by right-clicking the References node of a project in
the Solution Explorer and clicking the Add Web Reference option.
Note If you're using the same client application you used last time, you need to remove the
namespace and then add it again by using Add Web Reference option to get the latest updated
Web service contents.
Again, follow the same steps as in the last example. Type the URL of your service in the Address text box
and click the Add Reference button, which adds localhost (or YourRemoverServer if you're not using
the default localhost as Web server) namespace to the project. The Add Reference option also generates
the*.disco,*.wsdl,AppliedandADO.NET: Building
proxy files. Now youData-Driven Solutions
can call your Web service. Add some controls to the
by Mahesh Chand and David Talbot
page to make it look like Figure 15-12. We added six edit boxes ISBN:1590590732
to accept the order date, name, address,
Apress 2003 (928 pages)
city, country, and zip of a customer. The Enter Order button submits the order to the service.
This text provides extensive coverage of ADO.NET technology
including ADO.NET internals, namespaces, classes, and
interfaces, and takes a comprehensive look at XML
namespaces and classes, and how to integrate both with
ADO.NET.
Table of Contents
Applied ADO.NETBuilding Data-Driven Solutions
Introduction
Chapter 1 - ADO.NET Basics
Chapter 2 - Data Components in Visual Studio .NET
Chapter 3 - ADO.NET in Disconnected Environments
Chapter 4 - ADO.NET in Connected Environments
Chapter 5 - Handling ADO.NET Events
Chapter 6 - Integrating XML with ADO.NET
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
Chapter 8 - Constraints and Data Relations
Chapter 9 - ADO.NET Exception Handling
Chapter 10 - Working with the ODBC .NET Data Provider
Chapter 11 - Stored Procedures and Views
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Chapter 13 - Developing a Custom Data Provider
Chapter 14 - 15-12:
Figure Developing Database
Design Web
View of theApplications using entry
order customer ASP.NET
Web service
Chapter 15 - Using ADO.NET in Xml Web Services
Again, double-click
Chapter 16 - ASP.NETthe Enter
Server Order button
Controls and
and Data use the code in Listing 15-5 to populate the order array and
Binding
pass it 17
Chapter to the Web service.
- Building TheWeb
Real-World EnterApplications
Order button event handler looks like Listing 15-5.
Chapter 18 - Object-Relational Mapping in .NET
Listing 15-5: Client Event Handler for Executing the Web Service
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
Chapter 20 - COM Interoperability and ADO.NET
Private
Chapter 21 -Sub Button1_Click(ByVal sender As System.Object, _
Messaging
ByVal
Chapter 22 -eSQL
AsServer
System.EventArgs)
and ADO.NET: NotesHandles Button1.Click
on Performance
Appendix A - Relational Databases: Some Basic Concepts
Dim
Appendix B -orderData()
Commonly Used As
SQL String = New String(6) {}
Statements
orderData(0) = TextBox1.Text
Appendix C - ADO.NET Frequently Asked Questions
orderData(1) = TextBox2.Text
Index
orderData(3) = TextBox4.Text
List of Figures
orderData(4) = TextBox5.Text
List of Tables
orderData(5) = TextBox6.Text
List of Listings
' Create Web serice instalce and call InsertOrder
List of Sidebars
Dim myWebService As localhost.Service1 = New localhost.Service1()
myWebService.InsertOrder(orderData)
End Sub
The button event handler assigns a string array with information typed into the order form. You can create
an instance of the service by direct using mcb.Service1 and calling the InsertOrder method.
Now build and run the application. The output looks like Figure 15-13. Now you enter customer data and
clicking the Enter Order button adds the data to the Orders table.
Applied ADO.NET: Building Data-Driven Solutions
by Mahesh Chand and David Talbot ISBN:1590590732
Apress 2003 (928 pages)
This text provides extensive coverage of ADO.NET technology
including ADO.NET internals, namespaces, classes, and
interfaces, and takes a comprehensive look at XML
namespaces and classes, and how to integrate both with
ADO.NET.
Table of Contents
Applied ADO.NETBuilding Data-Driven Solutions
Introduction
Chapter 1 - ADO.NET Basics
Chapter 2 - Data Components in Visual Studio .NET
Chapter 3 - ADO.NET in Disconnected Environments
Chapter 4 - 15-13:
Figure ADO.NET in Connected
Adding an orderEnvironments
to the database using Enter Order
Chapter 5 - Handling ADO.NET Events
Chapter 6 - Integrating XML with ADO.NET
Adding- Data
Chapter 7More Functionality
Binding toData-Bound
and Windows Forms the Web Service
Controls
Chapter 8 - Constraints and Data Relations
Now you've
Chapter got a pretty
9 - ADO.NET good idea
Exception of how to develop a Web service and consume it in client applications.
Handling
What else
Chapter 10 -can a database
Working with theWeb service
ODBC do? When
.NET Data it comes to databases, the only thing you can do is
Provider
retrieve,
Chapter 11add, update,
- Stored and delete
Procedures anddata.
ViewsEarlier in this chapter, you saw how to retrieve and add data to a
data source through Web service methods.
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Chapter
Now you13just
- Developing a Custom
need to add Data Provider
functionality to update and delete data and you'll have a complete database
Chapter 14 -
Web service.Developing Database Web Applications using ASP.NET
Chapter 15 - Using ADO.NET in Xml Web Services
Actually,
Chapter 16updating and
- ASP.NET deleting
Server data and
Controls is pretty
Data simple.
Binding What you need to do is just create a new method for
the Web
Chapter 17service, which
- Building executes
Real-World SQL
Web statements. In the client application, you need to get data from the
Applications
users, construct
Chapter SQL UPDATE
18 - Object-Relational and DELETE
Mapping in .NETstatements, and then send this statement as a string to the
Web service
Chapter and letObjects:
19 - Mapped the WebPerformance
service execute the SQL statement.
Considerations and Data Binding
Chapter
Listing 20 - COM
15-6 Interoperability
shows a method that and ADO.NET
executes a SQL statement by creating a SqlCommand and calling the
Chapter 21 - Messaging
ExecuteNonQuery method.
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Listing 15-6:
Appendix ExecuteQuery
A - Relational Method
Databases: Some Basic Concepts
Appendix B - Commonly Used SQL Statements
Appendix C - ADO.NET
' SaveChanges Frequently
method AskedaQuestions
saves DataSet
Index<WebMethod(Description:="Exceute SQL Statement")> _
List of Figures
Public Function ExecuteQuery(ByVal sql As String) As Integer
List of Tables
Dim affectedRows As Integer = 0
List of Listings
' Open connection if already not open
If conn.State <> ConnectionState.Open Then
List of Sidebars
conn.Open()
End If
' Create a SqlCommand and execute it
Dim cmd As SqlCommand = New SqlCommand()
cmd.Connection = conn
cmd.CommandText = sql
affectedRows = cmd.ExecuteNonQuery()
' Close and dispose connection
If conn.State = ConnectionState.Open Then
conn.Close()
End If
Return affectedRows
Applied ADO.NET: Building Data-Driven Solutions
End Function
by Mahesh Chand and David Talbot ISBN:1590590732
Apress 2003 (928 pages)
This text provides extensive coverage of ADO.NET technology
including ADO.NET internals, namespaces, classes, and
interfaces, and takes a comprehensive look at XML
namespaces and classes, and how to integrate both with
ADO.NET.
Table of Contents
Applied ADO.NETBuilding Data-Driven Solutions
Introduction
Chapter 1 - ADO.NET Basics
Chapter 2 - Data Components in Visual Studio .NET
Chapter 3 - ADO.NET in Disconnected Environments
Chapter 4 - ADO.NET in Connected Environments
Chapter 5 - Handling ADO.NET Events
Chapter 6 - Integrating XML with ADO.NET
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
Chapter 8 - Constraints and Data Relations
Chapter 9 - ADO.NET Exception Handling
Chapter 10 - Working with the ODBC .NET Data Provider
Chapter 11 - Stored Procedures and Views
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Chapter 13 - Developing a Custom Data Provider
Chapter 14 - Developing Database Web Applications using ASP.NET
Chapter 15 - Using ADO.NET in Xml Web Services
Chapter 16 - ASP.NET Server Controls and Data Binding
Chapter 17 - Building Real-World Web Applications
Chapter 18 - Object-Relational Mapping in .NET
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
Chapter 20 - COM Interoperability and ADO.NET
Chapter 21 - Messaging
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Appendix A - Relational Databases: Some Basic Concepts
Appendix B - Commonly Used SQL Statements
Appendix C - ADO.NET Frequently Asked Questions
Index
List of Figures
List of Tables
List of Listings
List of Sidebars
Summary Applied ADO.NET: Building Data-Driven Solutions
by Mahesh Chand and David Talbot ISBN:1590590732
In this chapter you learned
Apress what
2003 (928apages)
Web service is and how you can set it up to perform services on the
World Wide Web.This Youtext
worked through a tutorial
provides extensive for creating
coverage a simple
of ADO.NET Web service for retrieving an order
technology
using ADO.NET and ASP.NET. You then created a Web service
including ADO.NET internals, namespaces, classes, and that allowed you to enter a customer for
interfaces,
the order using XML and takesIn
and ADO.NET. a the
comprehensive
end, you saw look at XML
how to update and delete data from a database
namespaces
through a Web service. Usingandtheclasses, and how to integrate
same methodology, you canboth with Web services, which can
develop
ADO.NET.
implement data access functionality for your clients. The next chapter covers data binding in ASP.NET.
You'll see how to use different Web server controls in data binding operations. This chapter is based on
real-world
Table usage of Web server data-bound controls. So, you'll learn a lot of good stuff that you can use in
of Contents
your applications.
Applied ADO.NETBuilding Data-Driven Solutions
Introduction
Chapter 1 - ADO.NET Basics
Chapter 2 - Data Components in Visual Studio .NET
Chapter 3 - ADO.NET in Disconnected Environments
Chapter 4 - ADO.NET in Connected Environments
Chapter 5 - Handling ADO.NET Events
Chapter 6 - Integrating XML with ADO.NET
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
Chapter 8 - Constraints and Data Relations
Chapter 9 - ADO.NET Exception Handling
Chapter 10 - Working with the ODBC .NET Data Provider
Chapter 11 - Stored Procedures and Views
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Chapter 13 - Developing a Custom Data Provider
Chapter 14 - Developing Database Web Applications using ASP.NET
Chapter 15 - Using ADO.NET in Xml Web Services
Chapter 16 - ASP.NET Server Controls and Data Binding
Chapter 17 - Building Real-World Web Applications
Chapter 18 - Object-Relational Mapping in .NET
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
Chapter 20 - COM Interoperability and ADO.NET
Chapter 21 - Messaging
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Appendix A - Relational Databases: Some Basic Concepts
Appendix B - Commonly Used SQL Statements
Appendix C - ADO.NET Frequently Asked Questions
Index
List of Figures
List of Tables
List of Listings
List of Sidebars
Chapter Applied
16: ASP.NET Server Controls
ADO.NET: Building Data-Driven Solutions
by Mahesh Chand and David Talbot
and Data
ISBN:1590590732
Now, simply double-click the Button and LinkButton controls. This action adds button click event
handlers. Use the ImageUrl property of ImageButton to set an image for the ImageButton control.
Listing 16-1 shows the code of the button click event handlers for the Button and LinkButton controls.
If you click the Load Image button, the output looks like Figure 16-2.
Table of Contents
Applied ADO.NETBuilding Data-Driven Solutions
Introduction
Chapter 1 - ADO.NET Basics
Chapter 2 - Data Components in Visual Studio .NET
Chapter 3 - ADO.NET in Disconnected Environments
Chapter 4 - ADO.NET in Connected Environments
Chapter 5 - Handling ADO.NET Events
Chapter 6 - Integrating XML with ADO.NET
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
Chapter 8 - Constraints and Data Relations
Chapter 9 - ADO.NET Exception Handling
Chapter 10 - Working with the ODBC .NET Data Provider
Chapter 11 - Stored Procedures and Views
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Chapter 13 - Developing a Custom Data Provider
Figure 16-2: Loading an image in an ImageButton control
Chapter 14 - Developing Database Web Applications using ASP.NET
Chapter 15 - Using ADO.NET in Xml Web Services
Chapter 16 - ASP.NET Server Controls and Data Binding
Using the Calendar Control
Chapter 17 - Building Real-World Web Applications
Chapter 18 - Object-Relational Mapping in .NET
TheCalendar control, represented by the Calendar class, displays a one-month calendar. A calendar
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
on Web pages allows users to view and select dates such as in an airline reservation application. The
Chapter 20 - control
Calendar COM Interoperability
displays and and ADO.NET
selects dates, but it can also display appointments and other information.
Chapter 21 - Messaging
TheCalendar
Chapter 22 - SQL control
Server is
andbased on theNotes
ADO.NET: DataTime data type of the .NET Framework, which displays any
on Performance
date between
Appendix the years
A - Relational 0 and 9999
Databases: A.D.
Some Basic Concepts
Appendix B - Commonly Used SQL Statements
Note In VB .NET, the Date data type is equivalent to the .NET Framework's DateTime data type.
Appendix C - ADO.NET Frequently Asked Questions
Index
To create a Calendar control, you simply drag a Calendar control from the Toolbox to the Web page.
List of Figures
After that, if you run the application, it displays the current month and provides options to move to the next
List
andofprevious
Tables months by default.
List of Listings
The
List of default
Sidebarsmonth for the Calendar control is the month of today's date represented by the
TodaysDate property. If you want to change the starting month of a Calendar control, you can use the
VisibleDate property. For example, the following line sets the visible month of a Calendar control to
January 2002:
After adding a Calendar control to a Web page, add a button called SelectedDate and write the code
inListing 16-2 on this button's click event.
Table of Contents
Applied ADO.NETBuilding Data-Driven Solutions
Introduction
Chapter 1 - ADO.NET Basics
Chapter 2 - Data Components in Visual Studio .NET
Chapter 3 - ADO.NET in Disconnected Environments
Chapter 4 - ADO.NET in Connected Environments
Chapter 5 - Handling ADO.NET Events
Chapter 6 - Integrating XML with ADO.NET
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
Chapter 8 - Constraints and Data Relations
Chapter 9 - ADO.NET Exception Handling
Chapter 10 - Working with the ODBC .NET Data Provider
Chapter 11 - Stored Procedures and Views
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Chapter 13 - Developing a Custom Data Provider
Figure 16-3: TheCalendar control in action
Chapter 14 - Developing Database Web Applications using ASP.NET
Chapter 15 - Using ADO.NET in Xml Web Services
Chapter 16 - ASP.NET Server Controls and Data Binding
Understanding Web Server Control Templates
Chapter 17 - Building Real-World Web Applications
Chapter 18 - Object-Relational Mapping in .NET
Before discussing more controls, we'll first cover templates. Templates play a major role in managing the
Chapter 19 -format
layout and MappedofObjects:
the dataPerformance Considerations
being displayed in ASP.NETanddata-bound
Data Binding
controls. You'll apply templates on
Chapter 20 - COM Interoperability and ADO.NET
various data-bound controls in this chapter. Before using templates, though, let's quickly look at template
Chapter 21 - how
basics and Messaging
they work.
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Templates
Appendix A - provide a way
Relational to applySome
Databases: complex
Basicformatting
Concepts to a control's parts such as the header, footer, and
items (text
Appendix B -being displayed
Commonly Usedby theStatements
SQL control). A template is a set of HTML tags that define the layout for a
particular
Appendix C part of a control.
- ADO.NET Besides
Frequently HTML
Asked tags, a template can also contain other controls and ASP.NET
Questions
inline code.
Index
List
ForofaFigures
better understanding, let's take a look at a simple use of templates. Listing 16-5 uses templates in a
List of Tables control. As you can see, this listing uses the AlternatingItemTemplate and
Repeater
List of Listings
ItemTemplate templates. (We discuss the different types of templates in the following section.)
List of Sidebars
Specifically, AlternatingItemTemplate, sets the font color to red, the font face to Verdana, and the
font size to 3. ItemTemplate sets the font color to green, the font face to Tahoma, and the font size to 2.
The listing also uses the HTML Table control to display items. As you probably can guess from this code,
the items of a Repeater control will have a green color, the font face Tahoma with a size of 2. Alternating
rows and their items will have the color red, the face Verdana, and a size of 3.
<FooterTemplate>
<font color= #996600 face ="verdana" size = 1>
Applied
DataList Control ADO.NET: Building Data-Driven Solutions
footer
</font> by Mahesh Chand and David Talbot ISBN:1590590732
Apress
</FooterTemplate> 2003 (928 pages)
This text provides extensive coverage of ADO.NET technology
including ADO.NET internals, namespaces, classes, and
interfaces, and takes a comprehensive look at XML
namespaces and classes, and how to integrate both with
Note You may have noticed a line containing DataBinder and other syntaxes. You'll learn about this
ADO.NET.
in the following sections.
Creating
Table Templates
of Contents Using the Form Designer
Applied ADO.NETBuilding Data-Driven Solutions
Besides using the HTML View, you can create templates in VS .NET by using the form designer. You
Introduction
simply 1drag
Chapter the control
- ADO.NET onto an ASP.NET page and right-click the control. For example, if you drag a
Basics
2 - control
DataList
Chapter and right-click
Data Components it, you'll
in Visual see.NET
Studio the Edit Template menu item. The Edit Template menu item
has three
Chapter 3 submenu
- ADO.NETitems: Header and
in Disconnected Footer Templates, Item Templates, and Separator Templates.
Environments
Clicking any
Chapter 4
of these menu items opens the form designer.
- ADO.NET in Connected Environments
Chapter 5 - Handling
Once you're ADO.NET
in the form Events
designer, you can enter HTML text and drop HTML or ASP.NET controls onto a
Chapter 6 - Integrating XML with ADO.NET
data-bound control. You'll see how to use the form designer with data binding in the following sections.
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
Tip8The
Chapter Auto Format
- Constraints andoption of data-bound controls lets you select a format of the control from
Data Relations
predefined formats.
Chapter 9 - ADO.NET Exception Handling
Chapter 10 - Working with the ODBC .NET Data Provider
Working with Templates Programmatically
Chapter 11 - Stored Procedures and Views
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
So far you've seen two methods for creating templates: using an HTML editor and the VS .NET IDE. Both
Chapter 13 - Developing
of the methods a Custom
force you to writeData
codeProvider
in an .aspx file at design-time. What if you're not sure what format
Chapter 14 - Developing Database Web Applications usingan
of template you want to create, or you want to create ASP.NET
application where users can pick the format of
Chapter 15 - Using ADO.NET in Xml Web Services
template?
Chapter 16 - ASP.NET Server Controls and Data Binding
There are
Chapter 17 -two ways Real-World
Building to accomplish
Webthis. The first way is to provide prebuilt templates similar to the Auto
Applications
Format18
Chapter option that the DataGrid
- Object-Relational control
Mapping provides. In this method, you create and save the layout of the
in .NET
templates with an .ascx extension and load the file using the LoadTemplate method of the Page
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
object. The second way is to create templates in memory based on the user selection.
Chapter 20 - COM Interoperability and ADO.NET
Chapter 21 - Messaging
Using the Repeater Control
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Appendix A - Relational Databases: Some Basic Concepts
TheRepeater control is a data-bound container control that produces a list of individual items of a data
Appendix B - Commonly Used SQL Statements
source. By default the Repeater control doesn't support any style, formatting, or layout. To provide a
Appendix C - ADO.NET Frequently Asked Questions
layout to a Repeater control, you define the layout of individual items on a Web page using templates. If
Index
there's no template specified, the control does not appear on a Web page. The Repeater control
List of Figures
supportsHeaderTemplate,FooterTemplate,ItemTemplate,AlternatingItemTemplate, and
List of Tables
SeparatorTemplate, as described in Table 16-3.
List of Listings
List of Sidebars
Table 16-3: Templates Supported by the Repeater Control
TEMPLATE DESCRIPTION
Applied ADO.NET: Building Data-Driven Solutions
by Mahesh Chand and David Talbot ISBN:1590590732
ItemTemplate Elements that are rendered once for each row in the data
Apress 2003 (928 pages)
source.
This text provides extensive coverage of ADO.NET technology
including ADO.NET internals,
AlternatingItemTemplate Like the namespaces,
ItemTemplateclasses, and but rendered for every
element,
interfaces, and takes other
a comprehensive look at XMLcontrol. You can specify a different
row in the Repeater
namespaces and classes, and how to integrate both with
ADO.NET. look for the AlternatingItemTemplate element by
setting its style properties.
HeaderTemplate
Table of Contents Header elements.
Applied ADO.NETBuilding Data-Driven Footer
FooterTemplate Solutions
elements.
Introduction
SeparatorTemplate
Chapter 1 - ADO.NET Basics
Elements to render between each row, such as line breaks
(<BR> tags), lines (<HR> tags), or commas.
Chapter 2 - Data Components in Visual Studio .NET
Chapter 3 - ADO.NET in Disconnected Environments
Chapter 4
Creating- ADO.NET in Connected Environments
a Repeater Control
Chapter 5 - Handling ADO.NET Events
Chapter 6 - Integrating
Unlike other Web serverXML with ADO.NET
controls, the Repeater control doesn't have much design-time support from the
Chapter 7 - Data Binding and Windows Formsonto
IDE. You can only drag and drop a control Data-Bound
the pageControls
and set its data-binding and data source
properties.
Chapter 8 - Everything
Constraintselse
and you
Datahave to do manually in the HTML View of the editor.
Relations
Chapter 9 - ADO.NET Exception Handling
The best way to create a Repeater control is to just use the HTML syntax. For example, the following
Chapter 10 - Working with the ODBC .NET Data Provider
code creates a simple Repeater control with three templates:
Chapter 11 - Stored Procedures and Views
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
<ASP:Repeater
Chapter id="repeaterControl"
13 - Developing a Custom Data Provider runat="server">
<HeaderTemplate>
Chapter 14 - Developing Database Web Applications using ASP.NET
</HeaderTemplate>
Chapter 15 - Using ADO.NET in Xml Web Services
<ItemTemplate>
Chapter 16 - ASP.NET Server Controls and Data Binding
</ItemTemplate>
Chapter 17 - Building Real-World Web Applications
<FooterTemplate>
Chapter 18 - Object-Relational Mapping in .NET
</FooterTemplate>
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
</ASP:Repeater>
Chapter 20 - COM Interoperability and ADO.NET
Chapter 21 - Messaging
Data Binding
Chapter and and
22 - SQL Server theADO.NET:
Repeater Control
Notes on Performance
Appendix A - Relational Databases: Some Basic Concepts
TheDataSource
Appendix property
B - Commonly Used of
SQLtheStatements
Repeater control binds data to the control. Like other controls, you can
assign any
Appendix C - data source
ADO.NET that implements
Frequently the IEnumerable interface. Some of the valid data sources are
Asked Questions
DataSet,DataView, and an Array. The syntax for binding the controls to the Repeater control uses
Index
"Container" as the data source because the Repeater is the container for all the controls. The
List of Figures
following code binds the CategoryID column of a DataSource:
List of Tables
List of Listings
<%#
List DataBinder.Eval(Container.DataItem, "CategoryID") %>
of Sidebars
Note You can't bind controls in the header, footer, and separator templates using
DataBinder.Eval expressions in HTML View.You must bind these controls in the code. Like
other data-bound controls, you must call the DataBind method of the control to get the records
to be displayed.
Table
<%@ ofImport
Contents
Namespace="System.Data" %>
Applied ADO.NETBuilding Data-Driven Solutions
<%@ Import Namespace="System.Data.SqlClient" %>
Introduction
<HTML>
Chapter
<script1 -language="VB"
ADO.NET Basics runat="server">
Chapter 2 - Data Components As
Sub Page_Load(sender in Visual Studio e
Object, .NET
As EventArgs)
Dim conn
Chapter As SqlConnection
3 - ADO.NET in Disconnected Environments
Dim adapter
Chapter As SqlDataAdapter
4 - ADO.NET in Connected Environments
dim connectionString
Chapter 5 - Handling ADO.NET=Events
_
"Data6 Source=MCB;Initial
Chapter Catalog=Northwind;user id=sa;password=;"
- Integrating XML with ADO.NET
conn =
Chapter 7 new SqlConnection(connectionString)
- Data Binding and Windows Forms Data-Bound Controls
conn.Open()
Chapter 8 - Constraints and Data Relations
dim sql = "SELECT * FROM Categories"
Chapter 9 - ADO.NET Exception Handling
adapter = new SqlDataAdapter(sql, conn)
Chapter 10 - Working with the ODBC .NET Data Provider
Dim ds As Dataset = new DataSet()
Chapter 11 - Stored Procedures and Views
adapter.Fill(ds)
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
repeaterControl.DataSource = ds
Chapter 13 - Developing a Custom Data Provider
repeaterControl.DataBind()
Chapter
End14Sub - Developing Database Web Applications using ASP.NET
Chapter
</script>15 - Using ADO.NET in Xml Web Services
Chapter
<body> - ASP.NET Server Controls and Data Binding
16
Chapter
<P> 17 - Building Real-World Web Applications
Chapter 18 - Object-Relational
<ASP:Repeater Mapping in .NET
id="repeaterControl" runat="server">
<HeaderTemplate>
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
<Table
Chapter 20 width="100%" style="font:
- COM Interoperability and ADO.NET 8pt verdana">
<tr style="background-color:DFA894">
Chapter 21 - Messaging
<th>CategoryID</th>
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
<th>CategoryName</th>
Appendix A - Relational Databases: Some Basic Concepts
<th>Description</th>
Appendix B - Commonly Used SQL Statements
<th>Picture</th>
Appendix C - ADO.NET Frequently Asked Questions
</tr>
Index
</HeaderTemplate>
List of Figures
<ItemTemplate>
List of Tables
<tr style="background-color:FFECD8">
List
<td>of Listings
List
<%# Sidebars
of DataBinder.Eval(Container.DataItem, "CategoryID") %>
</td>
<td>
<%# DataBinder.Eval(Container.DataItem, "CategoryName") %>
</td>
<td>
<%# DataBinder.Eval(Container.DataItem, "Description") %>
</td>
<td>
<%# DataBinder.Eval(Container.DataItem, "Picture") %>
</td>
</tr>
</ItemTemplate>
Applied ADO.NET: Building Data-Driven Solutions
<FooterTemplate>
by Mahesh Chand and David Talbot
</FooterTemplate> ISBN:1590590732
Apress
</ASP:Repeater></P> 2003 (928 pages)
</body> This text provides extensive coverage of ADO.NET technology
</HTML> including ADO.NET internals, namespaces, classes, and
interfaces, and takes a comprehensive look at XML
namespaces and classes, and how to integrate both with
ADO.NET.
See the help topic "Standard Numeric Format Strings" in the documentation for more details on these
formats.
Table of Contents
Applied ADO.NETBuilding Data-Driven Solutions
Introduction
Chapter 1 - ADO.NET Basics
Chapter 2 - Data Components in Visual Studio .NET
Chapter 3 - ADO.NET in Disconnected Environments
Chapter 4 - ADO.NET in Connected Environments
Figure 16-4: Using a ListBox Web server control
Chapter 5 - Handling ADO.NET Events
Chapter 6 - Integrating XML with ADO.NET
The Load
Chapter 7 -Data
Databutton
Bindingclick
andreads dataForms
Windows from Data-Bound
the Northwind database and binds data to the ListBox
Controls
control.8The
Chapter Get Selected
- Constraints andItem
Databutton click returns the selected item. Listing 16-9 shows the code for both
Relations
button click
Chapter event handlers.
9 - ADO.NET Exception Handling
Chapter 10 - Working with the ODBC .NET Data Provider
Listing 16-9: Data Binding in ListBox Control
Chapter 11 - Stored Procedures and Views
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Private
Chapter 13 -Sub LoadDataBtn_Click(ByVal
Developing a Custom Data Provider sender As System.Object, _
ByVal
Chapter 14 -eDeveloping
As System.EventArgs) Handles
Database Web Applications usingLoadDataBtn.Click
ASP.NET
ChapterDim
15 -conn As SqlConnection
Using ADO.NET = Nothing
in Xml Web Services
Dim adapter As SqlDataAdapter = Nothing
Chapter 16 - ASP.NET Server Controls and Data Binding
Dim reader As SqlDataReader = Nothing
Chapter 17 - Building Real-World Web Applications
Dim cmd As SqlCommand = Nothing
Chapter 18 - Object-Relational Mapping in .NET
Dim connectionString = _
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
"Data Source=MCB;Initial Catalog=Northwind;user id=sa;password=;"
Chapter 20 - COM Interoperability and ADO.NET
conn = New SqlConnection(connectionString)
Chapterconn.Open()
21 - Messaging
ChapterDim22 -sql
SQL Server and ADO.NET:
= "SELECT * FROM Notes on Performance
Products"
Appendix A - Relational
' Use DataSet Databases: Some Basic Concepts
Appendix B - Commonly
adapter = NewUsed SQL Statements
SqlDataAdapter(sql, conn)
Appendix C - ADO.NET
Dim ds As Frequently
DataSetAsked Questions
= New DataSet()
Index adapter.Fill(ds)
ListBox1.DataSource = ds
List of Figures
ListBox1.DataTextFormatString = "Unit Price: {0:C}"
List of Tables
ListBox1.DataTextField = "UnitPrice"
List of Listings
ListBox1.DataBind()
List of Sidebars
End Sub
As you can see from this listing, it simply creates and fills a DataSet and sets the DataSource property
of the ListBox control to DataSet. It also sets the DataTextField and DataTextFormatString
properties of the ListBox control. DataTextField is the name of the table column, which you want to
Applied ADO.NET: Building Data-Driven Solutions
display in the control. This sample displays the UnitPrice column's data from the Products table. Format
by Mahesh
the data so it displays Chandformat
in currency and David Talbotthe DataTextFormatString
by using ISBN:1590590732
property.
Apress 2003 (928 pages)
If you run the application
This text and load extensive
provides the data, the outputoflooks
coverage like Figure
ADO.NET 16-5. As you can see from this
technology
including
figure, the data displays inADO.NET
currencyinternals,
format. namespaces, classes, and
interfaces, and takes a comprehensive look at XML
namespaces and classes, and how to integrate both with
ADO.NET.
Table of Contents
Applied ADO.NETBuilding Data-Driven Solutions
Introduction
Chapter 1 - ADO.NET Basics
Chapter 2 - Data Components in Visual Studio .NET
Chapter 3 - ADO.NET in Disconnected Environments
Chapter 4 - ADO.NET in Connected Environments
Chapter 5 - Handling ADO.NET Events
Chapter 6 - Integrating XML with ADO.NET
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
Chapter 8 - Constraints and Data Relations
Chapter 9 - ADO.NET Exception Handling
Chapter 10 - Working with the ODBC .NET Data Provider
Chapter 11 - Stored Procedures and Views
Figure 16-5: Data binding in a ListBox control
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Chapter 13 - Developing a Custom Data Provider
Chapter 14 - Developing Database Web Applications using ASP.NET
Using the DropDownList Control
Chapter 15 - Using ADO.NET in Xml Web Services
Chapter 16 - ASP.NET Server
TheDropDownList controlControls
is a list and Datawhich
control, Binding
displays only the selected data. However, all data
Chapter 17 - Building Real-World Web Applications
items are available when you drop the control. Data binding in the DropDownList control works in the
Chapter 18 -as
same way Object-Relational
in the ListBoxMapping
control.inYou
.NET
simply set the DataSource,DataMember, and
Chapter 19 - Mappedproperties
DataTextField Objects: Performance
and call theConsiderations and Data
control's DataBind Binding
method.
Chapter 20 - COM Interoperability and ADO.NET
Note
Chapter 21 Data binding works in a similar way with the CheckBoxList and RadioButtonList controls,
- Messaging
Chapter 22 too. You
- SQL just need
Server to set theNotes
and ADO.NET: DataSource and DataTextField properties and call the
on Performance
- Relational method.
Appendix A DataBind Databases: Some Basic Concepts
Appendix B - Commonly Used SQL Statements
Let's create a similar application as in the last sample. To make the application little more interactive, add
Appendix C - ADO.NET Frequently Asked Questions
oneCheckBox control to the page, as shown in Figure 16-6. As you can see from this figure, when you
Index
check the Use DataReader check box, the Load Data button click reads data in a SqlDataReader and
List of Figures
binds it with the DropDownList control; otherwise it uses the DataSet.
List of Tables
List of Listings
List of Sidebars
Figure 16-6: Data binding in a DropDownList control
Applied ADO.NET: Building Data-Driven Solutions
by Mahesh
Listing 16-10 shows Chand
the code and
for the David
Load Talbot
Data ISBN:1590590732
and Get Selected Item button click event handlers. As you
Apress
can see, it binds the 2003 (928 pages)
CategoryName column of the Categories table to the control.
This text provides extensive coverage of ADO.NET technology
Listing 16-10: Data Binding
including in a DropDownList
ADO.NET Control
internals, namespaces, classes, and
interfaces, and takes a comprehensive look at XML
namespaces and classes, and how to integrate both with
ADO.NET.
Private Sub LoadDataBtn_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles LoadDataBtn.Click
Dim conn As SqlConnection = Nothing
Table of Contents
Dim adapter As SqlDataAdapter = Nothing
AppliedDim
ADO.NETBuilding Data-Driven Solutions
reader As SqlDataReader = Nothing
Introduction
Dim cmd As SqlCommand = Nothing
ChapterDim
1 -connectionString
ADO.NET Basics = _
Chapter"Data
2 - Data Components in Visual Studio
Source=MCB;Initial .NET
Catalog=Northwind;user id=sa;password=;"
Chapterconn
3 - ADO.NET in Disconnected Environments
= New SqlConnection(connectionString)
Chapterconn.Open()
4 - ADO.NET in Connected Environments
ChapterDim
5 -sql = "SELECT
Handling * FROM Categories"
ADO.NET Events
ChapterIf
6 CheckBox1.Checked Then
- Integrating XML with ADO.NET
Chapter 7 ' -Use
Data DataReader
Binding and Windows Forms Data-Bound Controls
Chapter 8 cmd = New SqlCommand(sql,
- Constraints and Data Relations conn)
reader = cmd.ExecuteReader()
Chapter 9 - ADO.NET Exception Handling
DropDownList1.DataSource = reader
Chapter 10 - Working with the ODBC .NET Data Provider
DropDownList1.DataTextField = "CategoryName"
Chapter 11 - Stored Procedures and Views
DropDownList1.DataBind()
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
If Not reader.IsClosed Then
Chapter 13 - Developing a Custom Data Provider
reader.Close()
Chapter 14 - Developing Database Web Applications using ASP.NET
End If
ChapterElse
15 - Using ADO.NET in Xml Web Services
Chapter 16' -Use
ASP.NET Server Controls and Data Binding
DataSet
Chapter 17 - Building Real-World Web Applications
adapter = New SqlDataAdapter(sql, conn)
Chapter 18 - Object-Relational
Dim ds As DataSet Mapping in .NET
= New DataSet()
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
adapter.Fill(ds)
Chapter 20 - COM Interoperability and ADO.NET
DropDownList1.DataSource = ds
Chapter 21DropDownList1.DataTextField
- Messaging = "CategoryName"
Chapter 22DropDownList1.DataBind()
- SQL Server and ADO.NET: Notes on Performance
End
Appendix A -If
Relational Databases: Some Basic Concepts
End Sub
Appendix B - Commonly Used SQL Statements
Appendix C - ADO.NET Frequently Asked Questions
Index
Private Sub GetSelItem_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles GetSelItem.Click
List of Figures
Label1.Text = "Selected Item: " & _
List of Tables
DropDownList1.SelectedItem.Value
List of Listings
End Sub
List of Sidebars
Caution When binding data to a TextBox control, you must write the runat="server" syntax after
theText property of these controls; otherwise you'll get the error "TextBox cannot have
children of DataBoundLiteralControl."
Listing 16-11 creates a TextBox,
Applied ADO.NET:a Button, and an ImageSolutions
Building Data-Driven control and binds data from the Employees
table of the Northwind database.
by Mahesh Chand and David Talbot ISBN:1590590732
Apress 2003 (928 pages)
Listing 16-11: Data Binding in the TextBox,Button, and Image Controls
This text provides extensive coverage of ADO.NET technology
including ADO.NET internals, namespaces, classes, and
interfaces, and takes a comprehensive look at XML
<%@ Import Namespace="System.Data" %>
namespaces and classes, and how to integrate both with
<%@ Import Namespace="System.Data.SqlClient"
ADO.NET. %>
<script language="VB" runat=server>
Sub Page_Load(sender As Object, e As EventArgs)
Table of Contents
Dim conn As SqlConnection
Applied ADO.NETBuilding
Dim adapter As Data-Driven Solutions
SqlDataAdapter
Introduction
dim connectionString = _
Chapter 1 "Data Source=MCB;Initial
- ADO.NET Basics Catalog=Northwind;user id=sa;password=;"
conn = new SqlConnection(connectionString)
Chapter 2 - Data Components in Visual Studio .NET
Chapter 3 conn.Open()
- ADO.NET in Disconnected Environments
Chapter 4 dim sql = in"SELECT
- ADO.NET Connected*Environments
FROM Employees"
Chapter 5 - Handling ADO.NET Events = new SqlCommand(sql, conn)
dim cmd as SqlCommand
Dim reader as SqlDataReader = cmd.ExecuteReader()
Chapter 6 - Integrating XML with ADO.NET
repeaterControl.DataSource = reader
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
repeaterControl.DataBind()
Chapter 8 - Constraints and Data Relations
reader.Close()
Chapter 9 - ADO.NET Exception Handling
conn.Close()
Chapter 10 - Working with the ODBC .NET Data Provider
End Sub
Chapter 11 - Stored Procedures and Views
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
</script>
Chapter 13 - Developing a Custom Data Provider
Chapter
<HTML> 14 - Developing Database Web Applications using ASP.NET
Chapter 15 - Using ADO.NETControls
<HEAD><title>Other in Xml Web Services
Data Binding</title></HEAD>
Chapter
<form16id="Form1"
- ASP.NET Server Controls and Data
method="post" Binding
runat="server">
<asp:Repeater
Chapter 17 - Building Real-World Web Applications
id="repeaterControl"
Chapter 18 - Object-Relational Mapping in .NET
runat="server">
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
<ItemTemplate>
Chapter 20 - COM Interoperability and ADO.NET
<asp:Button
Chapter 21 - Messaging
id="Button1"
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Text='<%# Container.DataItem("LastName") %>'
Appendix A - Relational Databases: Some Basic Concepts
runat="server">
Appendix B - Commonly Used SQL Statements
</asp:Button>
Appendix C - ADO.NET Frequently Asked Questions
<asp:TextBox
Index
id="TextBox1"
List of Figures Container.DataItem("Title") %>'
Text='<%#
List of Tables
runat="server">
List of Listings
</asp:TextBox>
List of Sidebars
<asp:Image
id="Image1"
ImageUrl='<%# Container.DataItem("Photo") %>'
runat="server">
</asp:Image>
</ItemTemplate>
</asp:Repeater>
</form>
</HTML>
Applied
Tip If you want to bindADO.NET: Building Data-Driven
data to a LinkButton Solutions
control, just replace asp:Button with
by Mahesh Chand
asp:LinkButton and16-10.
in Listing David Talbot ISBN:1590590732
Apress 2003 (928 pages)
This text provides extensive coverage of ADO.NET technology
including ADO.NET internals, namespaces, classes, and
interfaces, and takes a comprehensive look at XML
namespaces and classes, and how to integrate both with
ADO.NET.
Table of Contents
Applied ADO.NETBuilding Data-Driven Solutions
Introduction
Chapter 1 - ADO.NET Basics
Chapter 2 - Data Components in Visual Studio .NET
Chapter 3 - ADO.NET in Disconnected Environments
Chapter 4 - ADO.NET in Connected Environments
Chapter 5 - Handling ADO.NET Events
Chapter 6 - Integrating XML with ADO.NET
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
Chapter 8 - Constraints and Data Relations
Chapter 9 - ADO.NET Exception Handling
Chapter 10 - Working with the ODBC .NET Data Provider
Chapter 11 - Stored Procedures and Views
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Chapter 13 - Developing a Custom Data Provider
Chapter 14 - Developing Database Web Applications using ASP.NET
Chapter 15 - Using ADO.NET in Xml Web Services
Chapter 16 - ASP.NET Server Controls and Data Binding
Chapter 17 - Building Real-World Web Applications
Chapter 18 - Object-Relational Mapping in .NET
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
Chapter 20 - COM Interoperability and ADO.NET
Chapter 21 - Messaging
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Appendix A - Relational Databases: Some Basic Concepts
Appendix B - Commonly Used SQL Statements
Appendix C - ADO.NET Frequently Asked Questions
Index
List of Figures
List of Tables
List of Listings
List of Sidebars
Data Binding in Complex
Applied WebData-Driven
ADO.NET: Building Forms Controls
Solutions
by Mahesh Chand and David Talbot ISBN:1590590732
TheDataList and DataGrid
Apress controls
2003 (928 pages) are complex data-bound controls. These controls are capable of
displaying multiple columns of a data source.
This text provides extensive The DataList
coverage of ADO.NETandtechnology
DataGrid controls share some
common features. including ADO.NET internals, namespaces, classes, and common features.
Before discussing each control, we'll discuss these
interfaces, and takes a comprehensive look at XML
namespaces and classes, and how to integrate both with
Understanding the BaseDataList Class
ADO.NET.
Before discussing the DataList and DataGrid controls, let's take a look at the BaseDataList class.
Table of Contents
TheBaseDataList class is an abstract base class for the DataList and DataGrid controls. Because
Applied
it's an ADO.NETBuilding Data-Driven
abstract base class, Solutions
the functionality defined in this class can only be used through its derived
classes. The class hierarchy is as follows:
Introduction
Chapter 1 - ADO.NET Basics
Chapter 2 - Data Components in Visual Studio .NET
System.Object
Chapter 3 - ADO.NET in Disconnected Environments
System.Web.UI.Control
Chapter 4 System.Web.UI.WebControls.WebControl
- ADO.NET in Connected Environments
Chapter 5 System.Web.UI.WebControls.BaseDataList
- Handling ADO.NET Events
Chapter 6 System.Web.UI.WebControls.DataGrid
- Integrating XML with ADO.NET
Chapter 7 System.Web.UI.WebControls.DataList
- Data Binding and Windows Forms Data-Bound Controls
Chapter 8 - Constraints and Data Relations
Chapter 9 - ADO.NET Exception Handling
Table 16-5 describes the BaseDataList class properties.
Chapter 10 - Working with the ODBC .NET Data Provider
Chapter 11 - Stored Procedures and Views
Table 16-5: The BaseDataList Class Properties
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
PROPERTY
Chapter DESCRIPTION
13 - Developing a Custom Data Provider
Chapter 14 - Developing Database Web Applications using ASP.NET
CellPadding This is the space between a cell and its border. Both get and set.
Chapter 15 - Using ADO.NET in Xml Web Services
CellSpacing
Chapter This
16 - ASP.NET Server is theand
Controls space between
Data Binding two cells. Both get and set.
Chapter 17 - Building Real-World Web Applications
DataKeyField This is the key field in the data source. Both get and set.
Chapter 18 - Object-Relational Mapping in .NET
DataKeys
Chapter This
19 - Mapped Objects: is the collection
Performance of data keys
Considerations and in theBinding
Data form of DataKeyCollection.
Read only.
Chapter 20 - COM Interoperability and ADO.NET
Chapter 21 - Messaging
DataMember This is the data member in a multimember data source. Both get and set.
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
DataSource
Appendix This is the
A - Relational Databases: Somedata source.
Basic Both get and set.
Concepts
Appendix B - Commonly Used
GridLines SQL
This isStatements
the border between the cells is displayed if true; otherwise false.
Appendix C - ADO.NET Frequently Asked
Both get andQuestions
set.
Index
HorizontalAlign
List of Figures
This is the horizontal alignment of a data listing control within its
container.
List of Tables
List of Listings
List of Sidebars
Using the DataKeyCollection Class
TheDataKeyCollection object represents a collection of the key fields in a data source. Both the
DataList and DataGrid controls provide access to the key fields through their DataKeyField
properties.
TheCount property returns the number of items in the collection. The IsReadOnly property returns
true if the items in the collection are read only. If they aren't read only, the value of this property returns
false.
TheIsSynchronized property returns true if the collection is thread safe; otherwise it returns false.
TheItem property gets the item from the collection at the specified index, and the SyncRoot property
returns the objectApplied
used toADO.NET: Building Data-Driven Solutions
synchronize access to the collection.
by Mahesh Chand and David Talbot ISBN:1590590732
TheDataKeyCollection class
Apress 2003 provides two methods: CopyTo and GetEnumerator. The CopyTo
(928 pages)
method copies the contents
This of a collection
text provides extensivetocoverage
an array,ofand the GetEnumerator
ADO.NET technology method creates an
including ADO.NET
IEnumerator-implemented objectinternals, namespaces,
that contains classes,
all key fields andcollection.
in the
interfaces, and takes a comprehensive look at XML
namespaces and classes, and how to integrate both with
Using the DataList Web Server Control
ADO.NET.
TheDataList control represents a data-bound list control that displays items using templates. You can
Table of a
create Contents
DataList control by editing an .aspx file or by using the VS .NET IDE.
Applied ADO.NETBuilding Data-Driven Solutions
Before discussing DataList in more detail, let's look at a simple example. Listing 16-12 binds and
Introduction
displays1 data
Chapter in a DataList
- ADO.NET Basics control from the Categories table of the Northwind database.
Chapter 2 - Data Components in Visual Studio .NET
Listing 16-12: Data Binding in a DataList Control
Chapter 3 - ADO.NET in Disconnected Environments
Chapter 4 - ADO.NET in Connected Environments
<%@ Import
Chapter Namespace="System.Data"
5 - Handling ADO.NET Events %>
<%@ Import
Chapter Namespace="System.Data.SqlClient"
6 - Integrating XML with ADO.NET %>
<HTML>
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
<BODY>
Chapter 8 - Constraints and Data Relations
<font color="#006699" size="4" face="verdana">
Chapter 9 - ADO.NET Exception Handling
DataList Server Control Sample
Chapter 10 - Working with the ODBC .NET Data Provider
</font>
Chapter 11 - Stored Procedures and Views
<script language="VB" runat="server">
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Chapter 13 - Developing a Custom
Sub Page_Load(sender As Data Provider
Object, e As EventArgs)
Chapter 14 - Developing Database
Dim conn As SqlConnection Web Applications using ASP.NET
Chapter
Dim15 adapter
- Using ADO.NET in Xml Web Services
As SqlDataAdapter
Chapter
dim16 connectionString
- ASP.NET Server Controls
= and
_ Data Binding
Chapter 17 - Building
"Data Real-World Web Applications
Source=MCB;Initial Catalog=Northwind;user id=sa;password=;"
Chapter 18 -=Object-Relational
conn Mapping in .NET
new SqlConnection(connectionString)
conn.Open()
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
dim
Chapter 20 sql
- COM= Interoperability
"SELECT * FROM Categories"
and ADO.NET
adapter
Chapter = new SqlDataAdapter(sql, conn)
21 - Messaging
Dim
Chapter 22 ds AsServer
- SQL Dataset = new DataSet()
and ADO.NET: Notes on Performance
adapter.Fill(ds)
Appendix A - Relational Databases: Some Basic Concepts
dtList.DataSource = ds
Appendix B - Commonly Used SQL Statements
dtList.DataBind()
Appendix C - ADO.NET Frequently Asked Questions
End Sub
Index
List of Figures
</script>
List of Tables
<P>
List of Listings
<ASP:DataList
List of Sidebars
id="dtList"
RepeatColumns="1"
RepeatDirection="Horizontal"
runat="server">
<HeaderTemplate>
<FONT face="verdana" color="#cc3333" size="3">
<B>DataList Control Header</B></FONT>
</HeaderTemplate>
<FooterTemplate>
<FONT face="verdana" color="#996600" size="1">
DataList Control footer </FONT>
</FooterTemplate>
Applied ADO.NET: Building Data-Driven Solutions
<ItemTemplate> by Mahesh Chand and David Talbot ISBN:1590590732
Apress 2003
<FONT face="verdana" size="2"> (928 pages)
<BR> This text provides extensive coverage of ADO.NET technology
<B>Category ID: including
</B>ADO.NET internals, namespaces, classes, and
interfaces, and takes a comprehensive look at XML
<%# DataBinder.Eval(Container.DataItem, "CategoryID")
namespaces and classes, and how to integrate both with %>
<BR> ADO.NET.
<B>Category Name: </B>
<%# DataBinder.Eval(Container.DataItem, "CategoryName")%>
Table
<BR> of Contents
Applied ADO.NETBuilding
<B>Description: Data-Driven Solutions
</B>
Introduction
<%# DataBinder.Eval(Container.DataItem, "Description") %>
Chapter
<BR> 1 - ADO.NET Basics
Chapter 2 - Data </B>
<B>Picture: Components in Visual Studio .NET
<%# DataBinder.Eval(Container.DataItem,
Chapter 3 - ADO.NET in Disconnected Environments "Picture") %>
<P> 4 - ADO.NET in Connected Environments
Chapter
<DIV></DIV>
Chapter 5 - Handling ADO.NET Events
</FONT>
Chapter 6 - Integrating XML with ADO.NET
</ItemTemplate>
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
Chapter 8 - Constraints and Data Relations
</ASP:DataList>
Chapter 9 - ADO.NET Exception Handling
</P>
Chapter 10 - Working with the ODBC .NET Data Provider
</BODY>
Chapter 11 - Stored Procedures and Views
</HTML>
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Chapter 13 - Developing a Custom Data Provider
Chapter 14 - Developing Database Web Applications using ASP.NET
Chapter 15 - of
The output Using ADO.NET
Listing 16-12 inlooks
Xml like
WebFigure
Services
16-7.
Chapter 16 - ASP.NET Server Controls and Data Binding
Chapter 17 - Building Real-World Web Applications
Chapter 18 - Object-Relational Mapping in .NET
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
Chapter 20 - COM Interoperability and ADO.NET
Chapter 21 - Messaging
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Appendix A - Relational Databases: Some Basic Concepts
Appendix B - Commonly Used SQL Statements
Appendix C - ADO.NET Frequently Asked Questions
Index
List of Figures
List of Tables
List of Listings
List of Sidebars
Table of Contents
Applied ADO.NETBuilding Data-Driven Solutions
Introduction
Figure 16-8: Multiple columns in a DataList control
Chapter 1 - ADO.NET Basics
Chapter 2 - Data Components in Visual Studio .NET
Setting
Chapter 3 -the Styleinand
ADO.NET Templates
Disconnected of a DataList
Environments Control
Chapter 4 - ADO.NET in Connected Environments
As you saw in Table 16-6, the DataList class provides many style properties for different portions of the
Chapter 5 - Handling ADO.NET Events
control. These properties are AlternatingItemStyle,EditItemStyle,FooterItemStyle,
Chapter 6 - IntegratingItemStyle,
HeaderItemStyle, XML with ADO.NET
SelectedItemStyle, and SeparatorStyle. Using these
Chapter 7 - Data Binding andstyle
properties, you can set the Windows
of theForms Data-Bound
respective portionControls
of the control.
Chapter 8 - Constraints and Data Relations
In addition
Chapter 9 -to the styles,
ADO.NET you canHandling
Exception hide or show the DataList control headers and footers by using the
ShowHeader
Chapter and ShowFooter
10 - Working with the ODBCproperties.
.NET Data You can even set the layout of the DataList control by using
Provider
theRepeatLayout
Chapter property, and
11 - Stored Procedures which takes a value of the RepeatLayout enumeration, which has two
Views
values:12
Chapter Table and Flow.
- Oracle, The
SQLXML, Other layout
Table
and is responsible
.NET Data Providers for displaying items in a table. The Flow layout
is responsible
Chapter for displaying
13 - Developing itemsData
a Custom without a table.
Provider
Chapter 14 - Developing
TheDataList control Database
supports Web
manyApplications
templates,using
even ASP.NET
more than the DataGrid control. The templates
Chapter 15 - Using ADO.NET in Xml Web Services
supported by the DataList control are AlternatingItemTemplate,EditItemTemplate,
Chapter 16 - ASP.NET HeaderTemplate,
FooterTemplate, Server Controls and Data Binding
ItemTemplate, SelectedItemTemplate, and
Chapter 17 - Building Real-World Web Applications
SeparatorTemplate. Using these templates you can set or get the format of different portions of the
Chapter 18 - Object-Relational Mapping in .NET
DataList.
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
Note
Chapter 20 See theInteroperability
- COM "Understanding Web
and Server Control Templates" section for more details about
ADO.NET
Chapter 21 templates.
- Messaging
Chapter
Listing 22 - SQL
16-14 Server
sets and ADO.NET:
the styles Notes of
and templates onaPerformance
DataList control and its portions manually. This code
Appendix A - Relational Databases: Some Basic
shows you how you can use templates. You can Concepts
give them whatever format you want.
Appendix B - Commonly Used SQL Statements
Listing 16-14:
Appendix Setting
C - ADO.NET a DataList
Frequently AskedControl's
Questions Styles
Index
List of Figures
<asp:DataList
List of Tables
id=DataList1
List of Listings
runat="server"
List of Sidebars
GridLines="Both"
DataSource="<%# DataSet11 %>"
DataKeyField="CategoryID"
DataMember="Categories"
RepeatDirection="Horizontal"
RepeatColumns="5"
Font-Size="X-Small"
Font-Names="Verdana"
ForeColor="Navy"
BackColor="LightGray"
BorderColor="Black">
<SelectedItemStyle
ForeColor="#FF0033"
Applied ADO.NET: Building Data-Driven Solutions
BackColor="#CCCC99">
by Mahesh Chand and David Talbot
</SelectedItemStyle> ISBN:1590590732
The following code sets the DataKeyField property to the CategoryID column:
<ASP:DataList
id="dtList" RepeatColumns="5"
RepeatDirection="Horizontal"
GridLines="Both"
DataKeyField="CategoryID"
...........
> Applied ADO.NET: Building Data-Driven Solutions
by Mahesh Chand and David Talbot ISBN:1590590732
Apress 2003 (928 pages)
Understanding
ThisDataList Events
text provides extensive coverage of ADO.NET technology
including ADO.NET internals, namespaces, classes, and
interfaces,
TheDataList control and takes
supports a comprehensive
events look at XML
and provides method to raise events when items are being bound,
namespaces and classes, and how to integrate both with
edited, deleted, and created.
ADO.NET.
TheItemCreated event occurs when an item is created in the control. The event handler of the
of Contentsevent receives an argument of type DataListItemEventArgs, which contains the data
ItemCreated
Table
related to the event. You Data-Driven
Applied ADO.NETBuilding can use the Solutions
OnItemCreated method to raise this event.
Introduction
TheItemDataBound event occurs when an item is data bound to the control. You use this event to
Chapter
access1the- data
ADO.NET
item Basics
before it'll be displayed in the control. You can use the OnItemDataBound method
Chapter
to raise2the- ItemDataBound
Data Components inevent.
Visual Studio .NET
Chapter 3 - ADO.NET in Disconnected Environments
ADataList
Chapter control can
4 - ADO.NET have Update,
in Connected Delete, and Cancel buttons, which can be used to update, delete,
Environments
and cancel
Chapter 5 - data in a ADO.NET
Handling DataList control, respectively. The ItemCommand event occurs when any button is
Events
clicked.6
Chapter - Integrating XML with ADO.NET
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
TheCancelCommand event occurs when the Cancel button is clicked in a DataList control. You can
Chapter 8 - Constraints and Data Relations
use the OnCancelCommand method to raise this event.
Chapter 9 - ADO.NET Exception Handling
TheEditCommand
Chapter 10 - Working event occurs
with the ODBCwhen
.NETthe Edit
Data button of DataList is clicked. You can use the
Provider
11 - Stored method
OnEditCommand
Chapter to raise
Procedures this event.
and Views
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
TheDeleteCommand event occurs when the Delete button of DataList is clicked. You can use the
Chapter 13 - Developing a Custom Data Provider
OnDeleteCommand method to raise this event.
Chapter 14 - Developing Database Web Applications using ASP.NET
Chapter 15 - Using ADO.NET
TheUpdateCommand eventinoccurs
Xml Web Services
when the Edit button of DataList is clicked. You can use the
Chapter
OnUpdateCommand method to raise thisData
16 - ASP.NET Server Controls and Binding
event.
Chapter 17 - Building Real-World Web Applications
The event
Chapter 18 -handler of the ItemCreated,
Object-Relational CancelCommand,EditCommand,DeleteCommand , and
Mapping in .NET
19 - Mappedevents
UpdateCommand
Chapter receive
Objects: an argument
Performance of type DataListCommandEventArgs,
Considerations and Data Binding which contains
data related to this event. DataListCommandEventArgs provides information, which includes the
Chapter 20 - COM Interoperability and ADO.NET
argument for the command, the name of the command, the source of the command, and the item
Chapter 21 - Messaging
containing the command source in the control.
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Appendix A - Relational
Listing 16-15 adds theDatabases: Some Basic
Update,Delete, Concepts
Cancel, and Edit command event handlers by using the
Appendix B - CommonlyOnDeleteCommand,
OnUpdateCommand, Used SQL StatementsOnCancelCommand, and OnEditCommand methods.
Appendix C - ADO.NET Frequently Asked Questions
Listing 16-15: AddingUpdate,Delete,Cancel, and Edit Command Handlers
Index
List of Figures
List of Tables
<asp:datalist
List of Listings
id="dtList" runat="server" CellPadding="4"
List of Sidebars
GridLines="Horizontal" RepeatColumns="5"
OnUpdateCommand="UpdateCommandHandler"
OnDeleteCommand="DeleteCommandHandler"
OnCancelCommand="CancelCommandHandler"
OnEditCommand="EditCommandHandler"
DataKeyField="CategoryID" BackColor="WhiteSmoke"
BorderColor="#CCCCCC" BorderStyle="Solid"
BorderWidth="1px" ForeColor="Black"
Font-Names="Verdana" Font-Size="8pt">
Listing 16-16 shows the code written on the event handlers for these commands.
Applied ADO.NET: Building Data-Driven Solutions
by Mahesh
Listing 16-16: The Chand
Code for and David
the Update, Talbot Cancel, and
Delete, Edit Command Handlers
ISBN:1590590732
Apress 2003 (928 pages)
This text provides extensive coverage of ADO.NET technology
Sub EditCommandHandler(sender as object, _
including ADO.NET internals, namespaces, classes, and
args as DataListCommandEventArgs)
interfaces, and takes a comprehensive look at XML
namespaces and classes, and how to integrate both with
End Sub ADO.NET.
Second, format and set a layout for the control. For this example, set the header, footer, selected item,
item, alternating item, and edit item templates. On ItemTemplate and AlternatingItemTemplate,
add a LinkButton control with a CommandName of Edit, which means it'll be responsible for raising the
Applied
EditCommandevent. TheADO.NET: Building
following code addsData-Driven Solutions
an Edit link button to the items of a DataListcontrol:
by Mahesh Chand and David Talbot ISBN:1590590732
Apress 2003 (928 pages)
<asp:LinkButton Text="Edit" CommandName="Edit"
This text provides extensive coverage of ADO.NET technology
RunAt="server">
including ADO.NET internals, namespaces, classes, and
</asp:LinkButton>
interfaces, and takes a comprehensive look at XML
namespaces and classes, and how to integrate both with
ADO.NET.
The code for ItemTemplate and AlternatingItemTemplate is as follows:
Table of Contents
<ItemTemplate>
Applied ADO.NETBuilding Data-Driven Solutions
<b>Category ID:</b>
Introduction
<%# Container.DataItem("CategoryID") %>
Chapter 1 - ADO.NET Basics
<br>
Chapter 2 - Data Components in Visual Studio .NET
<b>Category Name:</b>
Chapter
<%#3 Container.DataItem("CategoryName")
- ADO.NET in Disconnected Environments %>
Chapter
<br> - ADO.NET in Connected Environments
4
Chapter 5 - Handling ADO.NET Events
<b>Description:</b>
Chapter
<%#6 Container.DataItem("Description")
- Integrating XML with ADO.NET %>
Chapter
<br> - Data Binding and Windows Forms Data-Bound Controls
7
Chapter 8 - Constraints and
<asp:LinkButton Data Relations CommandName="Edit"
Text="Edit"
RunAt="server">
Chapter 9 - ADO.NET Exception Handling
</asp:LinkButton>
Chapter 10 - Working with the ODBC .NET Data Provider
</ItemTemplate>
Chapter 11 - Stored Procedures and Views
<AlternatingItemTemplate>
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Chapter 13 -face="verdana"
<font Developing a Customcolor="green"
Data Provider size="1"><b>Category ID:</b>
<%# Container.DataItem("CategoryID") %>
Chapter 14 - Developing Database Web Applications using ASP.NET
<br>
Chapter 15 - Using ADO.NET in Xml Web Services
<b>Category Name:</b>
Chapter 16 - ASP.NET Server Controls and Data Binding
<%# Container.DataItem("CategoryName") %>
Chapter 17 - Building Real-World Web Applications
<br>
Chapter 18 - Object-Relational Mapping in .NET
<b>Description:</b>
Chapter
<%#19Container.DataItem("Description")
- Mapped Objects: Performance Considerations %>
and Data Binding
Chapter
<br>20 - COM Interoperability and ADO.NET
Chapter 21 - Messaging
<asp:LinkButton Text="Edit" CommandName="Edit"
Chapter 22 - SQL Server and
RunAt="server" ADO.NET: Notes on Performance
ID="Linkbutton1" NAME="Linkbutton1">
Appendix A - Relational
</asp:LinkButton> Databases: Some Basic Concepts
Appendix B - Commonly Used SQL Statements
</font>
</AlternatingItemTemplate>
Appendix C - ADO.NET Frequently Asked Questions
Index
List of Figures
As you can see from the previous code, you simply display the contents of the Categories table and, in the
List of Tables
end, add the Edit link button. You also set the header and footer styles of the control.
List of Listings
List of Sidebars
EditItemTemplate is another template that plays a major role in creating an editable DataList
control. This is the template where you set the types of control being used when a DataList control is in
edit mode. When a DataList control is in edit mode, you want to allow users to edit the CategoryName
and Description columns of the Categories table. To do so, you need to create TextBox controls so the
user can edit new values. Besides the TextBox controls, you need to allow options to save changes,
cancel changes, and delete an item from the DataList. The following code snippet adds TextBox
controls and link buttons to the edited item of the DataList control:
<EditItemTemplate>
<b>Category Name:</b>
<br>
<asp:TextBox ID="catNameTextBox"
Text='<%# Container.DataItem("CategoryName") %>'
Runat="server"Applied ADO.NET: Building Data-Driven Solutions
by Mahesh Chand
Font-Names="Verdana" and David Talbot
Font-Size="8pt" ISBN:1590590732
Apress
BorderStyle="Groove" /> 2003 (928 pages)
<br> This text provides extensive coverage of ADO.NET technology
including ADO.NET internals, namespaces, classes, and
<b>Description</b>
interfaces, and takes a comprehensive look at XML
<br> namespaces and classes, and how to integrate both with
<asp:TextBox ID="desTextBox"
ADO.NET.
Text='<%# Container.DataItem("Description") %>'
Runat="server"
TableFont-Names="Verdana"
of Contents Font-Size="8pt"
Applied ADO.NETBuilding Data-Driven
BorderStyle="Groove" /> Solutions
Introduction
<br>
Chapter 1 - ADO.NET Basics
<asp:LinkButton Text="Cancel" CommandName="cancel" Runat="server" />
Chapter 2 - Data Components
<asp:LinkButton in Visual Studio CommandName="delete"
Text="Delete" .NET Runat="server" />
<asp:LinkButton
Chapter Text="Update"
3 - ADO.NET in Disconnected CommandName="update" Runat="server" />
Environments
</EditItemTemplate>
Chapter 4 - ADO.NET in Connected Environments
Chapter 5 - Handling ADO.NET Events
Chapter 6 - Integrating XML with ADO.NET
The next step is to load data to the control. You create a method called FillDataList, which binds data
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
to the DataList control based on the items specified in ItemTemplate and
Chapter 8 - Constraints and Data Relations
AlternatingItemTemplate, as shown earlier.
Chapter 9 - ADO.NET Exception Handling
You call
Chapter 10the
- Working method
with the ODBC
FillDataList onData
.NET the Provider
Page_Load event, as shown in the following code:
Chapter 11 - Stored Procedures and Views
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Sub Page_Load
Chapter 13 - Developing
If not IsPostBack a Custom Data Provider
Chapter 14 - Developing Database Web Applications using ASP.NET
FillDataList()
Chapter
End15If- Using ADO.NET in Xml Web Services
End Sub
Chapter 16 - ASP.NET Server Controls and Data Binding
Chapter 17 - Building Real-World Web Applications
Chapter 18 - Object-Relational Mapping in .NET
Now you write the EditCommand event handler, where you set EditItemIndex of the DataList
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
control to the ItemIndex of DataListCommandEventArgs.Item returned by the EditCommand
Chapter 20 - COM Interoperability and ADO.NET
handler. After setting EditItemIndex of DataList, you refill data to the control by calling the
Chapter 21 - Messaging
FillDataList method, as shown in the following code:
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Appendix A - Relational Databases: Some Basic Concepts
Sub EditCommandHandler(sender as object, _
Appendix B - Commonly Used SQL Statements
args as DataListCommandEventArgs)
Appendix C - ADO.NET Frequently Asked Questions
dtList.EditItemIndex = args.Item.ItemIndex
Index
FillDataList()
List
End of Figures
Sub
List of Tables
List of Listings
Onofthe
List CancelCommand event handler, you simply set EditItemIndex of DataListto -1 and rebind
Sidebars
theDataList control:
Writing code for the UpdateCommand and DeleteCommand handlers is little tricky. You probably can
guess that on the UpdateCommand handler, you need to find out the index of the current item by using
Appliedwhich
DataList.DataKeys, ADO.NET: Building
returns Data-Driven
the PrimaryKey Solutions
column's value. Once you know the
by Mahesh Chand and David Talbot
PrimaryKey, you can easily find out which record you want toISBN:1590590732
update or delete. You can simply construct
aSqlCommand and Apress 2003it.(928 pages)
execute
This text provides extensive coverage of ADO.NET technology
including
TheDeleteCommand ADO.NET
event handlerinternals, namespaces, classes, and
is as follows:
interfaces, and takes a comprehensive look at XML
namespaces and classes, and how to integrate both with
dim strId as ADO.NET.
string = dtList.DataKeys(args.Item.ItemIndex)
dim sql = "DELETE Categories WHERE CategoryID=@catID"
dim cmd as SqlCommand = new SqlCommand(sql, conn)
Table of Contents
cmd.Parameters.Add("@catID", strId)
Applied ADO.NETBuilding Data-Driven Solutions
conn.Open()
Introduction
cmd.ExecuteNonQuery()
Chapter 1 - ADO.NET Basics
conn.Close()
Chapter 2 - Data Components =
dtList.EditItemIndex in -1
Visual Studio .NET
Chapter 3 - ADO.NET in Disconnected Environments
FillDataList()
Chapter 4 - ADO.NET in Connected Environments
Chapter 5 - Handling ADO.NET Events
As you can see from the previous code, you simply get the CategoryID value for the edited item of the
Chapter 6 - Integrating XML with ADO.NET
DataList control. Once you have the CategoryID value, you delete all records that match the
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
CategoryID by constructing and executing a DELETEstatement.
Chapter 8 - Constraints and Data Relations
Chapter
On the 9UpdateCommand
- ADO.NET Exception
eventHandling
handler, you need to get the values of the CategoryName and Description
Chapter
columns10and
- Working with the and
then construct ODBC .NET Data
execute Provider statement, as shown in the following code:
an UPDATE
Chapter 11 - Stored Procedures and Views
Chapter 12 - Oracle,
dim strId SQLXML, =and
as string Other .NET Data Providers
dtList.DataKeys(args.Item.ItemIndex)
Chapter 13 - Developingas
dim strCatName a Custom Data =
TextBox Provider
args.Item.FindControl("catNameTextBox")
Chapter 14 - Developing
dim strDesc Database Web
as TextBox Applications using ASP.NET
= args.Item.FindControl("desTextBox")
Chapter 15 - Using
dim sql ADO.NETCategories
= "UPDATE in Xml Web Services
SET CategoryName=@catName, " & _
Chapter 16 - ASP.NET Server Controls
" Description=@desc WHEREand Data Binding
CategoryID=@catID"
dim cmd
Chapter as SqlCommand
17 - Building = new
Real-World Web SqlCommand(sql, conn)
Applications
cmd.Parameters.Add("@catID",
Chapter strId)
18 - Object-Relational Mapping in .NET
cmd.Parameters.Add("@catName",
Chapter strCatName.Text.ToString())
19 - Mapped Objects: Performance Considerations and Data Binding
cmd.Parameters.Add("@desc",
Chapter strDesc.Text.ToString())
20 - COM Interoperability and ADO.NET
conn.Open()
Chapter 21 - Messaging
cmd.ExecuteNonQuery()
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
conn.Close()
Appendix A - Relational Databases: Some Basic Concepts
dtList.EditItemIndex = -1
Appendix B - Commonly Used SQL Statements
FillDataList()
Appendix C - ADO.NET Frequently Asked Questions
Index
List of Figures
List of Tables
List ofNote You also set the EditItemIndex of DataList to -1 and call the FillDataList method to
Listings
refill the DataList control.
List of Sidebars
<FooterTemplate>
Table<FONT
of Contents
face="verdana" color="#996600" size="1">
Applied ADO.NETBuilding
DataList Control Data-Driven
footer Solutions
Introduction
</FONT>
Chapter 1 - ADO.NET Basics
</FooterTemplate>
Chapter 2 - Data Components in Visual Studio .NET
<ItemTemplate>
' item
Chapter 3 template
- ADO.NET incode here Environments
Disconnected
</ItemTemplate>
Chapter 4 - ADO.NET in Connected Environments
Chapter 5 - Handling ADO.NET Events
<AlternatingItemTemplate>
Chapter 6 - Integrating XML with ADO.NET
' alternative
Chapter itemand
7 - Data Binding template codeData-Bound
Windows Forms here Controls
</AlternatingItemTemplate>
Chapter 8
- Constraints and Data Relations
Chapter 9 - ADO.NET Exception Handling
<FooterStyle ForeColor="Black" BackColor="#C0FFC0">
Chapter 10 - Working with the ODBC .NET Data Provider
</FooterStyle>
Chapter 11 - Stored Procedures and Views
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
<HeaderStyle Font-Bold="True" ForeColor="#C04000" BackColor="#FF8000">
Chapter 13 - Developing a Custom Data Provider
</HeaderStyle>
Chapter 14 - Developing Database Web Applications using ASP.NET
Chapter 15 - Using ADO.NET in Xml Web Services
<EditItemTemplate>
Chapter
' code 16 here
- ASP.NET Server Controls and Data Binding
Chapter 17 - Building Real-World Web Applications
</EditItemTemplate>
Chapter 18 - Object-Relational Mapping in .NET
</asp:datalist></form>
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
</body>
Chapter 20 - COM Interoperability and ADO.NET
</HTML>
Chapter 21 - Messaging
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Appendix A - Relational Databases: Some Basic Concepts
Appendix B - Commonly Used SQL Statements
If you run the application, the output looks like Figure 16-9.
Appendix C - ADO.NET Frequently Asked Questions
Index
List of Figures
List of Tables
List of Listings
List of Sidebars
Now if you click an Edit link button, the item changes to editable form, which looks like Figure 16-10.
Applied ADO.NET: Building Data-Driven Solutions
by Mahesh Chand and David Talbot ISBN:1590590732
Apress 2003 (928 pages)
This text provides extensive coverage of ADO.NET technology
including ADO.NET internals, namespaces, classes, and
interfaces, and takes a comprehensive look at XML
namespaces and classes, and how to integrate both with
ADO.NET.
Figure 16-10: ADataList control in editable mode
Table of Contents
The Update
Applied link button saves
ADO.NETBuilding the changes,
Data-Driven the Cancel link button ignores the changes and keeps the
Solutions
original values, and the Delete link button deletes the item.
Introduction
Chapter 1 - ADO.NET Basics
Using the VS .NET IDE to Set a DataList's Properties
Chapter 2 - Data Components in Visual Studio .NET
Chapter
The VS3.NET
- ADO.NET in Disconnected
IDE provides Environments
limited support to the DataList control. There are two common ways to set a
Chapter 4 - control's
DataList ADO.NET properties.
in Connected Environments
First, you can use the Properties windows; second, you can use the
Chapter
Property5 Builder.
- Handling
YouADO.NET Events Builder by right-clicking and selecting Property Builder or by
call the Property
Chapter
clicking the Property Builder link ADO.NET
6 - Integrating XML with at the bottom of the Properties window, as shown in Figure 16-11.
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
Chapter 8 - Constraints and Data Relations
Chapter 9 - ADO.NET Exception Handling
Chapter 10 - Working with the ODBC .NET Data Provider
Chapter 11 - Stored Procedures and Views
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Chapter 13 - Developing a Custom Data Provider
Chapter 14 - Developing Database Web Applications using ASP.NET
Chapter 15 - Using ADO.NET in Xml Web Services
Chapter 16 - ASP.NET Server Controls and Data Binding
Chapter 17 - Building Real-World Web Applications
Chapter 18 - Object-Relational Mapping in .NET
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
Chapter 20 - COM Interoperability and ADO.NET
Chapter 21 - Messaging
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Appendix A - Relational Databases: Some Basic Concepts
Appendix B - Commonly Used SQL Statements
Appendix C - ADO.NET Frequently Asked Questions
IndexFigure 16-11: The Properties window of a DataList control
List of Figures
List
The of first
Tables
page of the Property Builder is the General page. On this page, you can set DataKeyField and
List of Listings
other properties of the control. The Show Header and Show Footer check boxes indicate whether the
header
List and footer will be displayed in the control. In the Repeat Layout section, you can set the Columns,
of Sidebars
Direction, and Layout properties.
The second page of the Property Builder is the Format page. On this page, you can set the format of the
control, header, footer, items, and separators. From this page, you can set the properties such as
background color, foreground colors, font, and alignment of each portion of the DataList control. You
can even set the format of items, alternating items, selecting items, and edit mode items from this page.
The third page of the Property Builder is the Border Format page, which allows you to set the format of the
DataList border. The properties on this page are cell padding, cell spacing, grid lines, border color, and
border width.
Using the DataGrid WebBuilding
Applied ADO.NET: Server ControlSolutions
Data-Driven
by Mahesh Chand and David Talbot ISBN:1590590732
In Chapter 14, you learn about some DataGrid functionality. It discussed using data binding, setting a
Apress 2003 (928 pages)
control's properties and styles using the Properties window as well as the Property Builder, writing event
This text provides
handlers, and implementing pagingextensive coveragecontrol.
in a DataGrid of ADO.NET technology
including ADO.NET internals, namespaces, classes, and
interfaces, and takes a comprehensive look at XML
TheDataGrid control's functionality doesn't end there; it provides much more than that. In this section,
namespaces and classes, and how to integrate both with
you'll see the restADO.NET.
of the functionality. You'll work in the HTML View because it's easy to understand and
modify.
Table Caution If you skipped Chapter 14, you should go back and read the "DataGrid and DataList
of Contents
Controls" section.
Applied ADO.NETBuilding Data-Driven Solutions
Introduction
The following code creates a DataGrid control programmatically:
Chapter 1 - ADO.NET Basics
Chapter 2 - Data Components in Visual Studio .NET
<ASP:DataGrid
Chapter id="dtGrid"
3 - ADO.NET in Disconnected Environments
runat="server">
Chapter 4
- ADO.NET in Connected Environments
</ASP:DataGrid>
Chapter 5 - Handling ADO.NET Events
Chapter 6 - Integrating XML with ADO.NET
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
Chapter
Similar8to the
- Constraints
DataList and Data Relations
control, the DataGrid control provides a DataSource property, which binds
Chapter
data to9the- control.
ADO.NET Exception
Once Handling
you have set the DataSource property, you call the DataBind method. Listing
16-18 reads
Chapter data from
10 - Working the
with theCategories
ODBC .NETtable
Dataof Northwind and binds the filled DataSet to the DataGrid
Provider
control.11 - Stored Procedures and Views
Chapter
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Listing 16-18: Data Binding in a DataGrid Control
Chapter 13 - Developing a Custom Data Provider
Chapter 14 - Developing Database Web Applications using ASP.NET
<%@ Import
Chapter Namespace="System.Data.SqlClient"
15 - Using ADO.NET in Xml Web Services %>
<%@ Import
Chapter Namespace="System.Data"
16 - ASP.NET %>
Server Controls and Data Binding
<HTML>
Chapter 17 - Building Real-World Web Applications
<script
Chapter 18 -language="VB" runat="server">
Object-Relational Mapping in .NET
Sub19Page_Load(sender
Chapter As Object,
- Mapped Objects: Performance e As EventArgs)
Considerations and Data Binding
If Not IsPostBack Then
Chapter 20 - COM Interoperability and ADO.NET
FillDataGrid()
Chapter 21 - Messaging
End If
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
End SUb
Appendix A - Relational Databases: Some Basic Concepts
Sub FillDataGrid()
Appendix B - Commonly Used SQL Statements
Dim conn As SqlConnection
Appendix C - ADO.NET
Dim Frequently
adapter Asked Questions
As SqlDataAdapter
Index dim connectionString = _
List of Figures
"Data Source=MCB;Initial Catalog=Northwind;" & _
List of Tables
"user id=sa;password=;"
List of Listings
conn = new SqlConnection(connectionString)
List of Sidebars
conn.Open()
dim sql = "SELECT * FROM Categories"
adapter = new SqlDataAdapter(sql, conn)
Dim ds As Dataset = new DataSet()
adapter.Fill(ds)
dtGrid.DataSource = ds
dtGrid.DataBind()
End Sub
</script>
<body>
<ASP:DataGrid id="dtGrid"
runat="server">
Applied ADO.NET: Building Data-Driven Solutions
</ASP:DataGrid>
</body> by Mahesh Chand and David Talbot ISBN:1590590732
Table of Contents
Applied ADO.NETBuilding Data-Driven Solutions
Introduction
Chapter 1 - ADO.NET Basics
Chapter 2 - Data Components in Visual Studio .NET
Chapter 3 - ADO.NET in Disconnected Environments
Chapter 4 - ADO.NET in Connected Environments
Chapter 5 - Handling ADO.NET Events
Chapter 6 - Integrating XML with ADO.NET
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
Chapter 8 - Constraints and Data Relations
Chapter 9 - ADO.NET Exception Handling
Chapter 10 - Working with the ODBC .NET Data Provider
Chapter 11 - 16-12:
Figure Stored Procedures and
Data binding in Views
a DataGrid control
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Chapter 13 - Developing a Custom Data Provider
Setting
Chapter 14 -DataGrid
Developing Styles
Database Web Applications using ASP.NET
Chapter 15 - Using ADO.NET in Xml Web Services
Besides setting a DataGrid control's properties at design-time, you can always set a DataGrid control's
Chapter 16 - ASP.NET Server Controls and Data Binding
properties (including style properties) from the .aspx page by simply editing the HTML code using the VS
Chapter 17 - Building Real-World Web Applications
.NET IDE or a text editor.
Chapter 18 - Object-Relational Mapping in .NET
TheDataGrid
Chapter control
19 - Mapped provides
Objects: properties
Performance that can set the
Considerations andstyle
Dataof its various parts. The DataGrid style
Binding
properties
Chapter 20 -are
COMAlternatingItemStyle, HeaderStyle,FooterStyle,EditItemStyle,
Interoperability and ADO.NET
ItemStyle,
Chapter and SelectedItemStyle, which represent styles for alternating items, headers, footers,
21 - Messaging
edit items,
Chapter 22 -items, and selected
SQL Server items, Notes
and ADO.NET: respectively.
on Performance
Appendix A - Relational Databases: Some Basic Concepts
Each of these style properties is a type of the TableItemStyle class, which inherits from the Style
Appendix B - Commonly Used SQL Statements
class. The TableItemStyle class represents the style of properties for an element of a control. Table
Appendix C - ADO.NET
16-7 describes Frequently Asked Questions
the TableItemStyle class properties.
Index
List of Figures
Table 16-7: The TableItemStyle Class Properties
List of Tables
List of Listings
List of Sidebars
PROPERTY DESCRIPTION
Applied ADO.NET: Building Data-Driven Solutions
by Mahesh Chand and David Talbot ISBN:1590590732
BackColor Background color of the item.
Apress 2003 (928 pages)
BorderColor This text Border
providescolor of thecoverage
extensive item. of ADO.NET technology
including ADO.NET internals, namespaces, classes, and
BorderStyle interfaces,Border styleaof
and takes the item. It can
comprehensive beatDashed,
look XML Dotted,Double,Groove,
namespaces and None,
Inset, classes, and howOutset,
Notset, to integrate bothorwith
Ridge, Solid.
ADO.NET.
BorderWidth Width of the border.
CssStyle
Table of Contents Cascading style of the item.
Applied
FontADO.NETBuilding Data-Driven
FontInfo,Solutions
which defines how the font will be displayed.
Introduction
ForeColor
Chapter Foreground color of the item.
1 - ADO.NET Basics
Chapter
Height2 - Data Components in Visual
Height of theStudio
item. .NET
Chapter 3 - ADO.NET in Disconnected Environments
HorizontalAlign
Chapter 4 Horizontal
- ADO.NET in Connected alignment of the item.
Environments
Chapter 5 - Handling ADO.NET
VerticalAlign Events
Vertical alignment of the item.
Chapter 6 - Integrating XML with ADO.NET
Width
Chapter 7
Width of the item.
- Data Binding and Windows Forms Data-Bound Controls
Chapter
Wrap8 - Constraints and Data Relations
If true, items will be wrapped; otherwise not.
Chapter 9 - ADO.NET Exception Handling
Chapter 10 - Working with the ODBC .NET Data Provider
Listing 11
Chapter 16-19 adds Procedures
- Stored some colors to Views
and the DataGrid control by setting its ItemStyle,HeaderStyle,
FooterStyle,AlternatingItemStyle, and EditItemStyle properties.
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Chapter 13 - Developing a Custom Data Provider
Listing 16-19: Setting a DataGrid Control's Style Properties
Chapter 14 - Developing Database Web Applications using ASP.NET
Chapter 15 - Using ADO.NET in Xml Web Services
<ASP:DataGrid id="dtGrid"
Chapter 16 - ASP.NET Server Controls and Data Binding
HeaderStyle-BackColor=#003366
Chapter 17 - Building Real-World Web Applications
HeaderStyle-Font-Bold=True
Chapter 18 - Object-Relational Mapping in .NET
HeaderStyle-Font-Name=verdana
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
HeaderStyle-ForeColor=white
Chapter 20 - COM Interoperability and ADO.NET
HeaderStyle-Font-Size=10
Chapter 21 - Messaging
ItemStyle-BackColor=black
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
ItemStyle-Font-Name=verdana
Appendix A - Relational Databases: Some Basic Concepts
ItemStyle-Font-Size=8
Appendix B - Commonly Used SQL Statements
ItemStyle-ForeColor=#ffcc33
Appendix C - ADO.NET Frequently Asked Questions
AlternatingItemStyle-BackColor=LightSteelBlue
Index
AlternatingItemStyle-ForeColor=black
FooterStyle-BackColor=#ffff99
List of Figures
FooterStyle-Font-Name=tahoma
List of Tables
FooterStyle-Font-Size=6
List of Listings
FooterStyle-Font-Italic=True
List of Sidebars
EditItemStyle-BackColor=red
EditItemStyle-Font-Size=8
EditItemStyle-ForeColor=#ccffff
ShowHeader=True
ShowFooter=True
runat="server">
Table of Contents
Applied ADO.NETBuilding Data-Driven Solutions
Introduction
Figure 16-13: TheDataGrid control with the new styles
Chapter 1 - ADO.NET Basics
Chapter 2 - Data Components in Visual Studio .NET
Understanding
Chapter 3 - ADO.NETainDataGrid's Columns
Disconnected Environments
Chapter 4 - ADO.NET in Connected Environments
TheDataGrid
Chapter 5
control provides control and manages a DataGrid's columns in different ways. You can
- Handling ADO.NET Events
manage a DataGrid control's columns at design-time as well as at runtime. The Columns property of
Chapter 6 - Integrating XML with ADO.NET
theDataGrid control is the gateway to accessing and managing columns in a DataGrid at runtime. The
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
Columns property represents a collection of DataGridColumn objects.
Chapter 8 - Constraints and Data Relations
Chapter 9 -AutoGenerateColumns
Using the ADO.NET Exception Handling
Property
Chapter 10 - Working with the ODBC .NET Data Provider
So far you've
Chapter seen Procedures
11 - Stored that if you bind a DataGrid control to a data source, the control displays all the
and Views
columns
Chapter 12available
- Oracle, in a data source
SQLXML, in the
and Other same
.NET Dataorder as they are defined in the data source. The
Providers
AutoGenerateColumns property controls this behavior of the DataGrid control. If you want to change
Chapter 13 - Developing a Custom Data Provider
the order of the columns, or you want to customize a DataGrid control, you must set the
Chapter 14 - Developing Database Web Applications using ASP.NET
AutoGenerateColumnsproperty to false.
Chapter 15 - Using ADO.NET in Xml Web Services
Chapter 16setting
Actually, - ASP.NET Server Controls and Data
AutoGenerateColumns Bindingto true automatically binds columns for all fields in
property
Chapter 17 - Building Real-World Web Applications
the data source. Each field of the data source is rendered as a column of DataGrid. The BoundColumn
Chapter 18 - Object-Relational
class represents Mapping
a bound column of ainDataGrid
.NET control.
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
Using the
Chapter 20 -DataGridColumn Class
COM Interoperability and ADO.NET
Chapter 21 - Messaging
TheDataGridColumn class represents a column of a DataGrid control. A DataGrid control can have
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
different kind of columns such as bound columns, button columns, edit command columns, hyperlink
Appendix
columns, A and
- Relational Databases:
button columns. Some
The Basic Concepts
BoundColumn, ButtonColumn,EditCommandColumn,
Appendix B - Commonly and
HyperlinkColumn, UsedTemplateColumn
SQL Statements classes represent the bound columns, button, edit
Appendix
command, C - hyperlink,
ADO.NET Frequently Asked
and template Questions
column, respectively. The DataGridColumn class is the base class
Index
for all column classes.
List of Figures
The
List ofDataGridColumn
Tables class provides properties that can format a DataGrid column's header and
footers. These properties are FooterStyle,FooterText,HeaderImageUrl,HeaderStyle, and
List of Listings
HeaderText. The ItemStyle property gets the style of a column's items. The SortExpression
List of Sidebars
property represents the name of the field or expressions, which are used in the OnSortCommand method
when a column sorts its items.
To allow the custom view and selection of columns, the first thing you need to do is disable the
AutoGenerateColumns property:
Applied ADO.NET: Building Data-Driven Solutions
by Mahesh Chand and David Talbot ISBN:1590590732
AutoGenerateColumns=False
Apress 2003 (928 pages)
This text provides extensive coverage of ADO.NET technology
including ADO.NET internals, namespaces, classes, and
Now, because the AutoGenerateColumns property is false, you have to generate all the columns you
interfaces, and takes a comprehensive look at XML
want to display innamespaces
a DataGrid andcontrol. You
classes, anduse
howBoundColumn forwith
to integrate both adding data-bound columns to the
DataGrid control. You can use the Columnsproperty of DataGrid and bind the
ADO.NET.
ASP:BoundColumn.DataField property to the data source. Listing 16-20 displays the Description,
CategoryName, and CategoryID columns of the Categories table in the same order.
Table of Contents
Applied
ListingADO.NETBuilding Data-Driven
16-20: Rearranging Solutions
a DataGrid Column's Sequence
Introduction
Chapter 1 - ADO.NET Basics
<ASP:DataGrid id="dtGrid"
Chapter 2 - Data Components in Visual Studio .NET
AutoGenerateColumns=False
Chapter 3 - ADO.NET in Disconnected Environments
EnableViewState=False
Chapter 4 - ADO.NET in Connected Environments
runat="server">
Chapter 5 - Handling ADO.NET Events
<Columns>
Chapter 6 - Integrating XML
<ASP:BoundColumn with ADO.NET
DataField="Description" />
Chapter 7 - Data BindingDataField="CategoryName"
<ASP:BoundColumn and Windows Forms Data-Bound Controls
/>
<ASP:BoundColumn DataField="CategoryID"
Chapter 8 - Constraints and Data Relations />
</Columns>
Chapter 9 - ADO.NET Exception Handling
</ASP:DataGrid>
Chapter 10 - Working with the ODBC .NET Data Provider
Chapter 11 - Stored Procedures and Views
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Chapter 13 - Developing a Custom Data Provider
TheBoundColumn property provides the DataFormatString property, which can format the data of a
Chapter 14 - Developing Database Web Applications using ASP.NET
column. You can even set the format of the BoundColumn header and footers. For this example, set the
Chapter 15 - Using ADO.NET in Xml Web Services
header and footer text for the columns by using the HeaderText and FooterText properties of
Chapter 16 - ASP.NET
BoundColumn. Server
Listing 16-21Controls
shows and
the Data Binding
final code.
Chapter 17 - Building Real-World Web Applications
Listing18
Chapter 16-21: FormattingBoundColumn's
- Object-Relational Mapping in .NET Header and Footers
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
Chapter 20 - COM Interoperability and ADO.NET
<Columns>
Chapter 21 - Messaging
<ASP:BoundColumn
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
DataField="Description"
Appendix A - Relational Databases: Some Basic Concepts
HeaderText="Description"
Appendix B - Commonly Used SQL
FooterText="Category Statements
Description"/>
Appendix C - ADO.NET Frequently Asked Questions
<ASP:BoundColumn
DataField="CategoryName"
Index
HeaderText="Category
List of Figures Name"
FooterText="Name
List of Tables of Category"/>
<ASP:BoundColumn
List of Listings DataField="CategoryID"
HeaderText="ID"
List of Sidebars
FooterText="Category ID"/>
</Columns>
Table of Contents
Applied ADO.NETBuilding Data-Driven Solutions
Figure 16-14: DataGrid with BoundColumns
Introduction
Chapter 1 - ADO.NET Basics
Chapter 2 - Data Components in Visual Studio .NET
Calling DataGrid
Chapter 3
Events
- ADO.NET in Disconnected Environments
Chapter 4 - ADO.NET
TheDataGrid eventsinplay
Connected Environments
a major role in DataGrid customization. In this section, you'll learn about the
Chapter 5 - Handling ADO.NET Events
DataGrid events, which you'll use in later examples. Table 16-8 describes the DataGrid control events.
Chapter 6 - Integrating XML with ADO.NET
Chapter 7 - Data
Table 16-8: Binding and Control
The DataGrid WindowsEvents
Forms Data-Bound Controls
Chapter 8 - Constraints and Data Relations
EVENT - ADO.NET Exception
Chapter 9
DESCRIPTION
Handling
Chapter 10 - Working with theThe
CancelCommand ODBC .NET button
Cancel Data Provider
tells a DataGrid control not to save the changes
Chapter 11 - Stored Procedures and Views
made to the items. This event occurs when a Cancel button in a
Chapter 12 - Oracle, SQLXML,DataGrid
and Other .NET Data Providers
is clicked. The OnCancelCommand method raises this
event.Data
Chapter 13 - Developing a Custom TheProvider
OnCancelCommand allows you to write a custom event
handler
Chapter 14 - Developing Database WebforApplications
the CancelCommand, where you can get the data about a
using ASP.NET
command.
Chapter 15 - Using ADO.NET in The CancelCommand event handler provides an argument
Xml Web Services
Chapter 16 - ASP.NET Server of DataGridCommandArgs,
Controls and Data Binding which gets the data associated with a
command.
Chapter 17 - Building Real-World Web Applications
Chapter 18 - Object-RelationalThe
DeleteCommand Mapping inbutton
Delete .NET deletes an item of a DataGrid control. This event
Chapter 19 - Mapped Objects:occurs
Performance
when aConsiderations
Delete buttonand Data Binding
is clicked. The OnDeleteCommand
Chapter 20 - COM Interoperability
method andraises
ADO.NET
this event. The OnDeleteCommand allows you to write a
Chapter 21 - Messaging custom event handler for the DeleteCommand, where you can get the
Chapter 22 - SQL Server and data aboutNotes
ADO.NET: a command. The DeleteCommand event handler provides
on Performance
an argument
Appendix A - Relational Databases: of DataGridCommandArgs,
Some Basic Concepts which gets the data
Appendix B - Commonly Usedassociated with a command.
SQL Statements
Appendix C - ADO.NET Frequently Asked Questions
EditCommand The Edit button edits a DataGrid control's items. This event occurs
Index when the Edit button is clicked. The OnEditCommand method raises
List of Figures this event. The OnEditCommand allows you to write a custom event
List of Tables handler for the EditCommand, where you can get the data about a
List of Listings command. The EditCommand event handler provides an argument of
List of Sidebars DataGridCommandArgs, which gets the data associated with a
command.
UpdateCommand The Update button saves the changes made to a DataGrid. This event
occurs when the Update button is clicked. The OnUpdateCommand
method raises this event. The OnUpdateCommandallows you to write
a custom event handler for the UpdateCommand, where you can get
the data about a command. The UpdateCommandevent handler
provides an argument of DataGridCommandArgs, which gets the data
associated with a command.
This eventBuilding
ItemCommand Applied ADO.NET: occurs when any button
Data-Driven on a DataGrid is clicked. The
Solutions
OnItemCommand
by Mahesh Chand and David Talbot method raises this event. Similar to previous event
ISBN:1590590732
handler, the
Apress 2003 (928 pages) OnItemCommand event also provides an argument of
DataGridCommandArgs, which gets the data associated with a
This text provides extensive coverage of ADO.NET technology
command.
including ADO.NET internals, namespaces, classes, and
interfaces, and takes a comprehensive look at XML
This
ItemCreated namespaces andevent occurs
classes, and when
how tothe items of
integrate thewith
both control are created. The
ADO.NET. OnItemCreated method raises this event. This method also provides
an argument of DataGridCommandArgs, which gets the data
associated with a command.
Table of Contents
ItemDataBound
Applied This eventSolutions
ADO.NETBuilding Data-Driven occurs when an item is bound to a DataGrid control. The
Introduction OnItemDataBound method raises this event. The ItemDataBound
Chapter 1 - ADO.NET Basics
event handler provides an argument of DataGridItemEventArgs,
which contains data related to this event.
Chapter 2 - Data Components in Visual Studio .NET
Chapter 3 - ADO.NET in Disconnected
PageIndexChanged This eventEnvironments
occurs when a paging selection of a DataGrid control is
Chapter 4 - ADO.NET in Connected
clicked.Environments
Chapter 14 covers this event in it "Paging in the DataGrid
Control"
Chapter 5 - Handling ADO.NET Eventssection.
Chapter 6 - Integrating XML with ADO.NET
SortCommand TheDataGrid control has default built-in functionality for sorting. By
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
writing a few lines of code, you can add the sorting functionality to a
Chapter 8 - Constraints and DataGrid
Data Relationscontrol. First of all, you need to set the AllowSorting
Chapter 9 - ADO.NET Exception Handling
property of the DataGrid to true. Second of all, you need to write a
Chapter 10 - Working with theSortCommand
ODBC .NET Data Provider
event handler. The SortCommand event handler
Chapter 11 - Stored Procedures and Views
provides an argument of DataGridSortCommandEventArgs, which
Chapter 12 - Oracle, SQLXML,returns
and Other
data.NET DatatoProviders
related the sort command such as the column being
Chapter 13 - Developing a Custom
used Data Provider
to sort the data.
Chapter 14 - Developing Database Web Applications using ASP.NET
Chapter 15 - Using ADO.NET in Xml Web Services
Using16the
Chapter DataGridCommandEventArgs
- ASP.NET Server Controls and Data Binding Class
Chapter 17 - Building Real-World Web Applications
This class provides data for the CancelCommand,DeleteCommand,EditCommand,ItemComand, and
Chapter 18 - Object-Relational Mapping in .NET
UpdateCommand events. The event handler of these events takes an argument of
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
DataGridCommandEventArgs, which can be used to get the data about a command.
Chapter 20 - COM Interoperability and ADO.NET
Chapter 21 - Messaging
TheCommandArgument property returns an argument for the command. The CommandName property
returns22
Chapter the- name of theand
SQL Server command,
ADO.NET:which
Notescan
on be set by using a column's CommandName property. The
Performance
CommandSource
Appendix property
A - Relational returns
Databases: the source
Some of the command, and the Item property returns the item of
Basic Concepts
theDataGrid
Appendix that contains
B - Commonly the command.
Used SQL Statements
Appendix C - ADO.NET Frequently Asked Questions
Using
Index a DataGrid Control with Button Columns
List of Figures
TheButtonColumn class represents a button column. A button column can have two types: a push
List of Tables
button or a link button. The ButtonType property of ButtonColumn represents the type of button.
List of Listings
The
List ofCommandName
Sidebars property is a string that represents the command to perform when the button is
clicked. It's used to handle the button click event handler. The DataGridCommandEventArgs's
CommandName property returns the CommandName of a column.
<Columns>
<ASP:ButtonColumn
CommandName="Yes"
ButtonType=LinkButton
Applied ADO.NET: Building Data-Driven Solutions
Text="Select">
by Mahesh Chand and David Talbot
</ASP:ButtonColumn> ISBN:1590590732
Apress
<ASP:ButtonColumn 2003 (928 pages)
This text provides extensive coverage of ADO.NET technology
CommandName="No"
including ADO.NET internals, namespaces, classes, and
ButtonType=LinkButton
interfaces, and takes a comprehensive look at XML
Text="UnSelect">
namespaces and classes, and how to integrate both with
</ASP:ButtonColumn>
ADO.NET.
</Columns>
Table of Contents
Applied ADO.NETBuilding Data-Driven Solutions
The next step is to handle the button click event. The following code adds an ItemCommand event
Introduction
handler1 to-aADO.NET
Chapter DataGrid control:
Basics
Chapter 2 - Data Components in Visual Studio .NET
Chapter 3 - ADO.NET
<ASP:DataGrid in DisconnectedOnItemCommand="dtGridItem"
id="dtGrid" Environments runat="server">
Chapter 4 - ADO.NET in Connected Environments
Chapter 5 - Handling ADO.NET Events
Now you'll change the format of the row clicked in a DataGrid control. Listing 16-22 shows the event
Chapter 6 - Integrating XML with ADO.NET
handler of the button click. As you can see from this listing, you find out what command name was clicked
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
and set the row's format accordingly.
Chapter 8 - Constraints and Data Relations
Chapter
Listing916-22:
- ADO.NET Exception Handling
The ButtonColumn Click Event Handler
Chapter 10 - Working with the ODBC .NET Data Provider
Chapter 11 - Stored Procedures and Views
Sub dtGridItem(obj as Object, args as DataGridCommandEventArgs)
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
If (args.CommandName = "Yes") Then
Chapter 13 - Developing a Custom Data Provider
args.Item.BackColor = System.Drawing.Color.Gray
Chapterargs.Item.ForeColor
14 - Developing Database Web Applications using ASP.NET
= System.Drawing.Color.White
Chapterargs.Item.Font.Name
15 - Using ADO.NET in Xml =Web Services
"tahoma"
Chapter
Else 16 - ASP.NET Server Controls and Data Binding
Chapterargs.Item.BackColor
17 - Building Real-World Web Applications
= System.Drawing.Color.Black
Chapterargs.Item.ForeColor
18 - Object-Relational Mapping in .NET
= System.Drawing.Color.LightSteelBlue
Chapterargs.Item.Font.Name
19 - Mapped Objects: Performance Considerations and Data Binding
= "verdana"
End If
Chapter 20 - COM Interoperability and ADO.NET
End Sub
Chapter 21 - Messaging
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Appendix A - Relational Databases: Some Basic Concepts
Appendix B - Commonly Used SQL Statements
This DataGrid control looks like Figure 16-15 with the button columns. When you click the Select or
Appendix C - ADO.NET Frequently Asked Questions
UnSelect link button, you see the changes in the selected row.
Index
List of Figures
List of Tables
List of Listings
List of Sidebars
Table of Contents
Figure 16-16 shows the result of using template columns.
Applied ADO.NETBuilding Data-Driven Solutions
Introduction
Chapter 1 - ADO.NET Basics
Chapter 2 - Data Components in Visual Studio .NET
Chapter 3 - ADO.NET in Disconnected Environments
Chapter 4 - ADO.NET in Connected Environments
Chapter 5 - Handling ADO.NET Events
Chapter 6 - Integrating XML with ADO.NET
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
Chapter 8 - Constraints and Data Relations
Chapter 9 - ADO.NET Exception Handling
Chapter 10 - Working with the ODBC .NET Data Provider
Chapter 11 - Stored Procedures and Views
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Chapter 13 - Developing a Custom Data Provider
Figure 16-16: Using template columns
Chapter 14 - Developing Database Web Applications using ASP.NET
Chapter
Listing 15 - Using
16-25 ADO.NET
shows in Xml Web
the complete Services
code.
Chapter 16 - ASP.NET Server Controls and Data Binding
Listing17
Chapter 16-25: Using
- Building Template
Real-World Columns
Web in a DataGrid Control
Applications
Chapter 18 - Object-Relational Mapping in .NET
Chapter 19 - Mapped
<%@ Import Objects: Performance Considerations
Namespace="System.Data" %> and Data Binding
<%@ Import
Chapter 20 - COMNamespace="System.Data.SqlClient"
Interoperability and ADO.NET %>
<html>
Chapter 21 - Messaging
<script
Chapter language="VB"
22 - SQL runat="server">
Server and ADO.NET: Notes on Performance
Sub APage_Load(sender
Appendix - Relational Databases:As Object,
Some e As EventArgs)
Basic Concepts
IfB Not
Appendix IsPostBack
- Commonly Then
Used SQL Statements
FillDataGrid()
Appendix C - ADO.NET Frequently Asked Questions
End If
Index
End SUb
List of Figures
List of Tables
Sub FillDataGrid()
List of Listings
Dim conn As SqlConnection
List of Sidebars
Dim adapter As SqlDataAdapter
dim connectionString = _
"Data Source=MCB;Initial Catalog=Northwind;" & _
"user id=sa;password=;"
conn = new SqlConnection(connectionString)
conn.Open()
dim sql = "SELECT * FROM Categories"
adapter = new SqlDataAdapter(sql, conn)
Dim ds As Dataset = new DataSet()
adapter.Fill(ds)
dtGrid.DataSource = ds
dtGrid.DataBind()
End Sub
</script> Applied ADO.NET: Building Data-Driven Solutions
<body> by Mahesh Chand and David Talbot ISBN:1590590732
Apress 2003 (928
<form id="Form1" runat="server">pages)
This text provides
<ASP:DataGrid extensive coverage
id="dtGrid" of ADO.NET technology
HeaderStyle-BackColor="#003366"
including ADO.NET internals, namespaces, classes, and
HeaderStyle-Font-Bold="True" HeaderStyle-Font-Name="verdana"
interfaces, and takes a comprehensive look at XML
HeaderStyle-ForeColor="white"
namespaces and classes, and how HeaderStyle-Font-Size="10"
to integrate both with
ItemStyle-BackColor="black"
ADO.NET. ItemStyle-Font-Name="verdana"
ItemStyle-Font-Size="8" ItemStyle-ForeColor="#ffcc33"
AlternatingItemStyle-BackColor="LightSteelBlue"
Table of Contents
AlternatingItemStyle-ForeColor="black"
Applied ADO.NETBuilding Data-Driven Solutions
FooterStyle-BackColor="#ffff99" FooterStyle-Font-Name="tahoma"
Introduction
FooterStyle-Font-Size="6" FooterStyle-Font-Italic="True"
Chapter 1 EditItemStyle-BackColor="red"
- ADO.NET Basics EditItemStyle-Font-Size="8"
Chapter 2 EditItemStyle-ForeColor="#ccffff"
- Data Components in Visual Studio .NET
Chapter 3 ShowHeader="True"
- ADO.NET in Disconnected ShowFooter="True"
Environments
Chapter 4 AutoGenerateColumns="False"
- ADO.NET in Connected Environmentsrunat="server">
Chapter 5 -<Columns>
Handling ADO.NET Events
Chapter 6 - Integrating XML with ADO.NET
Chapter 7 - Data <ASP:TemplateColumn>
Binding and Windows Forms Data-Bound Controls
Chapter 8
<ItemTemplate>
- Constraints and Data Relations
<FONT face="verdana" size="2">
Chapter 9 - ADO.NET Exception Handling
<BR>
Chapter 10 - Working with the ODBC .NET Data Provider
<B>Category ID: </B>
Chapter 11 - Stored Procedures and Views
<%# DataBinder.Eval(Container.DataItem, "CategoryID") %>
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
<BR>
Chapter 13 - Developing<B>Category
a Custom Data Provider
Name: </B>
Chapter 14 - Developing<%#Database Web Applications using ASP.NET
DataBinder.Eval(Container.DataItem, "CategoryName")%>
Chapter 15 - Using ADO.NET
<BR>in Xml Web Services
Chapter 16 - ASP.NET Server Controls and Data</B>
<B>Description: Binding
Chapter 17 - Building Real-World Web Applications
<%# DataBinder.Eval(Container.DataItem, "Description") %>
Chapter 18 - Object-Relational
<BR> Mapping in .NET
Chapter 19 - Mapped </FONT>
Objects: Performance Considerations and Data Binding
Chapter 20 - COM </ItemTemplate>
Interoperability and ADO.NET
<HeaderTemplate>
Chapter 21 - Messaging
<font
Chapter 22 - SQL Server face="verdana"
and ADO.NET: size="3">
Notes on Performance
DataGrid
Appendix A - Relational Databases:with
Some Template Columns
Basic Concepts
</font>
Appendix B - Commonly Used SQL Statements
</HeaderTemplate>
Appendix C - ADO.NET Frequently Asked Questions
<FooterTemplate>
Index
<font face="verdana" size="2">DataGrid Footer </font>
List of Figures
</FooterTemplate>
List of Tables
</ASP:TemplateColumn>
List of Listings
</Columns>
List of Sidebars
</ASP:DataGrid>
</form>
</body>
</html>
So, the
Table first thing you need to do is to provide some buttons for the DataGrid control, which can set a
of Contents
DataGrid
Applied in editable mode.
ADO.NETBuilding You canSolutions
Data-Driven do this with the help of EditCommand columns. The
EditCommand column adds an Edit button to the DataGrid control. When you click the Edit button, it
Introduction
changes the control's current cells into TextBox controls and provides Update and Cancel buttons.
Chapter 1 - ADO.NET Basics
Chapter 2 - Data Componentsclass
TheEditCommandColumn in Visual Studio .NET
represents an EditCommand column. This class provides properties
Chapter 3 ButtonType,
including - ADO.NET in Disconnected
CancelText, Environments
EditText, and UpdateText. The ButtonType property
Chapter 4 - whether
represents ADO.NETthe
in Connected
buttons areEnvironments
hyperlink buttons or push buttons. The CancelText,EditText, and
Chapter 5 - Handling
UpdateText ADO.NET
properties Events
represent the text of the Cancel, Edit, and Update buttons. For example, the
following
Chapter 6 code sets the XML
- Integrating with ADO.NET
EditCommandColumn properties:
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
Chapter 8 - Constraints and Data Relations
<asp:EditCommandColumn
Chapter 9 - ADO.NET Exception Handling
ButtonType="LinkButton"
Chapter 10 - Working with the ODBC .NET Data Provider
UpdateText="Save"
Chapter 11 - Stored Procedures and Views
CancelText="Cancel"
EditText="Edit">
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
<ItemStyle
Chapter Font-Names="verdana"
13 - Developing a Custom Data Provider ForeColor="White"
BackColor="Red">
Chapter 14 - Developing Database Web Applications using ASP.NET
</ItemStyle>
Chapter 15 - Using ADO.NET in Xml Web Services
</asp:EditCommandColumn>
Chapter 16 - ASP.NET Server Controls and Data Binding
Chapter 17 - Building Real-World Web Applications
Chapter 18 - Object-Relational
TheDataGrid Mapping
control with an in .NET
EditCommandColumn looks like Figure 16-17.
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
Chapter 20 - COM Interoperability and ADO.NET
Chapter 21 - Messaging
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Appendix A - Relational Databases: Some Basic Concepts
Appendix B - Commonly Used SQL Statements
Appendix C - ADO.NET Frequently Asked Questions
Index
List of Figures
List of Tables
List of Listings
List of Sidebars
If you click the Edit button, the current row of the DataGrid will have TextBoxcontrols and the Edit
button will be replaced with Save and Cancel buttons, as shown in Figure 16-18.
Applied ADO.NET: Building Data-Driven Solutions
by Mahesh Chand and David Talbot ISBN:1590590732
Apress 2003 (928 pages)
This text provides extensive coverage of ADO.NET technology
including ADO.NET internals, namespaces, classes, and
interfaces, and takes a comprehensive look at XML
namespaces and classes, and how to integrate both with
ADO.NET.
Table of Contents
Applied ADO.NETBuilding Data-Driven Solutions
Introduction
Chapter 1 - ADO.NET Basics
Figure
Chapter 2 - 16-18: DataGridinwith
Data Components Save
Visual and .NET
Studio Cancel options
Chapter 3 - ADO.NET in Disconnected Environments
Chapter 4 You
Note - ADO.NET in Connected
can change the textEnvironments
of the Update and Cancel buttons by setting the EditText,
Chapter 5 UpdateText,
- Handling ADO.NET Events
and CancelText properties.
Chapter 6 - Integrating XML with ADO.NET
After setting
Chapter 7 - Datathe EditCommandColumn properties,
Binding and Windows Forms you need
Data-Bound to write the button click event handlers. The
Controls
OnCancelCommand,
Chapter and Data Relations and OnEditCommand methods of the DataGrid control are
OnUpdateCommand,
8 - Constraints
responsible
Chapter for raisingException
9 - ADO.NET the Cancel, Update, and Edit button click events, respectively. The following code
Handling
adds event
Chapter 10 - handlers for these
Working with commands:
the ODBC .NET Data Provider
Chapter 11 - Stored Procedures and Views
OnCancelCommand="dtGridCancel"
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
OnUpdateCommand="dtGridUpdate"
Chapter 13 - Developing a Custom Data Provider
OnEditCommand="dtGridEdit"
Chapter 14 - Developing Database Web Applications using ASP.NET
DataKeyField="CategoryID"
Chapter 15 - Using ADO.NET in Xml Web Services
Chapter 16 - ASP.NET Server Controls and Data Binding
Chapter
Now you 17need
- Building Real-World
to write the codeWeb Applications
for these command handlers. Editing in a DataGrid control works in a
Chapter
similar 18
way- to
Object-Relational
the DataListMapping
control.inListing
.NET 16-26 shows the complete code of an editable DataGrid.
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
Listing20
Chapter 16-26:
- COMEditableDataGrid
Interoperability and ADO.NET
Chapter 21 - Messaging
Chapter 22 - SQLNamespace="System.Data.SqlClient"
<%@ Import Server and ADO.NET: Notes on Performance %>
Appendix A - Relational Databases: Some Basic Concepts
<%@ Import Namespace="System.Data" %>
Appendix
<HTML>B - Commonly Used SQL Statements
Appendix
<HEAD>C - ADO.NET Frequently Asked Questions
Index <title>Editable DataGrid Sample</title>
<script language="VB" runat="server">
List of Figures
Shared
List ConnectionString As String = "user id=sa;password=;" & _
of Tables
"Initial Catalog=Northwind;" & _
List of Listings
"Data Source=MCB;"
List of Sidebars
Shared conn As SqlConnection = Nothing
Shared adapter As SqlDataAdapter = Nothing
Shared sql As String = Nothing
Shared cmd as SqlCommand = Nothing
Shared ds as DataSet = Nothing
Table of Contents
<Columns>
Applied ADO.NETBuilding Data-Driven Solutions
<asp:BoundColumn DataField="CategoryID" ReadOnly="True"
Introduction HeaderText="ID" FooterText="Category ID">
Chapter 1 - ADO.NET Basics
</asp:BoundColumn>
Chapter 2 - Data Components in VisualDataField="CategoryName"
<asp:BoundColumn Studio .NET
Chapter 3 HeaderText="Category
- ADO.NET Name" FooterText="Name of Category">
in Disconnected Environments
Chapter 4 </asp:BoundColumn>
- ADO.NET in Connected Environments
Chapter 5 <asp:BoundColumn
- Handling ADO.NET Events DataField="Description" HeaderText="Description"
Chapter 6 FooterText="Category
- Integrating XML with ADO.NET Description">
Chapter 7 </asp:BoundColumn>
- Data Binding and Windows Forms Data-Bound Controls
Chapter 8
<asp:EditCommandColumn
- Constraints and Data Relations
ButtonType="LinkButton"
Chapter 9 - ADO.NET Exception Handling
UpdateText="Save"
Chapter 10 - Working with the ODBC .NET Data Provider
CancelText="Cancel"
Chapter 11 - Stored Procedures and Views
EditText="Edit">
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
<ItemStyle Font-Names="verdana" ForeColor="White"
Chapter 13 - Developing a Custom Data Provider
BackColor="Red">
Chapter 14 - Developing
</ItemStyle>Web Applications using ASP.NET
Database
Chapter 15 - Using ADO.NET in Xml Web Services
</asp:EditCommandColumn>
Chapter 16 - ASP.NET
</Columns> Server Controls and Data Binding
Chapter 17
</ASP:DataGrid> Web Applications
- Building Real-World
Chapter</form>
18 - Object-Relational Mapping in .NET
</BODY>
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
</HTML>
Chapter 20 - COM Interoperability and ADO.NET
Chapter 21 - Messaging
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Appendix A - Relational Databases: Some Basic Concepts
Sorting
Appendix B -and Searching
Commonly inStatements
Used SQL a DataGrid
Appendix C - ADO.NET Frequently Asked Questions
TheDataGrid control provides partial built-in support for sorting. The AllowSorting property's true
Index
value makes DataGrid columns link buttons, which can sort a column's values. The OnSortCommand
List of Figures
method raises the sort event of the control. The following code activates the sorting in a DataGrid:
List of Tables
List of Listings
<ASP:DataGrid id="dtGrid"
List of Sidebars
AllowSorting="True"
OnSortCommand="dtGridSort"
runat="server">
</ASP:DataGrid>
TheOnSortCommand handler provides sorting data as the name of the column by using
DataGridSortCommandEventArgs.SortExpression, as shown in the following code:
Once you know the column, you can simply construct an ORDER BY query and refill the data in the
control.
Table Listing 16-27 shows the complete code for sorting in a DataGrid control.
of Contents
Applied ADO.NETBuilding Data-Driven Solutions
Listing 16-27: Implementing Sorting in a DataGrid Control
Introduction
Chapter 1 - ADO.NET Basics
<%@ Import
Chapter 2 - DataNamespace="System.Data.SqlClient"
Components in Visual Studio .NET %>
<%@ Import Namespace="System.Data"
Chapter 3 - ADO.NET in Disconnected Environments %>
<HTML>
Chapter 4 - ADO.NET in Connected Environments
<HEAD>
Chapter 5 - Handling ADO.NET Events
<title>Editable DataGrid Sample</title>
Chapter 6 - Integrating XML with ADO.NET
<script language="VB" runat="server">
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
Shared ConnectionString As String = "user id=sa;password=;" & _
Chapter 8 - Constraints and Data Relations
"Initial Catalog=Northwind;" & _
Chapter 9 - ADO.NET Exception Handling
"Data Source=MCB;"
Chapter 10 - Working
Shared conn As withSqlConnection
the ODBC .NET Data= Provider
Nothing
Chapter 11 - Stored Procedures and Views
Shared adapter As SqlDataAdapter = Nothing
Chapter 12 - Oracle,
Shared sql As SQLXML,
Stringand =Other .NET Data Providers
Nothing
Chapter 13 - Developing
Shared a Custom Data =
cmd as SqlCommand Provider
Nothing
Chapter 14 - Developing
Shared Database =Web
ds as DataSet Applications using ASP.NET
Nothing
Chapter 15 - Using ADO.NET in Xml Web Services
Private
Chapter Sub Page_Load(ByVal
16 - ASP.NET sender
Server Controls and Data As System.Object, _
Binding
ByVal
Chapter 17 -eBuilding
As System.EventArgs) Handles MyBase.Load
Real-World Web Applications
Chapter'Put user code toMapping
18 - Object-Relational initialize
in .NET the page here
ChapterIf
19 Not IsPostBack
- Mapped Then
Objects: Performance Considerations and Data Binding
Chapter FillDataGrid("")
20 - COM Interoperability and ADO.NET
End If
Chapter 21 - Messaging
End Sub
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Appendix A - Relational Databases: Some Basic Concepts
' FillDataGrid method
Appendix B - Commonly Used SQL Statements
Private Sub FillDataGrid(str as String)
Appendix C - ADO.NET Frequently Asked Questions
conn = New SqlConnection(ConnectionString)
Index If conn.State <> ConnectionState.Closed Then
List of Figures
conn.Open()
List of Tables
End If
List of Listings
if str = "" Then
List of Sidebarssql = "SELECT * FROM Categories"
Else
sql = "SELECT * FROM Categories ORDER BY " + str
End If
ds = New DataSet()
adapter = New SqlDataAdapter(sql, conn)
adapter.Fill(ds)
dtGrid.DataSource = ds.Tables(0)
dtGrid.DataBind()
If conn.State = ConnectionState.Open Then
conn.Close()
End If
End Sub
Applied ADO.NET: Building Data-Driven Solutions
by Mahesh
' Sort Event Chand and David Talbot
handler ISBN:1590590732
Apress 2003 (928 pages)
Sub dtGridSort(obj as Object, args as DataGridSortCommandEventArgs)
This text
Dim sortExpr asprovides
String extensive coverage of ADO.NET technology
including ADO.NET
sortExpr = args.SortExpressioninternals, namespaces, classes, and
interfaces, and takes a comprehensive look at XML
FillDataGrid(sortExpr)
namespaces and classes, and how to integrate both with
End Sub ADO.NET.
</script>
Table</HEAD>
of Contents
Applied ADO.NETBuilding Data-Driven Solutions
<BODY>
Introduction
<font face="verdana" size="4">Sorting in DataGrid</font>
Chapter<br>
1 - ADO.NET Basics
Chapter<form
2 - Data Components in Visual
runat="server" Studio .NET
ID="Form1">
Chapter 3 <ASP:DataGrid id="dtGrid"
- ADO.NET in Disconnected Environments
Chapter 4 AllowSorting="True"
- ADO.NET in Connected Environments
Chapter 5 OnSortCommand="dtGridSort"
- Handling ADO.NET Events
Chapter 6 runat="server">
- Integrating XML with ADO.NET
Chapter</ASP:DataGrid>
7 - Data Binding and Windows Forms Data-Bound Controls
</form>
Chapter 8- Constraints and Data Relations
</BODY>
Chapter 9 - ADO.NET Exception Handling
Chapter 10 - Working with the ODBC .NET Data Provider
Chapter 11 - Stored Procedures and Views
Chapter 12 - Oracle,
Caution SQLXML,
You can't andtext,
use the Other .NET
ntext, Data
and Providers
image data types in an ORDER BY clause.
Chapter 13 - Developing a Custom Data Provider
To implement
Chapter searching
14 - Developing in a DataGrid
Database control, you
Web Applications usingneed to read the name of the column and a value for
ASP.NET
which you're
Chapter searching.
15 - Using After
ADO.NET that Web
in Xml you can simply construct a SELECT..WHERE clause and refill the data.
Services
If you don't
Chapter 16 - want to sort
ASP.NET andControls
Server read data from
and Dataa Binding
data source, you can simply create a DataView control
from a 17
Chapter data source using
- Building a DataSet,
Real-World apply sort and filter criteria on a DataView, and bind the
Web Applications
18 - to
DataView
Chapter the DataGridMapping
Object-Relational control.in(See
.NETthe DataGrid and "Implementing Search in a DataGrid"
sections
Chapter 19of- Chapter 7 for more
Mapped Objects: information.)
Performance Sorting andand
Considerations searching works in both the controls in the same
Data Binding
way because it's done through ADO.NET. The only difference is the data binding.
Chapter 20 - COM Interoperability and ADO.NET
Chapter 21 - Messaging
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Appendix A - Relational Databases: Some Basic Concepts
Appendix B - Commonly Used SQL Statements
Appendix C - ADO.NET Frequently Asked Questions
Index
List of Figures
List of Tables
List of Listings
List of Sidebars
Summary Applied ADO.NET: Building Data-Driven Solutions
by Mahesh Chand and David Talbot ISBN:1590590732
Even though the Apress
data-binding concept
2003 (928 pages)in ASP.NET server controls looks similar to Windows Forms data
binding, they workThis
in totally different ways. Incoverage
text provides extensive this chapter, you learned
of ADO.NET the basic concepts of data binding
technology
in ASP.NET server controls and how to implement data binding in
including ADO.NET internals, namespaces, classes, and simple and complex data-bound
controls. interfaces, and takes a comprehensive look at XML
namespaces and classes, and how to integrate both with
ADO.NET.
Templates and columns play a major role in the formatting and data binding of controls. This chapter
discussed how templates and columns work in ASP.NET. We also discussed the various functionality of
theDataList and DataGrid ASP.NET server controls.
Table of Contents
Applied ADO.NETBuilding
In the next chapter, you'llData-Driven Solutionsdata-driven Web application using ASP.NET. You'll use the
create a real-world
Introduction
major data-binding concepts discussed in this chapter.
Chapter 1 - ADO.NET Basics
Chapter 2 - Data Components in Visual Studio .NET
Chapter 3 - ADO.NET in Disconnected Environments
Chapter 4 - ADO.NET in Connected Environments
Chapter 5 - Handling ADO.NET Events
Chapter 6 - Integrating XML with ADO.NET
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
Chapter 8 - Constraints and Data Relations
Chapter 9 - ADO.NET Exception Handling
Chapter 10 - Working with the ODBC .NET Data Provider
Chapter 11 - Stored Procedures and Views
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Chapter 13 - Developing a Custom Data Provider
Chapter 14 - Developing Database Web Applications using ASP.NET
Chapter 15 - Using ADO.NET in Xml Web Services
Chapter 16 - ASP.NET Server Controls and Data Binding
Chapter 17 - Building Real-World Web Applications
Chapter 18 - Object-Relational Mapping in .NET
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
Chapter 20 - COM Interoperability and ADO.NET
Chapter 21 - Messaging
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Appendix A - Relational Databases: Some Basic Concepts
Appendix B - Commonly Used SQL Statements
Appendix C - ADO.NET Frequently Asked Questions
Index
List of Figures
List of Tables
List of Listings
List of Sidebars
Chapter Applied
17: Building Real-WorldISBN:1590590732
Web Applications
ADO.NET: Building Data-Driven Solutions
by Mahesh Chand and David Talbot
Apressthe
Chapter 14 discussed 2003 (928of
basics pages)
ASP.NET and how to write data-driven Web applications using
ASP.NET and ADO.NET. Chapter extensive
This text provides coverage
16 discussed data of ADO.NET
binding technology
in ASP.NET and ASP.NET server controls
including ADO.NET internals, namespaces, classes, and
and how to use these controls to develop data-bound Web applications.
interfaces, and takes a comprehensive look at XML
namespaces and classes, and how to integrate both with
In this chapter, we'll use the functionality discussed in Chapter 14 and 16. In this chapter, you'll see how
ADO.NET.
you can write a real-world online job board where candidates can post their resumes, recruiters can post
their jobs, recruiters can browse the available resumes, and job hunters can browse and apply for the
Table of Contents
available jobs on the site.
Applied ADO.NETBuilding Data-Driven Solutions
Table of Contents
Applied ADO.NETBuilding Data-Driven Solutions
Introduction
Chapter 1 - ADO.NET Basics
Chapter 2 - 17-2:
Figure Data Components in Visual
Schema of the Studio .NET
Job table
Chapter 3 - ADO.NET in Disconnected Environments
Chapter 4 - ADO.NET in Connected Environments
Figure 17-3 shows the Resumes table schema, which has 10 columns. These columns store the
Chapter 5 - Handling ADO.NET Events
information about a candidate including a detailed resume.
Chapter 6 - Integrating XML with ADO.NET
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
Chapter 8 - Constraints and Data Relations
Chapter 9 - ADO.NET Exception Handling
Chapter 10 - Working with the ODBC .NET Data Provider
Chapter 11 - Stored Procedures and Views
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Chapter 13 - Developing a Custom Data Provider
Chapter 14 - Developing Database Web Applications using ASP.NET
Chapter 15 - Using ADO.NET in Xml Web Services
Chapter 16 - ASP.NET Server Controls and Data Binding
Figure 17-3: Schema of the Resumes table
Chapter 17 - Building Real-World Web Applications
Chapter
Figure 18 - Object-Relational
17-4 shows the UsersMapping in .NET which has only three columns to store the user ID, password,
table schema,
Chapter 19 -address.
and email Mapped Objects: Performance Considerations and Data Binding
Chapter 20 - COM Interoperability and ADO.NET
Chapter 21 - Messaging
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Appendix A - Relational Databases: Some Basic Concepts
Appendix B - Commonly Used SQL Statements
Appendix C - ADO.NET Frequently Asked Questions
Index
Figure 17-4: Schema of the Users table
List of Figures
List of Tables
List of Listings
List of Sidebars
DevelopingApplied
the Online
ADO.NET:Job Board
Building Application
Data-Driven Solutions
by Mahesh Chand and David Talbot ISBN:1590590732
When you start the application,
Apress thepages)
2003 (928 first page is Login.aspx. When you create an ASP.NET Web
application, it adds WebForm1 as the first page
This text provides extensive of the of
coverage application. You can simply change the name of this
ADO.NET technology
page to Login.aspx.including ADO.NET internals, namespaces, classes, and
interfaces, and takes a comprehensive look at XML
namespaces and classes, and how to integrate both with
Creating the Login.aspx Page
ADO.NET.
TheLogin.aspx page allows users to enter their user ID and password and checks these against the
Table
dataof Contents
stored in the database. If the user ID and password are found in the database table, then you let them
Applied
see theADO.NETBuilding
available options.Data-Driven Solutions
Otherwise they need to register as a new user.
Introduction
TheLogin.aspx
Chapter 1
page looks like Figure 17-5. As you can see from this page, it has two TextBox
- ADO.NET Basics
controls, one Hyperlink control, five Button controls, two Label controls, and a StatusBar control.
Chapter 2 - Data Components in Visual Studio .NET
When a user comes to this page, the buttons (Post a New Job, Post a New Resume, View Jobs, and View
Chapter 3 - ADO.NET in Disconnected Environments
Available Resumes) are hidden. These buttons are visible when user successfully logs in to the site.
Chapter 4 - ADO.NET in Connected Environments
Chapter 5 - Handling ADO.NET Events
Chapter 6 - Integrating XML with ADO.NET
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
Chapter 8 - Constraints and Data Relations
Chapter 9 - ADO.NET Exception Handling
Chapter 10 - Working with the ODBC .NET Data Provider
Chapter 11 - Stored Procedures and Views
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Chapter 13 - Developing a Custom Data Provider
Chapter 14 - Developing Database Web Applications using ASP.NET
Chapter 15 - Using ADO.NET in Xml Web Services
Chapter 16 - ASP.NET Server Controls and Data Binding
Chapter 17 - Building Real-World Web Applications
Chapter 18 - Object-Relational Mapping in .NET
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
Chapter 20 - COM Interoperability and ADO.NET
Chapter 21 - Messaging
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Appendix A - Relational Databases: Some Basic Concepts
Appendix B - Commonly Used SQL Statements
Figure
Appendix C - 17-5: TheFrequently
ADO.NET Login.aspx page
Asked Questions
Index
Listing 17-1 shows the code for the Login button click event handler. Here you simply read the values
List of Figures
entered in the User ID and Password TextBox controls and check if these values exist in the database.
List of Tables
As you can see from this code, you create and open a connection, read UserID and Password from the
List of Listings
Users table by creating a SqlCommand object, and call its ExecuteReader method that creates a
List of Sidebars
SqlDataReader. You use only a single row because a single row will tell you whether the user exists in
the table. After, that if the user exists, you display the Post a New Job, Post a New Resume, View Jobs,
and View Available Resumes buttons and hide the TextBox,Label, and Hyperlink controls. You also
display a message in the StatusBar control, if the user is logged in or not.
The Post a New Job, Post a New Resume, View Available Resumes, and View Jobs button clicks simply
open new Web pages: PostJob.aspx,PostResume.aspx,DisplayData.aspx, and
Resumes.aspx, respectively (we'll discuss them in a moment). Listing 17-2 shows the code for these
button click eventApplied ADO.NET:
handlers. Building
As you can Data-Driven
see, the code uses Solutions
the Me.Response.Redirect method to
by Mahesh
open the new Web pages. Chand and David Talbot ISBN:1590590732
Apress 2003 (928 pages)
Listing 17-2: TheThis
Button Click Event
text provides Handlers
extensive coverage of ADO.NET technology
including ADO.NET internals, namespaces, classes, and
interfaces, and takes a comprehensive look at XML
Private Sub PostResumeBtn_Click(ByVal
namespaces and classes, and how to sender As System.Object,
integrate both with _
ByVal e AsADO.NET.
System.EventArgs) Handles PostResumeBtn.Click
Me.Response.Redirect("PostResume.aspx")
End Sub
Table of Contents
Applied ADO.NETBuilding Data-Driven Solutions
Private Sub ViewJobsBtn_Click(ByVal sender As System.Object, _
Introduction
ByVal e As System.EventArgs) Handles ViewJobsBtn.Click
Chapter 1 -Me.Response.Redirect("DisplayData.aspx")
ADO.NET Basics
Chapter
End Sub2 - Data Components in Visual Studio .NET
Chapter
Private3 -Sub
ADO.NET in Disconnected Environments
PostJobBtn_Click(ByVal sender As System.Object, _
ChapterByVal
4 - ADO.NET in Connected Environments
e As System.EventArgs) Handles PostJobBtn.Click
Chapter 5 -Me.Response.Redirect("PostJob.aspx")
Handling ADO.NET Events
Chapter
End Sub6 - Integrating XML with ADO.NET
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
Private
Chapter 8 -Sub ViewResumesBtn_Click(ByVal
Constraints and Data Relations sender As System.Object, _
ByVal e As System.EventArgs)
Chapter 9 - ADO.NET Exception Handling Handles ViewResumesBtn.Click
Me.Response.Redirect("Resumes.aspx")
Chapter 10 - Working with the ODBC .NET Data Provider
End Sub
Chapter 11 - Stored Procedures and Views
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Chapter 13 - Developing a Custom Data Provider
Chapter 14 - Developing Database Web Applications using ASP.NET
Creating the Register.aspx Page
Chapter 15 - Using ADO.NET in Xml Web Services
Chapter 16 - ASP.NET Server Controls and Data Binding
Now you
Chapter 17add a new Real-World
- Building Web page Web
called Register.aspx to the application. This page reads the user ID,
Applications
password, and email address of the user. The page looks like Figure 17-7, where three TextBox controls
Chapter 18 - Object-Relational Mapping in .NET
are used to enter the user ID, password, and email address. The Register button click action saves these
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
values to the database. The Back to Home Page button simply goes back to the Login.aspx page.
Chapter 20 - COM Interoperability and ADO.NET
Chapter 21 - Messaging
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Appendix A - Relational Databases: Some Basic Concepts
Appendix B - Commonly Used SQL Statements
Appendix C - ADO.NET Frequently Asked Questions
Index
List of Figures
List of Tables
List of Listings
List of Sidebars
Listing 17-3 shows the code for both of the button click event handlers. As you can see from this code, for
theRegister button, you construct a SqlCommand using an INSERT..INTO SQL query, add
parameters and their values by reading from the TextBox controls of the page, and execute the query.
This query adds a new record to the Users table of the database.
Table of Contents
Applied ADO.NETBuilding Data-Driven Solutions
Introduction
Chapter 1 - ADO.NET Basics
Figure 17-8: TheContact.aspx page
Chapter 2 - Data Components in Visual Studio .NET
Chapter 3 -has
This page ADO.NET in Disconnected
only few lines of code Environments
for the Send Message click event handler, which is shown in Listing
Chapter 4 you
17-4. As - ADO.NET
can seeinfrom
Connected Environments
this code, you simply create a MailMessage that represents a mail message
and set5its -From,
Chapter Handling and Body properties. After that we set SmtpMail.SmtpServer to the
ADO.NET Events
To,Subject,
server, 6from
Chapter which we're
- Integrating sending
XML the email. Our mail server is mail5.fiberspeed.net. You must
with ADO.NET
change7it to
Chapter your Binding
- Data email server.
and Windows Forms Data-Bound Controls
Chapter 8 - Constraints and Data Relations
Listing 17-4:
Chapter 9
Send Message Click Event Handler
- ADO.NET Exception Handling
Chapter 10 - Working with the ODBC .NET Data Provider
Private
Chapter 11 -Sub SendMailBtn_Click(ByVal
Stored Procedures and Views sender As System.Object, _
ByVal
Chapter 12 -eOracle,
As System.EventArgs)
SQLXML, and Other .NETHandles SendMailBtn.Click
Data Providers
Chapter 13 - Developing a Custom Data Provider
ChapterDim
14 -msg As MailMessage
Developing = New MailMessage()
Database Web Applications using ASP.NET
msg.To = ToTextBox.Text
Chapter 15 - Using ADO.NET in Xml Web Services
msg.From = FromTextBox.Text
Chapter 16 - ASP.NET Server Controls and Data Binding
msg.Subject = SubTextBox.Text
Chapter 17 - Building Real-World Web Applications
msg.Body = MsgTextBox.Text
Chapter 18 - Object-Relational Mapping in .NET
SmtpMail.SmtpServer = "mail5.fiberspeed.net"
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
SmtpMail.Send(msg)
ChapterStatusBar.Text
20 - COM Interoperability and ADO.NET
= "Message recieved. We will contact you soon. "
Chapter
End Sub21 - Messaging
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Appendix A - Relational Databases: Some Basic Concepts
Appendix B - Commonly Used SQL Statements
Appendix C - ADO.NET Frequently Asked Questions
Creating the PostJob.aspx Page
Index
List
Now of you
Figures
add the PostJob.aspx page to the project. This page posts a new job to the job board. This
List of Tables
page reads the information related to a job and adds to the Job table of the database. This page looks like
List of Listings
Figure 17-9. As you can see from this page, there are five TextBox controls to read the company name,
List of Sidebars
description of the job, contact person, requirements, and job details.
Applied ADO.NET: Building Data-Driven Solutions
by Mahesh Chand and David Talbot ISBN:1590590732
Apress 2003 (928 pages)
This text provides extensive coverage of ADO.NET technology
including ADO.NET internals, namespaces, classes, and
interfaces, and takes a comprehensive look at XML
namespaces and classes, and how to integrate both with
ADO.NET.
Table of Contents
Applied ADO.NETBuilding Data-Driven Solutions
Introduction
Chapter 1 - ADO.NET Basics
Chapter 2 - Data Components in Visual Studio .NET
Chapter 3 - 17-9:
Figure ADO.NET
Thein Disconnected Environments
PostJob.aspx page
Chapter 4 - ADO.NET in Connected Environments
Chapter 5 - Handling ADO.NET Events
Besides the TextBox controls, this page also has three Button controls and a StatusBar control. The
Chapter 6 - Integrating XML with ADO.NET
Post Job button click event handler reads data from the TextBox controls and adds it to the Job database
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
table.Listing 17-5 shows the code for the Post Job button click event handler. As you can see from this
Chapter 8 -simply
code, you Constraints and a
construct Data Relations using an INSERT..INTO SQL query, add its parameters, and
SqlCommand
Chapter 9 - ADO.NET
execute the query. Exception Handling
Chapter 10 - Working with the ODBC .NET Data Provider
Listing11
Chapter 17-5: The Post
- Stored Job Button
Procedures Click Event Handler
and Views
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Chapter
Private13 -Sub
Developing a Custom Data Provider
SaveBtn_Click(ByVal sender As System.Object, _
Chapter
ByVal14 -eDeveloping Database Web Applications
As System.EventArgs) HandlesusingSaveBtn.Click
ASP.NET
Chapterconn
15 - Using
= New ADO.NET in Xml Web Services
SqlConnection()
Chapterconn.ConnectionString
16 - ASP.NET Server Controls =
andconnectionString
Data Binding
Chapter'17 - Building Real-World
Construct an INSERTWeb Applications
query with parameters
Chaptersql
18 -=Object-Relational
"INSERT INTO Job(Company,
Mapping in .NET Contacts, Description, " & _
Chapter"Requirements, Details,
19 - Mapped Objects: PostingDate)
Performance " &Data
Considerations and _ Binding
Chapter"VALUES
20 - COM (@comp, @cont,
Interoperability @req, @des, @det, @post)"
and ADO.NET
Chaptercmd
21 -=Messaging
New SqlCommand(sql, conn)
Chaptercmd.CommandType = CommandType.Text
22 - SQL Server and ADO.NET: Notes on Performance
cmd.CommandText = sql
Appendix A - Relational Databases: Some Basic Concepts
' Add parameters with values from text boxes
Appendix B - Commonly Used SQL Statements
cmd.Parameters.Add("@comp", CompanyTxtBox.Text)
Appendix C - ADO.NET Frequently Asked Questions
cmd.Parameters.Add("@cont", ContactsTxtBox.Text)
Index
cmd.Parameters.Add("@req", ReqTxtBox.Text)
List of Figures
cmd.Parameters.Add("@des", DesTxtBox.Text)
List of Tables
cmd.Parameters.Add("@det", DetailsTxtBox.Text)
List of Listings
cmd.Parameters.Add("@post", _
List of Sidebars
SqlDbType.DateTime).Value = DateTime.Today.ToString()
' Open connection
If conn.State <> ConnectionState.Open Then
conn.Open()
End If
' Execute the query
cmd.ExecuteNonQuery()
' Close connection
If conn.State <> ConnectionState.Closed Then
conn.Close()
End If
ClearFields()
StatusBar.Text = "Thank you for Job Posting"
End Sub Applied ADO.NET: Building Data-Driven Solutions
by Mahesh Chand and David Talbot ISBN:1590590732
Apress 2003 (928 pages)
This text provides extensive coverage of ADO.NET technology
The Reset Fieldsincluding ADO.NET
button simply internals,
clears namespaces,
the TextBox classes,
controls, and in Listing 17-6.
as shown
interfaces, and takes a comprehensive look at XML
namespaces and classes, and how to integrate both with
Listing 17-6: TheADO.NET.
Reset Fields Click Event Handler
Table of Contents
Applied ADO.NETBuilding Data-Driven Solutions
Introduction
Chapter 1 - ADO.NET Basics
Chapter 2 - Data Components in Visual Studio .NET
Chapter 3 - ADO.NET in Disconnected Environments
Figure 17-10: ThePostResume.aspx page
Chapter 4 - ADO.NET in Connected Environments
Chapter 5 - Handling ADO.NET Events
Now let's
Chapter 6 look at the code.
- Integrating XMLYou
withadd the options to the Education and Work Status combo boxes. Listing
ADO.NET
17-8 shows
Chapter the code.
7 - Data Asand
Binding youWindows
can see,Forms
the FillListBoxes methods add options to the combo boxes.
Data-Bound Controls
Chapter 8 - Constraints and Data Relations
Listing 17-8:
Chapter 9
Adding Options to Post Resume Page
- ADO.NET Exception Handling
Chapter 10 - Working with the ODBC .NET Data Provider
Private
Chapter 11 -Sub Page_Load(ByVal
Stored Procedures and Viewssender As System.Object, _
ByVal
Chapter 12 -eOracle,
As System.EventArgs)
SQLXML, and Other .NETHandles MyBase.Load
Data Providers
Chapter'Put user code
13 - Developing to initialize
a Custom Data Provider the page here
ChapterFillListBoxes()
14 - Developing Database Web Applications using ASP.NET
End Sub
Chapter 15 - Using ADO.NET in Xml Web Services
Chapter 16 - ASP.NET Server Controls and Data Binding
Private Sub FillListBoxes()
Chapter 17 - Building Real-World Web Applications
' This method adds selection data to list boxes
Chapter 18 - Object-Relational Mapping in .NET
EduList.Items.Add("Master's Degree")
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
EduList.Items.Add("Bachelor's Degree")
ChapterEduList.Items.Add("Some
20 - COM Interoperability and ADO.NET
College")
ChapterEduList.Items.Add("2
21 - Messaging Yrs Diploma")
ChapterStatusList.Items.Add("US
22 - SQL Server and ADO.NET: Notes on Performance
Citizen")
Appendix A - Relational Databases: Some
StatusList.Items.Add("Green Card Basic Concepts
or Authorized to work")
Appendix B - Commonly Used SQL Statements
StatusList.Items.Add("H1 Visa")
Appendix C - ADO.NET Frequently Asked Questions
StatusList.Items.Add("Need Sponsorship")
End Sub
Index
List of Figures
List of Tables
List of Listings
The Post Resume button click adds the contents of the page to the Resumes table of the database. Listing
List of Sidebars
17-9 shows the code for this button click event handler. As you can see, you again create a SqlCommand
with an INSERT..INTO SQL query, sets its parameters by reading their values from the fields filled by the
user, and execute the query. This option adds a new record to the Resumes table.
The code for filling data from the Resumes table to the DataList control and navigating through the
Table of Contents
resumes is the same as the code you saw on the DisplayData.aspx page for displaying a job. You just
Applied
need toADO.NETBuilding Data-Driven
change the database Solutions
table name from Job to Resumes in the FillDataGrid method. The rest
Introduction
is the same. For more details, download the source code from the Apress Web site (www.apress.com).
Chapter 1 - ADO.NET Basics
Chapter 2
- Data Components in Visual Studio .NET
Creating the dnjHeader.aspx Page
Chapter 3 - ADO.NET in Disconnected Environments
Chapter 4 one
There is - ADO.NET in Connected
more thing left to do. Environments
To make the application a little more interactive, you'll design one more
page called
Chapter dnjHeader.aspx.
5 - Handling ADO.NET Events This page has an image and two HyperLink controls: Home Page and
Contact6 Us.
Chapter The HomeXML
- Integrating Page linkADO.NET
with simply redirects the browser to the Login.aspx page, and the Contact
Us link 7redirects
Chapter - Data the browser
Binding to the Contacts.aspx
and Windows page.
Forms Data-Bound This page works as a header of he job board.
Controls
That means
Chapter every pageand
8 - Constraints of the job
Data board application includes this page. Figure 17-13 shows the
Relations
Chapter 9 - ADO.NETpage.
dnjHeader.aspx Exception Handling
Chapter 10 - Working with the ODBC .NET Data Provider
Chapter 11 - Stored Procedures and Views
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Chapter 13 - Developing a Custom Data Provider
Chapter 14 - Developing Database Web Applications using ASP.NET
Chapter 15 - Using ADO.NET in Xml Web Services
Chapter 16 - ASP.NET Server Controls and Data Binding
Chapter 17 - Building Real-World Web Applications
Chapter 18 - Object-Relational Mapping in .NET
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
Chapter 20 - COM Interoperability and ADO.NET
Chapter 21 - Messaging
Chapter 22 - 17-13:
Figure SQL Server and ADO.NET: Notespage
ThednjHeader.aspx on Performance
Appendix A - Relational Databases: Some Basic Concepts
Appendix B - Commonly Used SQL Statements
To include the dnjHeader.aspx page, you use the INCLUDE keyword. The third line in the following
Appendix C - ADO.NET Frequently Asked Questions
code includes the page to other pages. You want to make sure you change the path of the page to your
Index
application's path:
List of Figures
List of Tables
<HEAD>
List of Listings
<title>Resumes</title>
List of Sidebars
<!-- #INCLUDE Virtual="/Ch17/JobBoard/dnjHeader.aspx" -->
</HEAD>
Table of Contents
Applied ADO.NETBuilding Data-Driven Solutions
Introduction
Figure 17-14: The job board
Chapter 1 - ADO.NET Basics
Chapter 2 - Data Components in Visual Studio .NET
Once you register and log in to the site, you'll see job and resume options. You can test the application by
Chapter 3 - ADO.NET in Disconnected Environments
posting a few resumes and jobs. After posting a few jobs and resumes, you can view the jobs and
Chapter 4 - ADO.NET in Connected Environments
resumes by using the View Jobs and View Available Resumes buttons. The View Jobs page looks like
Chapter 5 - Handling ADO.NET Events
Figure 17-15. You can use the buttons to move to the next, previous, first, and last job available in the
Chapter 6 - Integrating XML with ADO.NET
database.
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
Chapter 8 - Constraints and Data Relations
Chapter 9 - ADO.NET Exception Handling
Chapter 10 - Working with the ODBC .NET Data Provider
Chapter 11 - Stored Procedures and Views
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Chapter 13 - Developing a Custom Data Provider
Chapter 14 - Developing Database Web Applications using ASP.NET
Chapter 15 - Using ADO.NET in Xml Web Services
Chapter 16 - ASP.NET Server Controls and Data Binding
Chapter 17 - Building Real-World Web Applications
Chapter 18 - Object-Relational Mapping in .NET
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
Chapter 20 - COM Interoperability and ADO.NET
Chapter 21 - Messaging
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Appendix A - Relational Databases: Some Basic Concepts
Appendix B - Commonly Used SQL Statements
Appendix C - ADO.NET Frequently Asked Questions
IndexFigure 17-15: View Jobs page
List of Figures
List
The of View
TablesResumes page looks like Figure 17-16. You can use the buttons to move to the next, previous,
List
firstofand
Listings
last job available in the database.
List of Sidebars
Applied ADO.NET: Building Data-Driven Solutions
by Mahesh Chand and David Talbot ISBN:1590590732
Apress 2003 (928 pages)
This text provides extensive coverage of ADO.NET technology
including ADO.NET internals, namespaces, classes, and
interfaces, and takes a comprehensive look at XML
namespaces and classes, and how to integrate both with
ADO.NET.
Table of Contents
Applied ADO.NETBuilding Data-Driven Solutions
Introduction
Chapter 1 - ADO.NET Basics
Chapter 2 - Data Components in Visual Studio .NET
Chapter 3 - ADO.NET in Disconnected Environments
Chapter 4 - ADO.NET in Connected Environments
Chapter 5 - Handling ADO.NET Events
Chapter 6 - Integrating XML with ADO.NET
Chapter 7 - 17-16:
Figure Data Binding and Windows
The View ResumesForms
pageData-Bound Controls
Chapter 8 - Constraints and Data Relations
Chapter 9 - ADO.NET Exception Handling
Chapter 10 - Working with the ODBC .NET Data Provider
Chapter 11 - Stored Procedures and Views
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Chapter 13 - Developing a Custom Data Provider
Chapter 14 - Developing Database Web Applications using ASP.NET
Chapter 15 - Using ADO.NET in Xml Web Services
Chapter 16 - ASP.NET Server Controls and Data Binding
Chapter 17 - Building Real-World Web Applications
Chapter 18 - Object-Relational Mapping in .NET
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
Chapter 20 - COM Interoperability and ADO.NET
Chapter 21 - Messaging
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Appendix A - Relational Databases: Some Basic Concepts
Appendix B - Commonly Used SQL Statements
Appendix C - ADO.NET Frequently Asked Questions
Index
List of Figures
List of Tables
List of Listings
List of Sidebars
Improving and Modifying
Applied the Application
ADO.NET: Building Data-Driven Solutions
by Mahesh Chand and David Talbot ISBN:1590590732
To keep in mind the size of
Apress this
2003 book
(928 and the chapter, we tried to limit the functionality of the Job Board
pages)
application. However, you can modify the existing
This text provides extensive application
coverage to build
of ADO.NET a Job Board application with some
technology
more user-friendly
including ADO.NET internals, namespaces, classes, and application could be the following:
features. Some of the possible improvements to the
interfaces, and takes a comprehensive look at XML
namespaces
Adding the latest andonclasses,
job listing and page
the home how to integrate both with
ADO.NET.
Adding the latest resume listing on the home page
Table of Contents
Adding a search feature that can search jobs and resumes based on keywords
Applied ADO.NETBuilding Data-Driven Solutions
Adding features such as a resume builder, search saves, personal pages, and other resources that
Introduction
can1 help
Chapter candidates
- ADO.NET to build their resume online
Basics
Chapter 2 - Data Components in Visual Studio .NET
Categorizing jobs based on the state or country (if there is enough traffic on your site)
Chapter 3 - ADO.NET in Disconnected Environments
Chapter 4 - ADO.NET in Connected Environments
Chapter 5 - Handling ADO.NET Events
Chapter 6 - Integrating XML with ADO.NET
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
Chapter 8 - Constraints and Data Relations
Chapter 9 - ADO.NET Exception Handling
Chapter 10 - Working with the ODBC .NET Data Provider
Chapter 11 - Stored Procedures and Views
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Chapter 13 - Developing a Custom Data Provider
Chapter 14 - Developing Database Web Applications using ASP.NET
Chapter 15 - Using ADO.NET in Xml Web Services
Chapter 16 - ASP.NET Server Controls and Data Binding
Chapter 17 - Building Real-World Web Applications
Chapter 18 - Object-Relational Mapping in .NET
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
Chapter 20 - COM Interoperability and ADO.NET
Chapter 21 - Messaging
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Appendix A - Relational Databases: Some Basic Concepts
Appendix B - Commonly Used SQL Statements
Appendix C - ADO.NET Frequently Asked Questions
Index
List of Figures
List of Tables
List of Listings
List of Sidebars
Summary Applied ADO.NET: Building Data-Driven Solutions
by Mahesh Chand and David Talbot ISBN:1590590732
In this chapter, you learned
Apress how
2003 (928topages)
build a real-world job application where employers can post their jobs
and candidates can post their resumes.
This text provides extensiveObject databases
coverage are quite
of ADO.NET useful in many situations, and as a
technology
developer there are
including ADO.NET internals, namespaces, classes, and object databases as well as
quite a few situations when you need to deal with
interfaces, and takes a comprehensive look at XML
relational databases.
namespaces and classes, and how to integrate both with
ADO.NET.
In the following chapter, we cover object and relational database mappings. You'll learn the basics of the
object-mapped data model and how to create a simple video store application that allows users to load,
create, and alter videos in the library as well as check in and out videos. You'll learn how to create
Table of Contents
mapped objects as well as workarounds for common pitfalls and quirks found in ADO.NET that can
Applied ADO.NETBuilding Data-Driven Solutions
adversely affect your data model.
Introduction
Chapter 1 - ADO.NET Basics
Chapter 2 - Data Components in Visual Studio .NET
Chapter 3 - ADO.NET in Disconnected Environments
Chapter 4 - ADO.NET in Connected Environments
Chapter 5 - Handling ADO.NET Events
Chapter 6 - Integrating XML with ADO.NET
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
Chapter 8 - Constraints and Data Relations
Chapter 9 - ADO.NET Exception Handling
Chapter 10 - Working with the ODBC .NET Data Provider
Chapter 11 - Stored Procedures and Views
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Chapter 13 - Developing a Custom Data Provider
Chapter 14 - Developing Database Web Applications using ASP.NET
Chapter 15 - Using ADO.NET in Xml Web Services
Chapter 16 - ASP.NET Server Controls and Data Binding
Chapter 17 - Building Real-World Web Applications
Chapter 18 - Object-Relational Mapping in .NET
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
Chapter 20 - COM Interoperability and ADO.NET
Chapter 21 - Messaging
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Appendix A - Relational Databases: Some Basic Concepts
Appendix B - Commonly Used SQL Statements
Appendix C - ADO.NET Frequently Asked Questions
Index
List of Figures
List of Tables
List of Listings
List of Sidebars
Chapter Applied
18: Object-Relational Mapping
ADO.NET: Building Data-Driven Solutions
by Mahesh Chand and David Talbot ISBN:1590590732
in .NET
Apress 2003 (928 pages)
Overview This text provides extensive coverage of ADO.NET technology
including ADO.NET internals, namespaces, classes, and
Relational databases treat data
interfaces, in terms
and takes of rows and columns,
a comprehensive and objects treat things in terms of arrays
look at XML
namespaces and mapping
and properties. Object-relational classes, and
(ORhow to integrate
mapping) boththese
bridges with two worlds so your code can look
ADO.NET.
like object code and still store itself in a relational database.
In this chapter, you'll create a simple object data model for a video store application. You'll learn how to
Table of Contents
create mapped objects as well as workarounds for common pitfalls and quirks found in ADO.NET that can
Applied ADO.NETBuilding Data-Driven Solutions
adversely affect your data model. Let's start by discussing why you may need to worry about OR mapping.
Introduction
Chapter 1 - ADO.NET
OR mapping providesBasics
three main benefits:
Chapter 2 - Data Components in Visual Studio .NET
Chapter 3 - ADO.NET in Disconnected Environments
Encapsulation: This is one of the primary pillars of object-oriented design, and OR mapping extends
Chapter 4 - ADO.NET in Connected Environments
this concept to the database.
Chapter 5 - Handling ADO.NET Events
Chapter 6 - Integrating XML with ADO.NET
Identity:
Chapter A mapped
7 - Data object
Binding and has anForms
Windows identity. In concrete
Data-Bound terms it has a unique identifier. Most objects
Controls
that are
Chapter 8
not mapped to a database lack a real identity independent of the data presented to the end
- Constraints and Data Relations
user. Although it's possible to create an identity for the objects using hashcodes or a similar
Chapter 9 - ADO.NET Exception Handling
methodology, mapped objects take this to the next logical level.
Chapter 10 - Working with the ODBC .NET Data Provider
Chapter 11 - Stored Procedures and Views
Behavior:
Chapter DataSQLXML,
12 - Oracle, in a database does
and Other notData
.NET haveProviders
behavior. By fusing the world of databases to software
code,
Chapter 13 -you have theaunique
Developing Customopportunity to define how your data should interact with your system in a
Data Provider
clean
Chapter 14 -and reusableDatabase
Developing way. Web Applications using ASP.NET
Chapter 15 - Using ADO.NET in Xml Web Services
Visual Basic .NET (VB .NET) takes the partial support for object-oriented programming found in VB 6 to
Chapter 16 - ASP.NET Server Controls and Data Binding
the next level. By leveraging this expanded capability in VB .NET, you're presented with an opportunity to
Chapter 17 - Building
create powerful Real-World
object systemsWeb
withApplications
persistence into a medium that allows for easy integration with other
Chapter
systems18and
- Object-Relational
a simple way ofMapping
reportingin on
.NET
that data.
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
Chapter 20 - COM Interoperability and ADO.NET
Chapter 21 - Messaging
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Appendix A - Relational Databases: Some Basic Concepts
Appendix B - Commonly Used SQL Statements
Appendix C - ADO.NET Frequently Asked Questions
Index
List of Figures
List of Tables
List of Listings
List of Sidebars
Why Not Just Use
Applied a DataSet?
ADO.NET: Building Data-Driven Solutions
by Mahesh Chand and David Talbot ISBN:1590590732
ADO.NET supplies you
Apress with a (928
2003 number
pages)of powerful objects including DataSet objects to provide a means
of accessing andThis
presenting
text provides but
data, these coverage
extensive objects fall
of short in situations
ADO.NET technology where you need to provide a
clear contract between the data and your object system. They also
including ADO.NET internals, namespaces, classes, and fall short in situations when you require
interfaces,
complex validation, and
portability takes a comprehensive
between look atmediums,
multiple persistence XML or abstraction of data operation.
namespaces and classes, and how to integrate both with
So, when does a ADO.NET.
programming problem require a clear contract to be defined between the data and the
code? A good example is a situation where the data provides a means of recording history that then
requires business logic to be applied to it before presenting it to the user or making a decision. For
Table of Contents
example, an order entry system requires that logic be applied to a user's entries before being stored into a
Applied ADO.NETBuilding Data-Driven Solutions
database to determine if the user can purchase the selected items. This is a prime candidate for object-
Introduction
relational mapping.
Chapter 1 - ADO.NET Basics
Chapter
Another2 situation
- Data Components in Visualcan
when OR mapping Studio .NET
really help is when you have the need to enforce complicated
Chapter 3 - ADO.NET
data validation. in Disconnected
Databases Environments
support enforcing relations and null vs. non-null values, but they do not (in
general)
Chapter 4 have good support
- ADO.NET for complex
in Connected validation. For example, if you need to make sure the user has
Environments
provided
Chapter 5 at
- least oneADO.NET
Handling method of contact (such as a phone or email address), you can easily enforce this
Events
with a mapped
Chapter object. XML with ADO.NET
6 - Integrating
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
Many packaged applications need to be able to store the application data in multiple database systems
Chapter 8 - Constraints and Data Relations
and even be able to support situations where the user purchasing the software has no database at all
Chapter 9 - ADO.NET Exception Handling
(such as a flat text file). By keeping your application logic and data model in your objects, support for each
Chapter 10 - Working with the ODBC .NET Data Provider
persistence medium is as simple as adding handling in the data access components. If you use direct SQL
Chapter 11 procedure
or stored - Stored Procedures and Views
calls throughout your code, you'll find portability a major problem.
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
The classic
Chapter view of ORamapping
13 - Developing involves
Custom Data abstracting a complex data model. A classic example is if you
Provider
have the
Chapter 14need to track Database
- Developing employees, salespeople,
Web Applications and
usingaccountants.
ASP.NET An employee is clearly the "base class"
for the 15
Chapter other typesADO.NET
- Using of employees. For example,
in Xml Web Services all employees have name information, but only sales
people16
Chapter have a sales Server
- ASP.NET territoryControls
code, and
and only
Dataaccountants
Binding have a CPA certification flag. You would put the
common
Chapter 17 parts in theReal-World
- Building EmployeeWeb
object (and related table in the database) and the task-specific information
Applications
in a related object (and related table in the database).
Chapter 18 - Object-Relational Mapping in .NET
Chapter
In all of19
the- previous
Mapped Objects: Performance
cases, you'll find ORConsiderations and Data
mapping beneficial Binding an easily manageable system.
in creating
Chapter 20 - COM Interoperability and ADO.NET
Chapter 21 - Messaging
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Appendix A - Relational Databases: Some Basic Concepts
Appendix B - Commonly Used SQL Statements
Appendix C - ADO.NET Frequently Asked Questions
Index
List of Figures
List of Tables
List of Listings
List of Sidebars
Understanding
AppliedObject
ADO.NET:Databases
Building Data-Driven Solutions
by Mahesh Chand and David Talbot ISBN:1590590732
Object databasesApress
such as Objectivity/DB,
2003 (928 pages) Poet, and Matisse started appearing in the 1980s as a proposed
alternative to transaction-oriented
This text provides extensive database
relational management
coverage of systems. The idea was to treat data
ADO.NET technology
more intuitively asincluding
objects ADO.NET
(Customer internals, namespaces, classes, and instead of as a series of flat rows
and Invoice objects, for example)
interfaces,
that have to be stored and and
in tables takesrelated
a comprehensive
via foreign look
keys.at(For
XMLa good overview of object databases, see
Doug Barry's sitenamespaces and classes, and how to integrate both with
at www.odbmsfacts.com/articles/object-oriented_databases.html.)
ADO.NET.
A simple way of thinking about object databases is looking at how you would create a simple program that
shows a list of all the users in your database.
Table of Contents
Applied
Using ADO.NETBuilding
SQL to get this dataData-Driven
from your Solutions
relational database, you would use the following statement:
Introduction
Chapter 1 - ADO.NET Basics
SELECT * FROM Users
Chapter 2 - Data Components in Visual Studio .NET
Chapter 3 - ADO.NET in Disconnected Environments
Chapter 4 - then
You would ADO.NET
havein toConnected Environments
take the data returned from the query, transform it into objects in your code,
iterate through
Chapter a list of
5 - Handling users, and
ADO.NET display the results. This is a hard-nosed look at the problem; technically
Events
you can6 just
Chapter pipe the results
- Integrating directly
XML with out from the database, but in doing so you give up the encapsulation
ADO.NET
promised
Chapter 7 by object-oriented
- Data Binding and programming.
Windows Forms Data-Bound Controls
Chapter 8 - Constraints and Data Relations
Using an object database, your code would look similar to the following statement:
Chapter 9 - ADO.NET Exception Handling
Chapter 10 - Working with the ODBC .NET Data Provider
Dim users As Users()
Chapter 11 - Stored Procedures and Views
users = open('users').Load()
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Chapter 13 - Developing a Custom Data Provider
Chapter 14 -allDeveloping
For listing users, theDatabase Web Applications
object database using of
wins in terms ASP.NET
simplicity. The data is acquired, and it's already
Chapter 15 - Using ADO.NET in Xml Web Services
an object with no need for a transformation to work with it. All you would need to do then is loop through
Chapter 16 - ASP.NET
the collection Server
of users Controls and Data Binding
objects.
Chapter 17 - Building Real-World Web Applications
It gets a18lot- more
Chapter complicatedMapping
Object-Relational when you want to perform a "reporting" type of function on the database
in .NET
such as19getting
Chapter the total
- Mapped amount
Objects: of ordersConsiderations
Performance to be shippedand
on aData
future date.
Binding
Chapter 20 - COM Interoperability and ADO.NET
In SQL you can use the following syntax:
Chapter 21 - Messaging
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
SELECT sum(Amount) FROM OrderedItems WHERE ShipDate > GetDate()
Appendix A - Relational Databases: Some Basic Concepts
Appendix B - Commonly Used SQL Statements
Appendix
With an C - ADO.NET
object Frequently
database Asked
you would Questions
have to actually loop through all of the items in the OrderedItems
Index
collection and add each amount to the total. There are other options that different object database
vendors
List support for summarizing data, but the options overall are not as simple and consistent as they are
of Figures
withofSQL
List tables.
Tables
List of Listings
Ultimately, object databases never caught on for a variety of reasons. Some people feel strongly about to
List of Sidebars
say that object databases are inferior to relational databases, but in the end the marketplace has spoken
and the number of object databases in actual use in production systems is tiny.
So, although it's unlikely you'll ever run into a project that uses an object database, you can still work with
objects in your code that store their properties in a database transparently, which allows you to focus on
developing new functionality instead of worrying about breaking old code.
Why ObjectApplied
Relational
ADO.NET:Mapping?
Building Data-Driven Solutions
by Mahesh Chand and David Talbot ISBN:1590590732
OR mapping keeps the
Apress code
2003 in your
(928 application encapsulated and clean, and it makes it easy to manage
pages)
changes in the database. By building an OR coverage
This text provides extensive mappingofcomponent, your database logic will be
ADO.NET technology
encapsulated andincluding
hidden ADO.NET
away frominternals,
the rest namespaces,
of your system.
classes, and the logic of loading and saving your
Because
interfaces,
object rests entirely in the ORandmapping
takes a comprehensive
subsystem, thelookcodeat in
XML
the rest of your program uses only clean
namespaces
object-oriented code. and classes,
It also makes and how
it far easier to integrate
to make changes bothtowith
the database later without having to
ADO.NET.
alter every place you reference the data.
The core issue is short-term vs. long-term laziness. Using short-term laziness would probably put SQL
Table of Contents
queries directly in your Web pages and just use SqlDataReader objects to work with your data. Past the
Applied ADO.NETBuilding Data-Driven Solutions
initial implementation, this method makes your code hard to maintain. If you add a column to the
Introduction
database, you'll have to find every reference to that table in your application and update it. Also, as the
Chapter 1 - ADO.NET Basics
need to use the same table on multiple pages arises, you'll find yourself copying and pasting large
Chapter 2 - Data Components in Visual Studio .NET
sections of code to get the same functionality on these new pages as well.
Chapter 3 - ADO.NET in Disconnected Environments
Long-term
Chapter 4 -laziness
ADO.NETmeans taking the
in Connected upfront time costs associated with building out the object relational
Environments
mapping
Chapter 5 for your table.
- Handling It will definitely
ADO.NET Events take you longer to initially produce these objects, but in the long
term it will
Chapter 6 -mean much XML
Integrating less with
work.ADO.NET
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
Chapter 8 - Constraints and Data Relations
Chapter 9 - ADO.NET Exception Handling
Chapter 10 - Working with the ODBC .NET Data Provider
Chapter 11 - Stored Procedures and Views
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Chapter 13 - Developing a Custom Data Provider
Chapter 14 - Developing Database Web Applications using ASP.NET
Chapter 15 - Using ADO.NET in Xml Web Services
Chapter 16 - ASP.NET Server Controls and Data Binding
Chapter 17 - Building Real-World Web Applications
Chapter 18 - Object-Relational Mapping in .NET
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
Chapter 20 - COM Interoperability and ADO.NET
Chapter 21 - Messaging
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Appendix A - Relational Databases: Some Basic Concepts
Appendix B - Commonly Used SQL Statements
Appendix C - ADO.NET Frequently Asked Questions
Index
List of Figures
List of Tables
List of Listings
List of Sidebars
Creating the Basic
Applied Design
ADO.NET: of the
Building VideoSolutions
Data-Driven Store Application
by Mahesh Chand and David Talbot ISBN:1590590732
The OR mappingApress
technique
2003used in this chapter was inspired by a demo application from Microsoft intended to
(928 pages)
show best practices in .NET called Duwamish7.
This text provides extensive Downloading
coverage of ADO.NETDuwamish7,
technologyreading through the source code, and
truly understanding
including ADO.NET internals, namespaces, classes, and better .NET programmer. It covers topics
how it works can really help you become a much
interfaces,
such as statelessness, and takes logical
OR mapping, a comprehensive look at XML and more. Download it from MSDN
three-tier structures,
namespaces and classes,
(http://msdn.microsoft.com) and how for
by searching to integrate
Duwamish7.both with
ADO.NET.
The design of the video store database is simple. At the core of this application is the VideoTape table, as shown in
Table 18-1. The VideoTape table tracks only the title and description of the title in question. You could have quite a
bit more information about a particular title and even expand the application to track DVDs as well as video tapes,
but for this application, let's keep it simple. You can always expand this later to create a complete application.
We selected this particular application because it provides the opportunity to touch on many of the real-world
issues you'll run in to when attempting to create a scalable Web application using .NET. Some of the topics ahead
cover how to handle potentially large sets of data among dependant tables, how to manage the disconnects
between the database's handling of null values, and how .NET handles null values. Additionally, you'll see some
practical considerations to keep in mind when designing a scalable system with .NET.
Creating the DataADO.NET:
Applied ObjectBuilding Data-Driven Solutions
by Mahesh Chand and David Talbot ISBN:1590590732
The data object represents
Apress 2003what
(928the table structure in the database is in your code. The data object is necessary
pages)
for type safety and to text
This provide a "bucket"
provides for your
extensive data.ofYou'll
coverage havetechnology
ADO.NET to create a data object for each object in your
database. You'll start by examining
including the VideoTapeData
ADO.NET internals, object, shown
namespaces, classes, and in Listing 18-1.
interfaces, and takes a comprehensive look at XML
Listing 18-1: Thenamespaces and classes,
VideoTapeData and how to integrate both with
Object
ADO.NET.
End Get
Table
End ofProperty
Contents
Applied ADO.NETBuilding Data-Driven Solutions
Introduction
Public Sub New(ByRef data As VideoTapeData, ByVal index As Integer)
Chapter 1 -Me.data
ADO.NET Basics
= data
Chapter 2 -Me.index
Data Components in Visual Studio .NET
= index
Chapter 3 -End Sub in Disconnected Environments
ADO.NET
Chapter 4 - ADO.NET in Connected Environments
Chapter 5 -Public
Handling Function GetColumn(ByRef ColumnName As String) As Object
ADO.NET Events
Chapter 6 Return
- Integrating XMLdata.Rows(index)(ColumnName)
with ADO.NET
Chapter 7 -End
Data Function
Binding and Windows Forms Data-Bound Controls
Chapter 8 - Constraints and Data Relations
Public Function SetColumn(ByRef ColumnName _
Chapter 9 - ADO.NET Exception Handling
As String, ByRef ColumnValue As Object)
Chapter 10 - Working with the ODBC .NET Data Provider
data.Rows(index)(ColumnName) = ColumnValue
Chapter 11 - Stored Procedures and Views
End Function
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Chapter 13 -Public
Developing a Custom Data
Property Provider
VideoTapeID() As Decimal
Chapter 14 - Developing
Get Database Web Applications using ASP.NET
Chapter 15 - Using ADO.NET in Xml Web Services
If (GetColumn("VideoTapeID").GetType() Is _
Chapter 16 - ASP.NET Server Controls and Data
Type.GetType("System.DBNull")) Binding
Then
Chapter 17 - Building Real-World Web Applications
Return -1
Chapter 18 - Object-Relational
End If Mapping in .NET
Return
Chapter 19 - Mapped Objects: CType(GetColumn("VideoTapeID"),
Performance Considerations and Data Binding Decimal)
Chapter 20 - COM End Get
Interoperability and ADO.NET
Set(ByVal Value As Decimal)
Chapter 21 - Messaging
Chapter 22 - SQL ServerSetColumn("VideoTapeID", Value)
and ADO.NET: Notes on Performance
End Databases:
Appendix A - Relational Set Some Basic Concepts
End Property
Appendix B - Commonly Used SQL Statements
Appendix C - ADO.NET Frequently Asked Questions
Public Property Title() As String
Index
Get
List of Figures
Return "" + GetColumn("Title")
List of Tables
End Get
List of Listings Set(ByVal Value As String)
List of Sidebars SetColumn("Title", Value)
End Set
End Property
The database meanwhile treats data that hasn't been given a value as null. This becomes a problem when you try
to move the content from the database into .NET because .NET needs to be able to represent the database's null
value to the rest of your application in a way that lets your application know that a column has not been initialized.
This includes things such as using -1 as a value for integers and decimals, an empty string for strings, and so on.
The trip back to the database compounds this problem. When the data is stored, if you have written a value to your
data object such Applied ADO.NET:DateTime,
as an uninitialized Building Data-Driven
an error willSolutions
occur. By handing these problems in the mapped
by Mahesh Chand and David Talbot ISBN:1590590732
object, you'll make the rest of your program more reliable by preventing value checks throughout your code.
Apress 2003 (928 pages)
The two string fields
Thisbeing mappedextensive
text provides in this object are easier
coverage to handle.
of ADO.NET If the database has a character field, such
technology
as a Char or Text,including
that's ADO.NET internals,
null, it'll return namespaces, classes,
a System.DBNull andThe handling on the .NET side is easier than
object.
interfaces, and takes a comprehensive look at XML
with other value types.
namespaces and classes, and how to integrate both with
ADO.NET.
The following statement returns the value if there is one:
Table of Contents
Return "" + GetColumn("Description")
Applied ADO.NETBuilding Data-Driven Solutions
Introduction
If the column
Chapter 1
is null in the database, it returns an empty string because ""+calls the ToString method on the
- ADO.NET Basics
System.DBNull object. Either way, an acceptable .NET value is returned to the calling program.
Chapter 2 - Data Components in Visual Studio .NET
Chapter 3 - ADO.NET in Disconnected Environments
Creating
Chapter 4 the Data
- ADO.NET Access
in Connected Component
Environments
Chapter 5 - Handling ADO.NET Events
The DAC's- responsibility
Chapter 6
is to fill your data objects with data from the database and create instances of your
Integrating XML with ADO.NET
mapped object. It does this by defining what stored procedures should be used to load and save your data and
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
makes them accessible to simple front-end methods. Once the DAC is done, the rest of your program will be able
Chapter 8 - Constraints and Data Relations
to get and set your mapped objects just as easy as calling a simple method (see Listing 18-3).
Chapter 9 - ADO.NET Exception Handling
Chapter
Listing10 - Working
18-3: with the ODBC .NET Data Provider
The VideoTapeDataAccess Object
Chapter 11 - Stored Procedures and Views
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Public Class VideoTapeDataAccess
Chapter 13 - Developing a Custom Data Provider
ChapterPublic
14 - Developing Database Web Applications
connectionString As String using ASP.NET
Chapter 15 -Protected
Using ADO.NET in Xml Web
adapter AsServices
SqlDataAdapter
Chapter 16 -Protected
ASP.NET Server
loadAll As Data
Controls and Binding
SqlDataAdapter
Chapter 17 - Building Real-World Web Applications
Chapter 18 -Public
Object-Relational
Sub New()Mapping in .NET
Chapter 19 - Mapped Objects: Performance="Your
connectionString Considerations and Data Binding
Connection String"
Chapter 20 - COM Interoperability and ADO.NET
Chapter 21 - Messaging
adapter
Chapter 22 - SQL Server = New SqlDataAdapter()
and ADO.NET: Notes on Performance
adapter.SelectCommand
Appendix A - Relational = New SqlCommand("ap_VideoTapeLoadByID", _
Databases: Some Basic Concepts
New SqlConnection(connectionString))
Appendix B - Commonly Used SQL Statements
adapter.SelectCommand.CommandType = CommandType.StoredProcedure
Appendix C - ADO.NET Frequently Asked Questions
adapter.SelectCommand.CommandType = CommandType.StoredProcedure
Index
adapter.SelectCommand.Parameters.Add _
List of Figures
("@VideoTapeID", SqlDbType.Decimal, 0, "VideoTapeID")
List of Tables
adapter.InsertCommand = New SqlCommand("ap_VideoTapeInsert", _
List of Listings
New SqlConnection(connectionString))
List of Sidebars adapter.InsertCommand.CommandType = CommandType.StoredProcedure
adapter.InsertCommand.Parameters.Add("@VideoTapeID", _
SqlDbType.Decimal, 0, "VideoTapeID")
adapter.InsertCommand.Parameters("@VideoTapeID").Direction = _
ParameterDirection.Output
adapter.InsertCommand.Parameters.Add("@Title", _
SqlDbType.Char, 50, "Title")
adapter.InsertCommand.Parameters.Add("@Description", _
SqlDbType.Text, 0, "Description")
The constructor of the VideoTapeDataAccess object initializes the SqlDataAdaptersto use the stored
Table of Contents
procedures that handle the actual database access. The constructor initializes the Select,Insert,Update,
Applied ADO.NETBuilding
andDelete Data-Driven
stored procedures on theSolutions
instance called adapter, but only the Select statement on the loadAll
Introduction
instance.
Chapter 1 - ADO.NET Basics
The reason
Chapter for this
2 - Data is there are
Components in multiple ways.NET
Visual Studio you want to choose what data to get, but in the end there's only one
way to update it in that database. Both adapters
Chapter 3 - ADO.NET in Disconnected Environments
could have been fully initialized, but that would produce a large
amount of redundant code. By only initializing one adapter for updates, inserts, and deletes, you're avoiding
Chapter 4 - ADO.NET in Connected Environments
additional code that would needlessly slow down your program.
Chapter 5 - Handling ADO.NET Events
Chapter 6 - Integrating XMLmethod
TheGetVideoTapeByID with ADO.NET
gets one VideoTape object out of the database. It sets the @VideoTapeID
Chapter 7 - Data Binding and Windows
parameter on the stored procedure toForms Data-Bound
the value Controls
passed in and fills the VideoTapeData object with data. If the
database
Chapter 8 didn't find anyand
- Constraints records with the VideoTapeID passed in, then it returns Nothing, a null value. If there's
Data Relations
at least9one
Chapter record returned,
- ADO.NET it creates
Exception Handlingan instance of the VideoTape object and initializes it with the data it loaded
into the10
Chapter VideoTapeData object
- Working with the ODBCand sets
.NET theProvider
Data index to 0 so that the first record retuned is used by the mapped
object. 11
Chapter Because the
- Stored Video-TapeID
Procedures column is a unique identity column in the database, this stored procedure
and Views
should 12
Chapter never returnSQLXML,
- Oracle, more than
andone row.
Other .NET Data Providers
Chapter 13 - Developing a Custom Data Provider
TheGetAllVideoTapes method is much simpler. It creates an instance of the VideoTapeData object and
Chapter 14 - Developing Database Web Applications using ASP.NET
then uses the loadAll SqlDataAdapter to fill it. It then calls the GetVideoTapeArrayFromData method to
Chapter
turn the15DataTable
- Using ADO.NET
into aninarray
Xml Web Services
of VideoTape objects.
Chapter 16 - ASP.NET Server Controls and Data Binding
TheGetVideoTapeArrayFromData
Chapter method creates an array of VideoTape objects the length of the number
17 - Building Real-World Web Applications
of results
Chapter 18 returned from the database
- Object-Relational Mapping inand loops through the results, creating an instance of the VideoTape
.NET
object for
Chapter 19 each row.Objects:
- Mapped As it goes through, it Considerations
Performance sets the index and
of each
DataVideoTape
Binding object to a different row in the same
result set.
Chapter 20 -InCOM
the end it provides the
Interoperability andarray of VideoTape objects to the calling program.
ADO.NET
Chapter 21 - Messaging
The purpose of making the GetVideoTapeArrayFromData a separate method instead of simply putting this
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
code inline with the GetAllVideoTapes method is to provide this method to other objects that may be
Appendix A - to
attempting Relational Databases:
create instances of Some Basic Concepts
VideoTape objects. You'll see this put to work later in the
Appendix B - Commonly Used SQL
VideoCheckInCheckOut Statements
object.
Appendix C - ADO.NET Frequently Asked Questions
If there are no video tapes in the database, it returns an array with no elements in it, not a null. This is, in general,
Index
good
List behavior for a DAC to have when it's expected to return an array of objects. In most situations the calling
of Figures
program
List will want to loop through however many elements are in the array, even if there are no elements. If the
of Tables
calling
List program wants to know if a null was returned, it can always check the length of the array to see if it's zero.
of Listings
In the
List end, returning a zerolength array should simplify your application's code.
of Sidebars
TheSetVideoTape object is amazingly short. It simply calls to update the row of the VideoTape object to the
database. It automatically selects which stored procedure to call and then executes it with the corresponding data.
If it was an insert call, the identity column will be automatically updated in the instance of the VideoTape object.
This comes in handy when writing the front-end code of the application. There are many cases where the user will
define the data for several related tables on one page, and you'll need a way to know the IDs of the related
columns in order to allow the user to edit the data properly.
The one-line update call really highlights one of the core ideas of .NET: Hide as much complexity as possible.
Your object builds on this principle to hide the rest of the database access functionality in your OR mapped
component.
TheRemoveVideoTape method actually uses the Delete command of the adapter directly. You could just
remove the row inApplied
questionADO.NET:
from the Building Data-Driven
VideoTapeData Solutions
object and then call Update, but doing so could lose the
by Mahesh Chand and David Talbot
isolation of the task to be performed. You would have to update ISBN:1590590732
the entire VideoTapeData set, which may
include changes Apress
that the calling
2003 (928 pages)
program doesn't want updated. This ensures that encapsulation is enforced and
only the row you This
wanttext provides
to delete extensive coverage of ADO.NET technology
is deleted.
including ADO.NET internals, namespaces, classes, and
In most cases, it'sinterfaces,
a bad ideaand
to takes a comprehensive
actually lookthe
delete rows from at XML
database to remove an item from your application.
namespaces and classes, and how to integrate both with
What you would normally
ADO.NET. do is have a deleted field on the table that's flagged so you don't have to worry about
maintaining your database's referential integrity or actually losing data. You would also modify your stored
procedures that load data into your adapters to not return rows that are flagged as deleted unless it's referred to
Table of Contents
directly by its primary key.
Applied ADO.NETBuilding Data-Driven Solutions
Introduction
Building the VideoTape Test Case
Chapter 1 - ADO.NET Basics
Chapter 2 - Data
It's important Components
to build in Visual
a test case for anStudio
object.NET
relationally mapped system. A test case ensures that your
component
Chapter does what
3 - ADO.NET init's supposed to
Disconnected do and ensures that none of your changes have broken existing code. Each
Environments
step of 4your
Chapter test caseinshould
- ADO.NET say what
Connected the expected output is and then show the output so that it's well marked in
Environments
terms of
Chapter 5 what it's supposed
- Handling to Events
ADO.NET do in order to compare the output. It's even possible to build automated test cases
that compare
Chapter these types
6 - Integrating XMLofwith
things automatically, but that's not required for this particular system.
ADO.NET
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
TheVideoTapeTestCase object will do the following:
Chapter 8 - Constraints and Data Relations
1. Load
Chapter 9
a VideoTape object from the database and display what its data is
- ADO.NET Exception Handling
Chapter 10 - Working with the ODBC .NET Data Provider
2. Change the title and description
Chapter 11 - Stored Procedures and Views
3. Store
Chapter the object
12 - Oracle, in theand
SQLXML, database
Other .NET Data Providers
Chapter 13 - Developing a Custom Data Provider
4. Reload the object and display what its data is
Chapter 14 - Developing Database Web Applications using ASP.NET
Chapter 15 - Using
5. Restore theADO.NET
original in Xml Web Services
VideoTape data and store it
Chapter 16 - ASP.NET Server Controls and Data Binding
6. Load
Chapter all of the
17 - Building VideoTape
Real-World Webobjects from the database and show what each one is
Applications
Chapter 18 - Object-Relational Mapping in .NET
Listing 18-4 shows the code for the test case.
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
Chapter
Listing20 - COM
18-4: Interoperability
The Test Case for and
theADO.NET
VideoTape Component
Chapter 21 - Messaging
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Imports VideoStoreDataModel.EnterpriseVB.VideoStore.Data
Appendix A - Relational Databases: Some Basic Concepts
Appendix B - Commonly Used SQL Statements
Module VideoTapeTestCase
Appendix C - ADO.NET Frequently Asked Questions
Index Sub Main()
List of Figures
Dim vDAC As New VideoTapeDataAccess()
List of TablesDim tVTape As VideoTape
List of Listings
Console.WriteLine("Loading VideoTape")
List of Sidebars
tVTape` = vDAC.GetVideoTapeByID(1)
Console.WriteLine("VideoTape Loaded:" + tVTape.GetType().ToString())
DisplayVideoTape(tVTape)
tVTape.Title = "TestTitle"
tVTape.Description = "TestDescription"
vDAC.SetVideoTape(tVTape)
tVTape = vDAC.GetVideoTapeByID(1)
Applied ADO.NET: _Building Data-Driven Solutions
Console.WriteLine
by Mahesh Title=TestTitle
("After alteration. Chand and David TalbotDescription=TestDescription")
ISBN:1590590732
Apress 2003 (928 pages)
DisplayVideoTape(tVTape)
This text provides extensive coverage of ADO.NET technology
including ADO.NET
tVTape.Title internals, namespaces, classes, and
= origTitle
interfaces, and takes a comprehensive look at XML
tVTape.Description = origDescription
namespaces and classes, and how to integrate both with
vDAC.SetVideoTape(tVTape)
ADO.NET.
tVTape = vDAC.GetVideoTapeByID(1)
Console.WriteLine _
Table of Contents
("Restored to origional, should look like the first displayed VideoTape.")
Applied ADO.NETBuilding Data-Driven Solutions
DisplayVideoTape(tVTape)
Introduction
Chapter 1 -Console.WriteLine("List
ADO.NET Basics all VideoTapes")
Chapter 2 - Data Components in Visual Studio .NET
Chapter 3 -Dim tVideos()
ADO.NET As VideoTape
in Disconnected Environments
Chapter 4 -tVideos
ADO.NET in=Connected
vDAC.GetAllVideoTapes()
Environments
Chapter 5 - Handling ADO.NET Events
Chapter 6 -Dim i As XML
Integrating Integer
with ADO.NET
Chapter 7 -For
Data i = 0 and
Binding To Windows
tVideos.Length - 1 Controls
Forms Data-Bound
Chapter 8
DisplayVideoTape(tVideos(i))
- Constraints and Data Relations
Next
Chapter 9 - ADO.NET Exception Handling
Console.WriteLine("Press Any Key To Quit...")
Chapter 10 - Working with the ODBC .NET Data Provider
Console.ReadLine()
Chapter 11 - Stored Procedures and Views
End Sub
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
ChapterSub
13 -DisplayVideoTape(ByRef
Developing a Custom Data Provider
tVTape As VideoTape)
Chapter 14 -Console.WriteLine("---------------------------")
Developing Database Web Applications using ASP.NET
Chapter 15 -Console.WriteLine("VideoTapeID:"
Using ADO.NET in Xml Web Services + tVTape.VideoTapeID.ToString())
Chapter 16 -Console.WriteLine("Title:"
ASP.NET Server Controls and Data Binding
+ tVTape.Title)
Chapter 17 -Console.WriteLine("Description:"
Building Real-World Web Applications + tVTape.Description)
ChapterEnd
18 -Sub
Object-Relational Mapping in .NET
End Module
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
Chapter 20 - COM Interoperability and ADO.NET
Chapter 21 - Messaging
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Figure 18-2 shows the VideoTape test case output.
Appendix A - Relational Databases: Some Basic Concepts
Appendix B - Commonly Used SQL Statements
Appendix C - ADO.NET Frequently Asked Questions
Index
List of Figures
List of Tables
List of Listings
List of Sidebars
Imports
Table System
of Contents
Imports System.Data
Applied ADO.NETBuilding Data-Driven Solutions
Imports System.Data.SqlClient
Introduction
Imports System.Data.Common
Chapter 1 - ADO.NET Basics
Chapter 2 - Data Components in Visual Studio .NET
Namespace EnterpriseVB.VideoStore.Data
Chapter 3 - ADO.NET in Disconnected Environments
Chapter 4 - ADO.NET in Connected Environments
ChapterPublic
5 - Handling
Class ADO.NET
User Events
Chapter 6 - Integrating XML with ADO.NET
Chapter 7 -Protected
Data Binding and
dataWindows Forms Data-Bound Controls
As DataTable
Chapter 8 -Protected
Constraints and Data Relations
index As Integer
Chapter 9 - ADO.NET Exception Handling
Chapter 10 -Protected
Working with Friend
the ODBC ReadOnly Property MyData() As DataRow()
.NET Data Provider
Get
Chapter 11 - Stored Procedures and Views
Dim myRow()
Chapter 12 - Oracle, SQLXML, As DataRow
and Other .NET = {Me.data.Rows(index)}
Data Providers
Chapter 13 - DevelopingReturn
a CustommyRow
Data Provider
End Get
Chapter 14 - Developing Database Web Applications using ASP.NET
End Property
Chapter 15 - Using ADO.NET in Xml Web Services
Chapter 16 - ASP.NET Server Controls and Data Binding
Public Sub New(ByRef data As UserData, ByVal index As Integer)
Chapter 17 - Building Real-World Web Applications
Me.data = data
Chapter 18 - Object-Relational Mapping in .NET
Me.index = index
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
End Sub
Chapter 20 - COM Interoperability and ADO.NET
Chapter 21 -Public
MessagingFunction GetColumn(ByRef ColumnName As String) As Object
Chapter 22 - SQL Server
Return anddata.Rows(index)(ColumnName)
ADO.NET: Notes on Performance
Appendix A -End
Relational Databases: Some Basic Concepts
Function
Appendix B - Commonly Used SQL Statements
Appendix C -Public
ADO.NET Function
Frequently Asked Questions
SetColumn(ByRef ColumnName As String, _
ByRef ColumnValue As Object)
Index
List of Figures data.Rows(index)(ColumnName) = ColumnValue
List of TablesEnd Function
List of Listings
Public Property UserID() As Decimal
List of Sidebars
Get
If (GetColumn("UserID").GetType() Is _
Type.GetType("System.DBNull")) Then
Return -1
End If
Return CType(GetColumn("UserID"), Decimal)
End Get
Set(ByVal Value As Decimal)
SetColumn("UserID", Value)
End Set
End Property
Public Property FirstName() As String
Get Applied ADO.NET: Building Data-Driven Solutions
by Mahesh""
Return Chand and David Talbot
+ GetColumn("FirstName") ISBN:1590590732
Apress
End Get 2003 (928 pages)
This textValue
Set(ByVal providesAs extensive
String) coverage of ADO.NET technology
including ADO.NET
SetColumn("FirstName",internals, namespaces,
Value) classes, and
interfaces, and takes a comprehensive look at XML
End Set
namespaces and classes, and how to integrate both with
End Property
ADO.NET.
TheUserData object defines only three fields in the DataTable: UserID, FirstName, and LastName. Although
much more data could be tracked on a user such as addresses and telephone numbers, let's keep it simple.
If you want to add this additional functionality, make sure you model it in separate tables. A common mistake
beginners make is modeling all of a user's data in one giant table. Some systems go so far as having the person's
name, address, phone numbers, credit card information, company, title, and more all in one table. This is bad both
from a clean design sense and a performance sense. If a table has too many columns, SQL server handles it
slowly.
adapter.SelectCommand.CommandType = CommandType.StoredProcedure
adapter.DeleteCommand.Parameters.Add("@UserID", _
SqlDbType.Decimal, 0, "UserID")
End Sub
Applied
Public ADO.NET:
Function Building Data-DrivenuserID
GetUserByID(ByVal Solutions
As Decimal) As User
by Mahesh Chand and David Talbot ISBN:1590590732
Apress
Dim 2003As
data (928New
pages)UserData()
This text provides extensive coverage of ADO.NET technology
adapter.SelectCommand.Parameters("@UserID").Value = userID
including ADO.NET internals, namespaces, classes, and
adapter.Fill(data)
interfaces, and takes a comprehensive look at XML
If (data.Rows.Count < 1) Then
namespaces and classes, and how to integrate both with
Return Nothing
ADO.NET.
End If
Dim vt As New User(data, 0)
Table of Contents Return vt
Applied ADO.NETBuilding
End Function Data-Driven Solutions
Introduction
Chapter 1 -Public
ADO.NET Function
Basics GetAllUsers() As User()
Chapter 2 - Data Dim data As
Components New Studio
in Visual UserData()
.NET
Chapter 3 loadAll.Fill(data)
- ADO.NET in Disconnected Environments
Chapter 4 Dim inuArray(data.Rows.Count)
- ADO.NET Connected Environments As User
Chapter 5 DimADO.NET
- Handling i As Integer
Events
Chapter 6 - Integrating XML with ADO.NET
For i = 0 To data.Rows.Count
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
uArray(i) = New User(data, i)
Chapter 8 - Constraints and Data Relations
Next i
Chapter 9 - ADO.NET Exception Handling
Chapter 10 - Working with the ODBC .NET Data Provider
Return uArray
Chapter 11 -End
Stored Procedures and Views
Function
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Chapter 13 -Public
Developing a Custom Data
Function Provider
SetUser(ByRef user As User)
Chapter 14 - Developing Database Web Applications using ASP.NET
adapter.Update(user.MyData)
Chapter 15 -End
UsingFunction
ADO.NET in Xml Web Services
Chapter 16 - ASP.NET Server Controls and Data Binding
Chapter 17 -Public FunctionWeb
Building Real-World RemoveUser(ByRef
Applications user As User)
adapter.DeleteCommand.Parameters("@UserID").Value
Chapter 18 - Object-Relational Mapping in .NET = user.UserID
adapter.DeleteCommand.Connection.Open()
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
Chapter 20 - COM adapter.DeleteCommand.ExecuteNonQuery()
Interoperability and ADO.NET
adapter.DeleteCommand.Connection.Close()
Chapter 21 - Messaging
End Function
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
End Class
Appendix A - Relational Databases: Some Basic Concepts
Appendix B - Commonly Used SQL Statements
End Namespace
Appendix C - ADO.NET Frequently Asked Questions
Index
List of Figures
List
The of DAC
Tablesfor the User component allows the calling program to look up a single user, list all of the users, update
List of Listings
or insert a user, or delete a user. Once again the stored procedures are kept simple and the DAC itself is simple.
List of Sidebars
5.
6.
3.
4.
Table of Contents
Module UserTestCase
Applied ADO.NETBuilding Data-Driven Solutions
Sub Main()
Introduction
Chapter 1 -Dim uDACBasics
ADO.NET As New UserDataAccess()
Chapter 2 -Dim
Data tUser As User
Components in Visual Studio .NET
Chapter 3 -Console.WriteLine("Loading User")
ADO.NET in Disconnected Environments
Chapter 4
tUser = uDAC.GetUserByID(1)
- ADO.NET in Connected Environments
Console.WriteLine("User Loaded:" + tUser.GetType().ToString())
Chapter 5 - Handling ADO.NET Events
DisplayUser(tUser)
Chapter 6 - Integrating XML with ADO.NET
Dim origFirstName = tUser.FirstName
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
Dim origLastName = tUser.LastName
Chapter 8 - Constraints and Data Relations
Chapter 9 -tUser.FirstName
ADO.NET Exception Handling
= "TestFirst"
Chapter 10 -tUser.LastName
Working with the ODBC .NET Data Provider
= "TestLast"
Chapter 11 - Stored Procedures and Views
Chapter 12 -uDAC.SetUser(tUser)
Oracle, SQLXML, and Other .NET Data Providers
Chapter 13 - Developing a Custom Data Provider
Chapter 14 -tUser
Developing Database Web Applications using ASP.NET
= uDAC.GetUserByID(1)
Chapter 15 -Console.WriteLine _ Services
Using ADO.NET in Xml Web
("After
Chapter 16 -alteration. FirstName=TestFirst
ASP.NET Server Controls and Data Binding LastName=TestLast")
Chapter 17 -DisplayUser(tUser)
Building Real-World Web Applications
Chapter 18 -Console.WriteLine
Object-Relational Mapping_in .NET
("Restored
Chapter to origional,
19 - Mapped should
Objects: Performance look likeand
Considerations the
Datafirst
Bindingdisplayed user.")
tUser.FirstName = origFirstName
Chapter 20 - COM Interoperability and ADO.NET
tUser.LastName = origLastName
Chapter 21 - Messaging
uDAC.SetUser(tUser)
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
tUser = uDAC.GetUserByID(1)
Appendix A - Relational Databases: Some Basic Concepts
DisplayUser(tUser)
Appendix B - Commonly Used SQL Statements
Appendix C -Console.WriteLine("List
ADO.NET Frequently Asked Questions
all users")
Index
List of Figures
Dim tUsers() As User
List of TablestUsers = uDAC.GetAllUsers()
List of Listings
List of Sidebars
Dim i As Integer
For i = 0 To tUsers.Length - 1
DisplayUser(tUsers(i))
Next
Console.WriteLine("Press Any Key To Quit...")
Console.ReadLine()
End Sub
Table of Contents
Applied ADO.NETBuilding Data-Driven Solutions
Introduction
Chapter 1 - ADO.NET Basics
Chapter 2 - Data Components in Visual Studio .NET
Chapter 3 - ADO.NET in Disconnected Environments
Chapter 4 - ADO.NET in Connected Environments
Chapter 5 - Handling ADO.NET Events
Chapter 6 - Integrating XML with ADO.NET
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
Chapter 8 - 18-3:
Figure Constraints and Data
The output Relations
of the UserTestCase program
Chapter 9 - ADO.NET Exception Handling
Chapter 10 - Working with the ODBC .NET Data Provider
Managing Dependencies
Chapter 11 - Stored Procedures and Views
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Although
Chapter 13 the User component
- Developing a CustomisData
similar to the VideoTape component, it's important to talk about what isn't in the
Provider
User object.
Chapter Components
14 - Developing that are
Database WebatApplications
the center of yourASP.NET
using system and relate to a number of other tables should
wherever
Chapter 15 possible avoid referencing
- Using ADO.NET in Xml Webother components. The other components can reference your core
Services
component, but by avoiding the core component referencing narrowly scoped entities such as Check In/Check
Chapter 16 - ASP.NET Server Controls and Data Binding
Out, you can keep your code portable to be used in other projects that don't use Check In Check Out.
Chapter 17 - Building Real-World Web Applications
Chapter
Figure 18 - Object-Relational
18-4 Mapping in
shows the dependencies .NETthe video store application.
within
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
Chapter 20 - COM Interoperability and ADO.NET
Chapter 21 - Messaging
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Appendix A - Relational Databases: Some Basic Concepts
Appendix B - Commonly Used SQL Statements
Appendix C - ADO.NET Frequently Asked Questions
Index
List of Figures
List ofFigure
Tables 18-4: The dependencies in the video store application
List of Listings
List of Sidebars
In the design of this application, the Check In/Check Out component has all of the dependencies. You could
easily move the VideoTape or User components to their own DLL and use them in other projects with or without
each other, and nothing would be broken. The Check In/Check Out component, on the other hand, requires
both the User component and VideoTape component.
When you're designing your next project, do some careful thinking about what components you plan on being able
to use in other projects and think about what you need to do to make sure that core component is as independent
as possible.
Paranoid Programming
In a perfect world, software has a specification that doesn't change, programmers produce the software, and
it's done; there's no need for a second version. In reality, specifications change, goals change, and revisions
happen fasterApplied ADO.NET: Building Data-Driven Solutions
than you intend. The only way to really manage this risk is what we like to call paranoid
programming. by Mahesh Chand and David Talbot ISBN:1590590732
Apress 2003 (928 pages)
When designingThis your system, imagine
text provides extensivewhat usersofmight
coverage ask for
ADO.NET next and try to anticipate it in your design and
technology
including ADO.NET
code. If the specification internals,
says that namespaces,
each user classes,
in the system hasand
only one address, design the table schema and
data objects interfaces, and takes a comprehensive
to allow a one-to-many look at XML
relationship because when users change their minds-and they will-it will
namespaces and classes, and how to integrate both with
be painful to ADO.NET.
make an alteration of this type if you did not allow for it in your original design.
The hardest part of being a professional programmer is managing expectations and exceeding them. A good
Table design will help you manage the S.A.L.E.S. (Say Anything Let Engineering Sweat) part of the equation. Making
of Contents
sure your core components
Applied ADO.NETBuilding can easily
Data-Driven be added to new projects will help this immensely.
Solutions
Introduction
To find out what specification for the next version of your product is, check the marketing brochures your sales
Chapter 1 - ADO.NET Basics
team is showing to customers; this should give you a good idea of where the product is headed.
Chapter 2 - Data Components in Visual Studio .NET
Chapter 3 - ADO.NET in Disconnected Environments
Chapter 4 - ADO.NET in Connected Environments
Chapter 5
- Handling ADO.NET Events
Creating
Chapter 6
the Check In/Check Out Component
- Integrating XML with ADO.NET
Chapter 7 - Data
TheCheck Binding and
In/Check OutWindows
componentForms Data-Bound
allows Controls
the calling program to do the following:
Chapter 8 - Constraints and Data Relations
1. List all of the video tapes currently checked out
Chapter 9 - ADO.NET Exception Handling
Chapter 10 - Working
2. Check with the ODBC .NET Data Provider
out a video
Chapter 11 - Stored Procedures and Views
3. Check
Chapter in a video
12 - Oracle, SQLXML, and Other .NET Data Providers
Chapter 13 - Developing a Custom Data Provider
4. Discover the status of a single video
Chapter 14 - Developing Database Web Applications using ASP.NET
This object
Chapter 15 - is at the
Using core ofinyour
ADO.NET Xmlsystem's functionality. The User and VideoTape components hold no real logic,
Web Services
but the16
Chapter Check In/Check
- ASP.NET Out component
Server Controls and Datahas enough to make up the rest of it. Although technically the
Binding
VideoTape
Chapter and User
17 - Building objects Web
Real-World are business objects in that they hold some of the system's logic, the
Applications
CheckInCheckOut
Chapter object isMapping
18 - Object-Relational where the vast majority of the job happens.
in .NET
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
Chapter 20 - COM Interoperability and ADO.NET
Death to N-Tier
Chapter 21 - Messaging
Traditional thought is the only way to create a scalable system on the Web is the three-tier model (what
Chapter 22 - SQL call
academics Server
the and ADO.NET:
four-tier modelNotes on Performance
because they count the browser as a tier). The three-tier model is made up
Appendix A - Relational Databases: Some Basic
of a Web server, an application server, and Concepts
a database server. The thinking goes that the code on your Web
Appendix B - Commonly
servers should only Used SQL Hypertext
provide StatementsMarkup Language (HTML) generation and an interface back to the
Appendix C - ADO.NET
application Frequently
server, Asked Questions
which is actually running the code with the business logic in it. Of course, behind that is the
Indexdatabase server, which should be treated as a dumb repository of data with no logic in it whatsoever
List of(depending
Figures on the server you purchased, this may be a more truthful statement than with others).
List of Tables
The three-tier model has a number of problems, though. Every layer you add increases the likelihood of down
List of Listings
time. If your application server cluster goes down, then your whole application will cease to function. Also,
List of Sidebars
every incoming request goes from the Web server to the database server and on to the database server-and
of course back again. The extra layer increases latency and adds to the complexity of your application.
Complexity is inherently evil and must be destroyed; therefore, the physical two-tier model and logical three-
tier model were born.
Under the 2/3 model, the database stays a dumb place where your data is stored, but the business logic
objects live on the Web server. We're not saying your business logic should go in your code behind-far from it.
What we're saying is that the data objects and logic objects you're creating in this chapter should live in nice,
neat, compiled DLLs that your ASPX pages access.
This reduces latency as network usage goes down, this reduces complexity because you've cut a layer out of
your application, and this significantly reduces the total cost of deploying your application.
Applied ADO.NET: Building Data-Driven Solutions
by Mahesh Chand and David Talbot ISBN:1590590732
TheCheckInCheckOut
Apress object
2003 (928looks
pages)quite a bit like a function library and less like a real object. The reason is
simple; this component defines the actions you're
This text provides extensive coveragetaking on the video
of ADO.NET tapes and users. By isolating the types of
technology
actions that can be
including ADO.NET internals, namespaces, classes, and the .aspx pages that use this business
taken with users and video tapes inside this object,
object layer haveinterfaces,
the ability and
to dotakes a comprehensive
amazing things in justlook at XML
a few lines of code:
namespaces and classes, and how to integrate both with
ADO.NET.
VideosCheckedOutDataGrid.DataSource = (New _
VideoCheckInCheckOut(conn)). _
Table of Contents
GetVideoTapesCheckedOutToUser(user)
Applied ADO.NETBuilding Data-Driven Solutions
Introduction
This example
Chapter shows how
1 - ADO.NET the VideoCheckInCheckOut component allows everything that's currently checked
Basics
out to a single
Chapter 2
person to be listed in an .aspx page in one line of code. This truly comes in handy when you've got
- Data Components in Visual Studio .NET
20 different pages listing the videos checked out to a single user and the need arises to alter the actual logic
Chapter 3 - ADO.NET in Disconnected Environments
behind it. One scenario where this might happen is if the checkout process allowed the user to choose how many
Chapter 4 - ADO.NET in Connected Environments
days they wanted to pay for when they checked out the video. This would involve altering the data model and the
Chapter 5 - Handling ADO.NET Events
logic concerning the data model, especially if a "list overdue" videos feature was added that would include even
Chapter 6 - Integrating XML with ADO.NET
more dependant logic than just a simple check in/check out.
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
Chapter 8 -embedded
If you had Constraintsthe
and Data
call Relations
to a stored procedure directly into your page as you probably would have under the
ASP model,
Chapter you would
9 - ADO.NET have quite
Exception a task ahead of you! You would have to go to each page and add the handling
Handling
for the 10
Chapter new- Working
field nowwith
being
thereturned from
ODBC .NET theProvider
Data stored procedure and take proper action on it to handle it. Obviously,
this is a11
Chapter situation toProcedures
- Stored avoid. and Views
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
In the VideoCheckInCheckOut object, you'll notice a few things that are poorly coded in terms of good object-
Chapter 13 - Developing a Custom Data Provider
oriented principles, so be prepared. There's a conflict between good and fast under this model. You can have your
Chapter 14 - Developing Database Web Applications using ASP.NET
code 90 percent well designed and easy to maintain, but sometimes you just have to break it a little to get the kind
Chapter 15 - Using ADO.NET in Xml Web Services
of performance you need.
Chapter 16 - ASP.NET Server Controls and Data Binding
Chapter 17 - Building Real-World Web Applications
Seeing How It Works
Chapter 18 - Object-Relational Mapping in .NET
Chapter 19 - Mapped Objects: Performance
TheVideoCheckInCheckOut Considerations
component's and fairly
workings are Data simple.
Binding The design goal of this component is to
Chapter 20 - COM Interoperability and ADO.NET
provide the ability to check out a video tape to a user, check it back in, and be able to determine the state of this
Chapter 21 - Messaging
information in a few ways.
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
When a Arow
Appendix is inserted
- Relational into the VideoCheckOut
Databases: table, a new VideoCheckOutIDis "automagically" generated
Some Basic Concepts
by SQL B
Appendix Server. The VideoCheckIn
- Commonly table has a VideoCheckOutID that references this ID. Anytime there's a
Used SQL Statements
VideoCheckOutID
Appendix in the VideoCheckOut
C - ADO.NET Frequently table that's not in the VideoCheckIn table, a video is currently
Asked Questions
checked out.
Index
List of Figures
You can apply a few strategies on this data to determine if a video tape is checked out; you'll learn about this in the
List
nextof section,
Tables which is about the design of the Check In/Check Out components.
List of Listings
List of Sidebars
Making Design Tradeoffs
Applied ADO.NET: Building Data-Driven Solutions
by Mahesh Chand and David Talbot ISBN:1590590732
There are three main
Apresstradeoffs to pages)
2003 (928 look at between good and fast design. Depending on the requirements for
your application you'll have to make decisions
This text provides extensive on eachofofADO.NET
coverage these items and evaluate the kinds of risks doing
technology
it the fast way pose to the design of your system.
including ADO.NET internals, namespaces, classes, and
interfaces, and takes a comprehensive look at XML
namespaces
The seemingly innocent codeand classes,
in Listing andhas
18-9 howato integrate
number of both with
implications you must be aware of when
ADO.NET.
working with OR mapping in a system such as the video store application.
The other point of balance is large chunks of data. If the data to be returned is potentially large, it could be
more of a burden on your database servers overall than having just sorted through it on its own. It'll take
some time and thinking as to whether it's more database intensive one way or another. In the video store
application, for example, most people in the system of an average video store have checked out more than
100 tapes but only have two checked out at a time. Some people have checked out more than 1,000, and
returning all 2,000 (1,000 from the VideoCheckIn table and 1,000 from the VideoCheckOut table) could
cause serious stress on the database server and the network.
Applied ADO.NET: Building Data-Driven Solutions
by Mahesh Chand and David Talbot ISBN:1590590732
Understanding Component
Apress 2003 (928 pages) Isolation
This text provides extensive coverage of ADO.NET technology
The next problemincluding
with the ADO.NET
stored procedure in Listing 18-9 is the co-mingling of components. Notice how
internals, namespaces, classes, and
the stored procedure
interfaces, and takes a comprehensive look but
returns not only the VideoTapeID, the Title and Description as well? This
at XML
means that if an alteration
namespaces is made to the and
and classes, VideoTape component's
how to integrate data model, the
both with
ADO.NET. object will require reworking.
VideoCheckInCheckOut
The only advantage of returning the data in line is speed. If only the was returned, then the calling program
Table
wouldof likely
Contents
make a separate call to the VideoTapeDataAccess object's GetVideoTapeByID, each in turn
Applied ADO.NETBuilding
calling a stored procedureData-Driven
on its own Solutions
to get the VideoTape referenced by the returned ID. By returning the
Introduction
data inline you're removing the need for the calling program to make separate round trips to the database.
Chapter 1 - ADO.NET Basics
The disadvantage
Chapter of returninginthe
2 - Data Components dataStudio
Visual in line.NET
is that changes in your VideoTape component will likely
break the
Chapter 3 VideoCheckInCheckOut component. If you add a field to the VideoTape object such as
- ADO.NET in Disconnected Environments
YearReleased,
Chapter 4
you must alter the VideoCheckInCheckOut object and stored procedure as well. If
- ADO.NET in Connected Environments
these types of interdependencies
Chapter 5 - Handling ADO.NET Events
are not well documented, you're well on your way to creating an
unmaintainable system.
Chapter 6 - Integrating XML with ADO.NET
Chapter
The good7 -design
Data Binding anditWindows
way to do is to haveForms Data-Bound
the stored Controls
procedure only return VideoTapeIDs and then leave the
Chapter 8 - Constraints
job of turning these IDsand
intoData Relations
objects in the VideoTape component's court.
Chapter 9 - ADO.NET Exception Handling
If you employ
Chapter a technique
10 - Working likeODBC
with the this in your
.NET system,
Data make sure that it's well documented within the
Provider
VideoTape
Chapter and the
11 - Stored VideoCheckInCheckOut
Procedures and Views components. Both sides that are engaging in naughty
behavior
Chapter 12need to have
- Oracle, a lineand
SQLXML, drawn between
Other them
.NET Data not only to let future programmers that come after you
Providers
know what you've done, but also to help you keep track of what you've done.
Chapter 13 - Developing a Custom Data Provider
Chapter 14 - Developing Database Web Applications using ASP.NET
Creating a Workaround on Part of the Problem
Chapter 15 - Using ADO.NET in Xml Web Services
Chapter 16 - ASP.NET Server Controls and Data Binding
The component isolation part of the speed vs. design problem has a partial solution. You can take the
Chapter 17 - Building Real-World Web Applications
specifics of turning the results of your VideoCheckInCheckOut stored procedure from data into objects
Chapter 18 - Object-Relational Mapping in .NET
and place it squarely on the shoulders of your VideoTape component. By designing the VideoTape
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
component to include public methods for transforming VideoTapeData objects into VideoTape objects,
Chapter 20 - COM Interoperability and ADO.NET
you can bank on ADO.NET's SqlDataAdapter's ability to map the results of a stored procedure to fields
Chapter 21 - Messaging
in an ADO.NET DataSet.Listing 18-10 shows the VideoCheckInCheckOut object, found in
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
ObjectRelationalMappingVB/VideoStoreDataModel/VideoCheckInCheckOut.vb.
Appendix A - Relational Databases: Some Basic Concepts
Listing 18-10:
Appendix The VideoCheckInCheckOut
B - Commonly Used SQL Statements Object
Appendix C - ADO.NET Frequently Asked Questions
Index Public Function GetVideoTapesCheckedOutToUser(ByRef usr As User) _
List
AsofVideoTape()
Figures
List of Tables Dim cmd As New SqlDataAdapter("ap_SelectVideosCheckedOutToUser", _
List
New of Listings
SqlConnection(connectionString))
List of Sidebars
cmd.SelectCommand.CommandType = CommandType.StoredProcedure
cmd.SelectCommand.Parameters.Add("@UserID", _
SqlDbType.Decimal)
cmd.SelectCommand.Parameters("@UserID").Value = usr.UserID
Dim data As VideoTapeData
cmd.Fill(data)
Return VideoTapeDataAccess.GetVideoTapeArrayFromData(data)
End Function
In the GetVideoTapesCheckedOutToUser method, you use the VideoTapeData object to fill the
result set and use the GetVideoTapeArrayFromData method on the VideoTapeDataAccess object
Applied
to turn this data into ADO.NET:
an array Buildingobjects.
of VideoTape Data-Driven Solutions
This means that any alterations made to the structure
by Mahesh Chand and David Talbot
of the VideoTape table in the database will require fixing only the ISBN:1590590732
VideoTape component's code, not the
Apress 2003
VideoCheckInCheckOut (928 pages)
component's code. The stored procedure that the VideoCheckInCheckOut
component is using will still have toextensive
This text provides be alteredcoverage of ADO.NET
to ensure technology
it includes the new fields, but if you're careful in
including ADO.NET internals, namespaces, classes, and
documenting your dependencies this should make it manageable (see Listing 18-11).
interfaces, and takes a comprehensive look at XML
namespaces and classes, and how to integrate both with
Listing 18-11: The VideoCheckInCheckOut Object
ADO.NET.
Under that scenario, you would not need to change any of your front-end code to work with these
enhancements to your system.
2.
1. Check a video to see if it's checked out
Applied ADO.NET: Building Data-Driven Solutions
2. Check outby Mahesh Chand and David Talbot
a video ISBN:1590590732
Apress 2003 (928 pages)
3. Check theThis
video's
text status
provides extensive coverage of ADO.NET technology
including ADO.NET internals, namespaces, classes, and
4. List all checked out videos
interfaces, for the
and takes user
a comprehensive look at XML
namespaces and classes, and how to integrate both with
5. List all theADO.NET.
videos that are not checked out to anyone
Table of Contents
Console.WriteLine("Press Any Key To Quit...")
Applied ADO.NETBuilding Data-Driven Solutions
Console.ReadLine()
Introduction
End Sub
ChapterSub
1 -DisplayTapeArray(ByRef
ADO.NET Basics tapes() As VideoTape)
Chapter 2 -Dim
Data i
Components in Visual Studio .NET
As Integer
Chapter 3 -For i = in0Disconnected
ADO.NET To tapes.Length - 1
Environments
Chapter 4 Console.WriteLine("TAPE:"
- ADO.NET in Connected Environments + tapes(i).Title)
Chapter 5 -Next
Handling ADO.NET Events
ChapterEnd
6 -Sub
Integrating XML with ADO.NET
End Module
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
Chapter 8 - Constraints and Data Relations
Chapter 9 - ADO.NET Exception Handling
Chapter 10 - Working with the ODBC .NET Data Provider
The test case correctly exercises each of the methods provided by the VideoCheckInCheckOut
Chapter 11 - Stored
component. There'sProcedures and Views
a caveat here, though; if the video (VideoTapeID 1) is already checked out, an
Chapter 12 - Oracle, SQLXML, and Othershows
exception will be thrown. Figure 18-5 .NET Data Providers
the output of CheckInCheckOut test case.
Chapter 13 - Developing a Custom Data Provider
Chapter 14 - Developing Database Web Applications using ASP.NET
Chapter 15 - Using ADO.NET in Xml Web Services
Chapter 16 - ASP.NET Server Controls and Data Binding
Chapter 17 - Building Real-World Web Applications
Chapter 18 - Object-Relational Mapping in .NET
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
Chapter 20 - COM Interoperability and ADO.NET
Chapter 21 - Messaging
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Appendix A - Relational Databases: Some Basic Concepts
Appendix B - Commonly Used SQL Statements
Appendix C - 18-5:
Figure ADO.NET
TheFrequently Asked
output of the Questions
CheckInCheckOut test case
Index
List of Figures
List of Tables
List of Listings
List of Sidebars
Summary Applied ADO.NET: Building Data-Driven Solutions
by Mahesh Chand and David Talbot ISBN:1590590732
OR mapping affords theability
Apress to hide
2003 (928 pages)data access completely from your application and greatly simplify
the front-end code you write for your application.
This text provides extensive It allows
coverage you to write
of ADO.NET all of your data access logic once
technology
and allows significantly increased flexibility in your system.
including ADO.NET internals, namespaces, classes, and
interfaces, and takes a comprehensive look at XML
namespaces
In the next chapter, you'll lookand classes,
at how andthese
to use how to integrate
mapped both with
objects with ASP.NET widgets such as
DataGrids. You'llADO.NET.
also look at some additions to the performance end of your data model and implement
a high-performance caching mechanism.
Table of Contents
Applied ADO.NETBuilding Data-Driven Solutions
Introduction
Chapter 1 - ADO.NET Basics
Chapter 2 - Data Components in Visual Studio .NET
Chapter 3 - ADO.NET in Disconnected Environments
Chapter 4 - ADO.NET in Connected Environments
Chapter 5 - Handling ADO.NET Events
Chapter 6 - Integrating XML with ADO.NET
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
Chapter 8 - Constraints and Data Relations
Chapter 9 - ADO.NET Exception Handling
Chapter 10 - Working with the ODBC .NET Data Provider
Chapter 11 - Stored Procedures and Views
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Chapter 13 - Developing a Custom Data Provider
Chapter 14 - Developing Database Web Applications using ASP.NET
Chapter 15 - Using ADO.NET in Xml Web Services
Chapter 16 - ASP.NET Server Controls and Data Binding
Chapter 17 - Building Real-World Web Applications
Chapter 18 - Object-Relational Mapping in .NET
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
Chapter 20 - COM Interoperability and ADO.NET
Chapter 21 - Messaging
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Appendix A - Relational Databases: Some Basic Concepts
Appendix B - Commonly Used SQL Statements
Appendix C - ADO.NET Frequently Asked Questions
Index
List of Figures
List of Tables
List of Listings
List of Sidebars
Chapter Applied
19: Mapped Objects: Performance
ADO.NET: Building Data-Driven Solutions
by Mahesh Chand and David Talbot ISBN:1590590732
End Class
In the Page_Load method, first you create an instance of the VideoTapeDataAccess Data Access Component
(DAC). Next, youApplied ADO.NET: Building
set the DataSource Data-Driven Solutions
of the VideoTapesGrid to the array of VideoTape objects returned
by Mahesh Chand and David Talbot
from the GetAllVideoTapes() method of the VideoTapeDataAccess ISBN:1590590732 DAC. Finally, if the page request being
Apress 2003
served is not a postback, (928 pages)
you call the DataBind method to update the User Interface (UI) of the
VideoTapesGrid DataGrid. extensive coverage of ADO.NET technology
This text provides
including ADO.NET internals, namespaces, classes, and
interfaces,
The Hypertext Markup and takes
Language a comprehensive
(HTML) look at
side of this page XML as simple as the code-behind file using the
is just
namespaces and classes, and how to integrate both with
syntax identical toADO.NET.
the way you would bind to a DataSet or DataTable (see Listing 19-2).
When a data-bound object such as a DataGrid is processing a collection of items-either your objects or a
DataTable-it uses the Reflect architecture (found in System.Reflection) to make dynamic invocations on
your code at runtime. This is the "secret sauce" that makes data binding in .NET so flexible.
UsingDataBinder.Eval is only one of the options available to you, but you're missing out on half of the power
afforded
Table by this flexible reflection-based architecture.
of Contents
Applied ADO.NETBuilding Data-Driven Solutions
The more powerful way to work with bound objects is to get a reference to the objects themselves and use it to
Introduction
actually perform logic inline on your page. Listing 19-3 references the object itself and the number of characters in
Chapter 1 - ADO.NET Basics
the Description field.
Chapter 2 - Data Components in Visual Studio .NET
Chapter
Listing319-3:
- ADO.NET in Disconnected
The HTML Environments Page
of the TestGridObjects
Chapter 4 - ADO.NET in Connected Environments
Chapter 5 - Handling ADO.NET Events
<%@ Page Language="vb" AutoEventWireup="false" Codebehind="TestGrid.aspx.vb"
Chapter 6 - Integrating XML with ADO.NET
Inherits="TestDataGrid.WebForm1" %>
Chapter 7
<%@ import - Data Binding and Windows Forms Data-Bound Controls
namespace="VideoStoreDataModel.EnterpriseVB.VideoStore.Data" %>
Chapter
<!DOCTYPE8 - Constraints and Data
HTML PUBLIC Relations
"-//W3C//DTD HTML 4.0 Transitional//EN">
Chapter
<HTML> 9 - ADO.NET Exception Handling
Chapter
<HEAD> 10 - Working with the ODBC .NET Data Provider
Chapter 11 - Stored Procedures and Views
<Title></Title>
Chapter
<meta12name="GENERATOR"
- Oracle, SQLXML, and content="Microsoft
Other .NET Data Providers Visual Studio.NET 7.0">
Chapter 13 - Developing a Custom Data content="Visual
<meta name="CODE_LANGUAGE" Provider Basic 7.0">
<meta name="vs_defaultClientScript" content="JavaScript">
Chapter 14 - Developing Database Web Applications using ASP.NET
<meta15name="vs_targetSchema"
Chapter - Using ADO.NET in Xml Web Services
content="http://schemas.microsoft.com/intellisense/ie5">
Chapter 16 - ASP.NET Server Controls and Data Binding
</HEAD>
Chapter 17 - Building Real-World Web Applications
<body>
Chapter 18 - Object-Relational Mapping in .NET
<form Id="Form1" method="post" runat="server">
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
<asp:DataGrid Id="VideoTapesGrid" runat="server" AutoGenerateColumns="false">
Chapter 20 - COM Interoperability and ADO.NET
<Columns>
Chapter 21 - Messaging
<asp:TemplateColumn HeaderText="Title">
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
<ItemTemplate>
Appendix A - Relational Databases: Some Basic Concepts
<%# (CType(Container.DataItem, VideoTape)).Title%>
Appendix B - Commonly Used SQL Statements
</ItemTemplate>
Appendix</asp:TemplateColumn>
C - ADO.NET Frequently Asked Questions
Index <asp:TemplateColumn HeaderText="Description">
List of Figures
<ItemTemplate>
List of Tables
<%# (CType(Container.DataItem, VideoTape)).Description %>
( <%# (CType(Container.DataItem, VideoTape)).Description.Length %> )
List of Listings
</ItemTemplate>
List of Sidebars
</asp:TemplateColumn>
</Columns>
</asp:DataGrid>
</form>
</body>
</html>
Functionality such as this is important in a number of situations. For example, if you added a derived field to the
User object that concatenates the user's first name and last name and made sure they had initial caps, you could
display it inline using this technique.
The HTML for this page isADO.NET:
Applied fairly simple. You simply
Building cast theSolutions
Data-Driven Container.DataItemobject to be a VideoTape
object using CType(), and Chand
by Mahesh then you
andaccess the property the same
David Talbot way you would in regular compiled code.
ISBN:1590590732
Apress 2003 (928 pages)
To use an object such as VideoTape, you have to import the namespace in your HTML as well as in your code-
This text provides extensive coverage of ADO.NET technology
behind file so thatincluding
the HTML page will
ADO.NET know what
internals, namespace
namespaces, to look
classes, and in for your objects. If you don't do this, your
application will compile successfully
interfaces, and takeswithout any errors;look
a comprehensive however,
at XML when you try to actually view the Web page in
namespaces
your browser, you'll and classes,
get a "BC30002: Typeand howdefined:
is not to integrate both with error. Figure 19-2 shows the output of the
'VideoTape'"
ADO.NET.
TestGridObjects page that utilizes object binding.
Table of Contents
Applied ADO.NETBuilding Data-Driven Solutions
Introduction
Chapter 1 - ADO.NET Basics
Figure 19-2: The output of the TestGridObjects page
Chapter 2 - Data Components in Visual Studio .NET
Chapter 3
The output- of
ADO.NET in Disconnected Environments
the TestGridObjects page shows the title, description, and description's character count of all of the
Chapter 4 - ADO.NET
video tapes in Connected Environments
in the database.
Chapter 5 - Handling ADO.NET Events
Chapter 6 - Integrating XML with ADO.NET
Using Logic
Chapter 7
with Bound Objects
- Data Binding and Windows Forms Data-Bound Controls
Chapter
It often 8isn't
- Constraints andable
enough being DatatoRelations
just passively display data exactly as it is in the database. Quite often with a long
Chapter 9 - ADO.NET Exception
field such as a description, you'llHandling
want to clip it off after a certain number of characters so the line won't wrap.
Chapter 10 - Working with the ODBC .NET Data Provider
You'll likely
Chapter 11 - run intoProcedures
Stored a number and
of situations
Views where you want to call a method on one of your bound objects and
display12
Chapter the- result inline
Oracle, in a list.
SQLXML, andThere
Other are
.NETbasically two ways to apply logic to the cells in a bound collection.
Data Providers
Chapter 13 - Developing a Custom Data Provider
The first, and simplest, method is to cast the Container.DataItem object to your object type and call a method
Chapter 14 - Developing Database Web Applications using ASP.NET
on the object. This can be useful in a number of situations, especially if you have a method on your object that
Chapter 15 - Using ADO.NET in Xml Web Services
retrieves derived data. An example of where this might be useful is on a shopping cart object where you calculate
Chapter 16of- aASP.NET
the total person'sServer
orderControls
and wantand
to Data Binding
display it in your grid (see Listing 19-4).
Chapter 17 - Building Real-World Web Applications
Listing18
Chapter 19-4: The Theoretical
- Object-Relational Shopping
Mapping Cart Example
in .NET
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
Chapter 20 - COM Interoperability
<asp:TemplateColumn and ADO.NET
HeaderText="Total">
Chapter 21 - Messaging
<ItemTemplate>
Chapter <%#
22 - SQL Server and ADO.NET: Notes on Performance
(CType(Container.DataItem, ShoppingCart)).CalculateTotal().ToString() %>
Appendix
</ItemTemplate> Databases: Some Basic Concepts
A - Relational
Appendix B - Commonly Used SQL Statements
</asp:TemplateColumn>
Appendix C - ADO.NET Frequently Asked Questions
Index
List of Figures
In Listing 19-4 you use the same syntax for casting Container.DataItem to your object type and then convert it
List of Tables
to a string using the ToString() method. Everything you display in a bound collection must be converted to a
List of Listings
string before it's sent to a browser, so keep this in mind anytime you call a method that returns anything other than
List of Sidebars
a string.
The second method of applying logic to your grid is to pass your bound object to a function in your code-behind
object, process it there, and then return a string to be displayed inline in the DataGrid. In the FancyBinding Web
page example, a function is called in the code-behind object, which makes a decision as to whether it should clip
the Description field to 10 characters (see Listing 19-5). Granted, this is a simple example, but it represents a
common problem in data binding.
The example in Listing 19-5 has five columns. The first column is the VideoTapeID column, which you have to
have to set SelectedVideoTape, the second column simply displays the title of the video tape, and the third and
fourth columns are where things get interesting.
The Description column's ItemTemplate calls the TrimDescription() method and passes a VideoTape
object and the length to trim as a parameter. Because the HTML side of your page inherits from your code-behind
object, you can call any method that's protected or public on your code-behind object from your HTML.
The Show Description column provides the user with a link to choose that they want the description of one of the
lines to display in its entirety. There's a corresponding event handler in the code-behind object that makes this
happen (covered shortly).
Applied ADO.NET: Building Data-Driven Solutions
by Maheshthe
In the interest of simplicity, Chand
videoand David
store Talbot project keeps
example the mapped objects simple, so there's not a
ISBN:1590590732
good method to callApress
to show
2003how to do an inline method call. Therefore, the FancyBinding page displays a text
(928 pages)
string representing thetext
This object type extensive
provides of the VideoTape object
coverage of (seetechnology
ADO.NET Listing 19-6).
including ADO.NET internals, namespaces, classes, and
Listing 19-6: Theinterfaces, and takes
Code-Behind a comprehensive
Object look at XML
of the FancyBinding Page
namespaces and classes, and how to integrate both with
ADO.NET.
Imports VideoStoreDataModel.EnterpriseVB.VideoStore.Data
Table of Contents
Public Class FancyBinding
AppliedInherits
ADO.NETBuilding Data-Driven Solutions
System.Web.UI.Page
Introduction
Protected WithEvents VideoTapesDataGrid As System.Web.UI.WebControls.DataGrid
Chapter 1 - ADO.NET Basics
ChapterPublic
2 - Data Components
Property in Visual Studio .NET
ShowTapeID() As Decimal
Chapter 3 -Get
ADO.NET in Disconnected Environments
Chapter 4 If (ViewState("ShowTapeID")
- ADO.NET in Connected Environments = "") Then
Chapter 5 ReturnEvents
- Handling ADO.NET -1
Chapter 6 End If
- Integrating XML with ADO.NET
Chapter 7 - Data Return Convert.ToDecimal(ViewState("ShowTapeID"))
Binding and Windows Forms Data-Bound Controls
Chapter 8
End Get
- Constraints and Data Relations
Set(ByVal Value As Decimal)
Chapter 9 - ADO.NET Exception Handling
ViewState("ShowTapeID") = "" + Value.ToString()
Chapter 10 - Working with the ODBC .NET Data Provider
End Set
Chapter 11 - Stored Procedures and Views
End Property
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
ChapterPrivate
13 - Developing a Custom Data Provider
Sub Page_Load(ByVal sender As System.Object, _
Chapter 14 - Developing Database
ByVal e As System.EventArgs) Web Applications
_ using ASP.NET
Chapter
Handles15 -MyBase.Load
Using ADO.NET in Xml Web Services
Chapter 16 -Dim
ASP.NET
dacServer Controls
As New and Data Binding
VideoTapeDataAccess()
Chapter 17 -VideoTapesDataGrid.DataSource
Building Real-World Web Applications = dac.GetAllVideoTapes()
Chapter 18 -If
Object-Relational Mapping inThen
(Not IsPostBack) .NET
VideoTapesDataGrid.DataBind()
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
Chapter 20 -End
COM If
Interoperability and ADO.NET
ChapterEnd
21 -Sub
Messaging
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Public
Appendix Function
A - Relational TrimDescription(ByRef
Databases: Some Basic Concepts tape As VideoTape, _
ByVal characters As Int32) As String
Appendix B - Commonly Used SQL Statements
If (tape.Description.Length < characters Or _
Appendix C - ADO.NET Frequently Asked Questions
tape.VideoTapeID = ShowTapeID) _
Index
Then
List of Figures
Return tape.Description
List of Tables
End If
List of Listings
Return tape.Description.Substring(0, characters) + "..."
List of Sidebars
End Function
As the DataGrid is rendered it calls the TrimDescription() method for each row as it passes the current
videooftape.
Table The TrimDescription() method checks the length of the string and if it's shorter, it's trimmed;
Contents
otherwise it returns the full
Applied ADO.NETBuilding length of the
Data-Driven string. If it's under the length and it tried to call Substring on it, an
Solutions
IndexOutOfRange
Introduction exception would be thrown.
Chapter 1 - ADO.NET Basics
TheDataGrid also returns the full-length description if the VideoTapeID matches the ShowTapeID property.
Chapter 2 - Data Components in Visual Studio .NET
TheShowTapeID property is a member of the FancyBinding object that stores its value in the ViewState so it
Chapter 3 - ADO.NET in Disconnected Environments
can keep its state between page views.
Chapter 4 - ADO.NET in Connected Environments
If the description
Chapter is longer
5 - Handling thanEvents
ADO.NET the length to be trimmed and the user hasn't chosen to have the full description
displayed
Chapter 6 for that item, XML
- Integrating thenwith
the string
ADO.NETis clipped and the shortened string is returned.
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
The event handler for VideoTapesDataGrid_ItemCommand checks to make sure the command matches up
Chapter 8 - Constraints and Data Relations
with the Show Description button and then sets the member property ShowTapeID to the VideoTapeID that the
Chapter 9 - ADO.NET Exception Handling
user selected. It then calls VideoTapesGrid.DataBind() to refresh the display.
Chapter 10 - Working with the ODBC .NET Data Provider
Chapter
Figure 11 - Stored
19-3 shows Procedures and Views
the grid bound with the text description clipped, and Figure 19-4 shows the entire text.
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Chapter 13 - Developing a Custom Data Provider
Chapter 14 - Developing Database Web Applications using ASP.NET
Chapter 15 - Using ADO.NET in Xml Web Services
Figure
Chapter 16 - 19-3: TheServer
ASP.NET output of the FancyBinding
Controls page with the description shortened
and Data Binding
Chapter 17 - Building Real-World Web Applications
Chapter 18 - Object-Relational Mapping in .NET
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
Chapter 20 - COM Interoperability and ADO.NET
Figure 19-4: The output of the FancyBinding page with the description expanded
Chapter 21 - Messaging
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Appendix A - Relational Databases: Some Basic Concepts
Appendix B - Commonly Used SQL Statements
Appendix C - ADO.NET Frequently Asked Questions
Index
List of Figures
List of Tables
List of Listings
List of Sidebars
Understanding
AppliedProblematic Master-Detail
ADO.NET: Building Relationships
Data-Driven Solutions
by Mahesh Chand and David Talbot ISBN:1590590732
Several types of master-detail andpages)
Apress 2003 (928 parent-child relationships pose unique challenges to creating a high-
performance Web application. There are twocoverage
This text provides extensive main master-detail
of ADO.NET problems:
technology highly nested structures such as
category trees and large master-detail relationships.
including ADO.NET internals, namespaces, classes, and
interfaces, and takes a comprehensive look at XML
namespaces and classes, and how to integrate both with
Working with Highly Nested Structures
ADO.NET.
Most applications have a tree structure somewhere in them. Generally they are used as a method of navigating a
Table
Webof Contents
site or organizing a collection. The data structure behind them is generally the same and usually wrong. Look
Applied
atTableADO.NETBuilding Data-Driven
19-1 and see if you Solutions
can find the problem with this structure.
Introduction
Table 19-1:
Chapter The VideoCategory
1 - ADO.NET Basics Table, the Poor Performance Way
Chapter 2 - Data Components in Visual Studio .NET
DESCRIPTION DATA TYPE
Chapter 3 - ADO.NET in Disconnected Environments
Chapter 4 - ADO.NET in Connected Environments
CategoryID Int
Chapter 5 - Handling ADO.NET Events
Description Char(20)
Chapter 6 - Integrating XML with ADO.NET
ParentCategoryID
Chapter Int
7 - Data Binding and Windows Forms Data-Bound Controls
Chapter 8 - Constraints and Data Relations
CategoryID
Chapter is the primary
9 - ADO.NET key for
Exception this table. The Description field is the name of the category displayed to the user
Handling
so they10
Chapter know what they're
- Working seeing.
with the ODBC ParentCategoryID
.NET Data Provider is a subcategory of CategoryID. Generally the root-level
category
Chapter 11has a ParentCategoryID
- Stored Procedures and of 0 or -1 to indicate that it's a root-level category and that there's no parent
Views
category.
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Chapter 13 - Developing a Custom Data Provider
The problem with Table 19-1 is that there isn't a way to get the entire tree without executing multiple Select
Chapter 14 - Developing Database Web Applications using ASP.NET
statements. To get all of the categories in this tree you'll have to commit another scalability mistake-using
Chapter 15 -The
recursion. Using ADO.NET
only in Xml Web Services
way to successfully get the whole tree is to recursively select everything that has a
Chapter 16 - ASP.NET Server
ParentCategoryID equal to the Controls andCategoryID
current Data Binding
and so on. If your tree structure gets malformed, major
Chapter 17 - Building Real-World Web Applications
problems can happen on your Web server and/or database server depending on exactly how you coded your
Chapter 18 - Object-Relational Mapping in .NET
statement.
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
The second
Chapter problem
20 - COM with Table and
Interoperability 19-1ADO.NET
is that to get decent performance, you'll have to have an index for
CategoryID
Chapter and a clustered index for ParentCategoryID, which is unnecessary with the alternate method described
21 - Messaging
inTable 19-2.
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Appendix A - Relational Databases: Some Basic Concepts
Table 19-2: The VideoCategory Table, the High Performance Way
Appendix B - Commonly Used SQL Statements
Appendix C - ADO.NET Frequently Asked Questions
DESCRIPTION DATA TYPE
Index
CategoryID
List of Figures
Int
ListDescription
of Tables Char(20)
List of Listings
ParentCategoryID Int
List of Sidebars
RootCategoryID Int
Don't despair if you're using a system that uses this technique; it's a common programming error. The important
thing is that there's a solution. Table 19-2 shows a minor modification to the table that makes a major difference in
performance.
This structure adds a RootCategoryID column, which is the category at the base of this entire tree. This column
gives you a simple way to load the entire tree in a single Select statement with no recursion needed on the
database server, and with a little fancy code on your Web server, you can avoid recursion there as well.
An additional advantage of this structure is the level of optimization afforded by a single clustered index on the
RootCategoryID. Because you won't be using the CategoryID in the WHERE clause of any of your Select
statements, you won't even need it to be indexed-just the RootCategoryID column. Figure 19-5 shows a populated
Applied ADO.NET: Building Data-Driven Solutions
VideoCategory table, the high performance way.
by Mahesh Chand and David Talbot ISBN:1590590732
Apress 2003 (928 pages)
This text provides extensive coverage of ADO.NET technology
including ADO.NET internals, namespaces, classes, and
interfaces, and takes a comprehensive look at XML
namespaces and classes, and how to integrate both with
ADO.NET.
Table of Contents
Applied ADO.NETBuilding Data-Driven Solutions
Figure 19-5: The data in the VideoCategory table
Introduction
Chapter
One of 1the- mantras
ADO.NETof Basics
good database design is to never have repetitive data, a mantra we're breaking here with
good reason. In this case,
Chapter 2 - Data Components it's in
necessary. Listing
Visual Studio .NET19-7 shows the VideoCategory, VideoCategoryData, and
VideoCategoryDataAccess
Chapter objects.
3 - ADO.NET in Disconnected Environments
Chapter 4 - ADO.NET in Connected Environments
Listing 19-7: VideoCategory and Related Objects
Chapter 5 - Handling ADO.NET Events
Chapter 6 - Integrating XML with ADO.NET
Imports
Chapter 7 -System
Data Binding and Windows Forms Data-Bound Controls
Imports
Chapter 8 -System.Data
Constraints and Data Relations
Imports
Chapter 9 -System.Data.SqlClient
ADO.NET Exception Handling
Imports
Chapter 10 -System.Data.Common
Working with the ODBC .NET Data Provider
Chapter 11 - Stored Procedures and Views
Namespace EnterpriseVB.VideoStore.Data
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Chapter 13 - Developing a Custom Data Provider
Chapter 14 - Developing Database Web Applications using ASP.NET
Public Class VideoCategory
Chapter 15 - Using ADO.NET in Xml Web Services
Chapter 16 -Protected
ASP.NET Server Controls
data and Data Binding
As DataTable
Chapter 17 -Protected
Building Real-World Web Applications
index As Integer
Chapter 18 -Protected
Object-Relational Mapping in .NET As New ArrayList()
subCategories
Chapter 19 -Protected
Mapped Objects: Performance
Friend Considerations
ReadOnly Property and MyData()
Data BindingAs DataRow()
Chapter 20 - COM Get
Interoperability and ADO.NET
Chapter 21 - Messaging Dim myRow() As DataRow = {Me.data.Rows(index)}
Chapter 22 - SQL ServerReturn myRow
and ADO.NET: Notes on Performance
End Databases:
Appendix A - Relational Get Some Basic Concepts
Appendix B -End Property
Commonly Used SQL Statements
Appendix C - ADO.NET Frequently Asked Questions
Index Public Sub New(ByRef data As VideoCategoryData, ByVal index As Integer)
List of Figures
Me.data = data
Me.index = index
List of Tables
End Sub
List of Listings
Public Sub New()
List of Sidebars
Me.data = New VideoCategoryData()
data.Rows.Add(data.NewRow())
Me.index = 0
End Sub
TheVideoCategory object models the complete tree by providing a GetSubCategory() method to retrieve
the subcategories of the current category. Internally, the VideoCategory object stores its subcategories in an
ArrayList that it manages.
TheVideoCategory object also provides a FindCategoryByID() method that does a search on the tree and
returns the requested VideoCategory object. When a specific category gets referenced, either by the user
selecting something or by some other method, it will likely be by the CategoryID. Without a method such as this,
you would likely have to make another round trip to the database to load a category again that you already have in
Applied ADO.NET: Building Data-Driven Solutions
memory.
by Mahesh Chand and David Talbot ISBN:1590590732
Apress
Figure 19-6 shows the output of a pages)
2003 (928 test harness. A test harness is a simple application used to exercise the features
of a component. This
Testtext
harnesses
providescan be helpful
extensive in doing
coverage object-level
of ADO.NET or component-level debugging.
technology
including ADO.NET internals, namespaces, classes, and
interfaces, and takes a comprehensive look at XML
namespaces and classes, and how to integrate both with
ADO.NET.
Table of Contents
Applied ADO.NETBuilding Data-Driven Solutions
Introduction
Chapter 1 - ADO.NET Basics
Chapter 2 - Data Components in Visual Studio .NET
Figure
Chapter 3 - 19-6: Theinoutput
ADO.NET of the test
Disconnected harness
Environments
Chapter 4 - ADO.NET in Connected Environments
Chapter 5 - Handling ADO.NET Events
Working
Chapter 6 with aXML
- Integrating Much Larger Tree
with ADO.NET
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
The method
Chapter described and
8 - Constraints in the "Highly
Data Nested Structures" section works great on most category trees with a
Relations
reasonable amount of categories, but
Chapter 9 - ADO.NET Exception Handling
if you have a tree with potentially hundreds of categories, you'll need to use
an alternate method.
Chapter 10 - Working with the ODBC .NET Data Provider
Chapter 11 structures
For large - Stored Procedures
you need and Views
to be able to load the tree in logical blocks. For example, look at the large structure-
Chapter 12 - Oracle, SQLXML, and Other .NET
optimized version of the category tree in Data19-3.
Table Providers
Chapter 13 - Developing a Custom Data Provider
Chapter 14 - Developing
Table 19-3: Database Table
The BlockedTree Web Applications using ASP.NET
Chapter 15 - Using ADO.NET in Xml Web Services
DESCRIPTION DATA TYPE
Chapter 16 - ASP.NET Server Controls and Data Binding
Chapter 17 - Building Real-World Web Applications
CategoryID Int
Chapter 18 - Object-Relational Mapping in .NET
Description Char(20)
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
Chapter 20 - COM Interoperability and ADO.NET
ParentCategoryID Int
Chapter 21 - Messaging
GroupID Int
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Appendix A - Relational Databases: Some Basic Concepts
In this table's structure you can load the tree one block at a time and assemble the tree structure using your
Appendix B - Commonly Used SQL Statements
mapped objects in memory.
Appendix C - ADO.NET Frequently Asked Questions
Index
The stored procedure in Listing 19-8 allows you to request all the children of a specific category and get all of the
List of Figures
categories in that group in a single block. The result is you can display a collapsed tree to the user, and as they
expand
List the tree, the server won't have to hit the database for each expanded category.
of Tables
List of Listings
Listing 19-8: The GetBlockedCategory Stored Procedure
List of Sidebars
Table of Contents
Applied ADO.NETBuilding Data-Driven Solutions
Introduction
Chapter 1 - ADO.NET Basics
Chapter 2 - Data Components in Visual Studio .NET
Chapter 3 - ADO.NET in Disconnected Environments
Chapter 4 - ADO.NET in Connected Environments
Chapter 5 - Handling ADO.NET Events
Chapter 6 - Integrating XML with ADO.NET
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
Figure 19-7: The BlockedTree table with data
Chapter 8 - Constraints and Data Relations
Chapter 9 - ADO.NET Exception Handling
Chapter 10 - Working with the ODBC .NET Data Using
Provider
a Better Tree Control
Chapter 11 - Stored Procedures and Views
The
Chapter 12test harness
- Oracle, in this example
SQLXML, and Otheruses
.NETaData
simple custom-coded method of displaying a tree, but there's a better
Providers
way to do it. Microsoft provides the outstanding TreeView control for just this task in their Internet Explorer Web
Chapter 13 - Developing a Custom Data Provider
controls package at http://msdn.microsoft.com/library/default.asp?
Chapter 14 - Developing Database Web Applications using ASP.NET
url=/workshop/webcontrols/overview/treeview.asp. Don't let the name fool you-it's not only for
Chapter 15 - Using ADO.NET in Xml Web Services
Internet Explorer. In fact, it works quite well in Netscape 4.x and 6, thanks to some clever coding by Microsoft.
Chapter 16 - ASP.NET Server Controls and Data Binding
Chapter
The17Internet
- Building Real-World
Explorer Web Web Applications
controls package is free and includes several other useful Web components, such
Chapter
as 18 - Object-Relational
a tabbed Mapping in .NET toolbar that will have your Web applications looking like desktop
view and a docking-capable
applications!
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
Chapter 20 - COM Interoperability and ADO.NET
Chapter 21 - Messaging
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
A Final Note on Tree Optimization
Appendix A - Relational Databases: Some Basic Concepts
Appendix B - Commonly Used SQL Statements
Using recursion
Appendix to walk
C - ADO.NET through Asked
Frequently the tree is not the most high-performance method of moving through a tree
Questions
structure. As an alternative, you can create an index that looks like Table 19-4.
Index
List of Figures
Table
List 19-4: An Indexed Table
of Tables
ListCATEGORYID
of Listings DESCRIPTION PARENTCATEGORYID INDEX
List of Sidebars
1 Video Tapes -1 1.0.0
2 Horror 1 1.2.0
3 Comedy 1 1.3.0
4 Romantic Comedy 3 1.3.4
5 Drama 1 1.5.0
The index is a string that shows the category at each stop of the tree. In Table 19-4, the root CategoryID is 1;
therefore, all of the first numbers in the index are 1. The second number is the next level down in the tree, which is
different for everything except the Romantic Comedy category. Romantic Comedy is a subcategory of Comedy, so
they share the second number 3. The last number is 0 for everything but Romantic Comedy because only it is
Applied ADO.NET: Building Data-Driven Solutions
nested three levels deep.
by Mahesh Chand and David Talbot ISBN:1590590732
The index would Apress
not actually
2003be stored
(928 pages) in the database but instead assembled in memory as a way to quickly
iterate through the tree
This without
text recursion.
provides extensiveThe reason of
coverage why it's not technology
ADO.NET a good idea to necessarily store the index in the
including
database is because ADO.NET
you would haveinternals, namespaces,
to use the substring classes,
function and
as part of your subquery, which would cause a
table scan. interfaces, and takes a comprehensive look at XML
namespaces and classes, and how to integrate both with
ADO.NET.
Implementing an index such as this is both a good and a bad thing depending on how you look at it. The good part
is that once the tree is assembled, the tree can be iterated through and searched quickly and without recursion.
The of
Table bad part is there's a small upfront cost in building the index. Because .NET is stateless and will forget the tree
Contents
as soon as it's assembled,
Applied ADO.NETBuilding we included
Data-Driven the "quick-and-dirty" method over building the full index for the examples in
Solutions
this chapter.
Introduction
Chapter 1
If you plan-on
ADO.NET Basics
caching a tree or implementing some type of method that reuses the same structure, we
Chapter 2 - Data
recommend Components
adding an index.in Visual Studio .NET
Chapter 3 - ADO.NET in Disconnected Environments
Chapter 4 - ADO.NET in Connected Environments
Chapter 5 - Handling ADO.NET Events
Chapter 6 - Integrating XML with ADO.NET
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
Chapter 8 - Constraints and Data Relations
Chapter 9 - ADO.NET Exception Handling
Chapter 10 - Working with the ODBC .NET Data Provider
Chapter 11 - Stored Procedures and Views
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Chapter 13 - Developing a Custom Data Provider
Chapter 14 - Developing Database Web Applications using ASP.NET
Chapter 15 - Using ADO.NET in Xml Web Services
Chapter 16 - ASP.NET Server Controls and Data Binding
Chapter 17 - Building Real-World Web Applications
Chapter 18 - Object-Relational Mapping in .NET
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
Chapter 20 - COM Interoperability and ADO.NET
Chapter 21 - Messaging
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Appendix A - Relational Databases: Some Basic Concepts
Appendix B - Commonly Used SQL Statements
Appendix C - ADO.NET Frequently Asked Questions
Index
List of Figures
List of Tables
List of Listings
List of Sidebars
Working with Large
Applied Master-Detail
ADO.NET: Relationships
Building Data-Driven Solutions
by Mahesh Chand and David Talbot ISBN:1590590732
One of the most common issues
Apress 2003 (928 with OR mapping is how to handle large master-detail relationships without
pages)
degrading performance.
This text provides extensiveways
There are several to handle
coverage these types
of ADO.NET of relationships. You'll have to decide what
technology
works best for theincluding
application
ADO.NET internals, namespaces, classes, and depends on how your data will actually be
you're building because the best method
used; also, someinterfaces, and takes
of it may require somea comprehensive look at XML
experimentation.
namespaces and classes, and how to integrate both with
ADO.NET.
There are three primary approaches to this problem:
AVideoTape array called vids is added to the object. Because this array hasn't been initialized, its default value
isNothing. The read-only property Videos provides access to the VideoTape objects that belong in this
category.
When the calling program accesses the Videos array, the VideoCategory object checks to see if vids hasn't
been initialized. If it hasn't, then the VideoCategory creates an instance of the VideoTapeDataAccess DAC
and initializes vids with the array of VideoTapes that belong in this category. Listing 19-10 shows the HTML side
Applied ADO.NET: Building Data-Driven Solutions
of the LazyLoading page.
by Mahesh Chand and David Talbot ISBN:1590590732
Apress
Listing 19-10: The HTML Page
2003 (928of the LazyLoading Page
pages)
This text provides extensive coverage of ADO.NET technology
including ADO.NET internals, namespaces, classes, and
<%@ Page Language="vb" AutoEventWireup="false"
interfaces, and takes a comprehensive look at XML
Codebehind="LazyLoading.aspx.vb" Inherits="LazyLoadingWeb.WebForm1"%>
namespaces and classes, and how to integrate both with
ADO.NET.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
Table of Contents
<title></title>
Applied ADO.NETBuilding Data-Driven Solutions
<meta content="Microsoft Visual Studio.NET 7.0" name="GENERATOR">
Introduction
<meta content="Visual Basic 7.0" name="CODE_LANGUAGE">
Chapter <meta
1 - ADO.NET Basics
content="JavaScript" name="vs_defaultClientScript">
Chapter <meta
2 - Data Components in Visual Studio .NET
content=http://schemas.microsoft.com/intellisense/ie5
Chapter 3 - ADO.NET in Disconnected Environments
name="vs_targetSchema">
Chapter
</HEAD>4 - ADO.NET in Connected Environments
Chapter
<body> 5 - Handling ADO.NET Events
Chapter
<form6 id="Form1"
- Integrating XML with ADO.NET runat="server">
method="post"
<table
Chapter 7 cellSpacing="0" cellPadding="0"
- Data Binding and Windows width="100%"
Forms Data-Bound Controls border="0">
<tr>
Chapter 8 - Constraints and Data Relations
Chapter <td vAlign="top"
9 - ADO.NET Exception align="left">
Handling
<asp:table
Chapter 10 - Working withid="CategoryTree" runat="server"></asp:table>
the ODBC .NET Data Provider
</td>
Chapter 11 - Stored Procedures and Views
<td vAlign="top" align="left" width="100%">
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
<asp:DataGrid id="VideoTapesGrid" runat="server"
Chapter 13 - Developing a Custom Data Provider
AutoGenerateColumns="False" Width="100%">
Chapter 14 - Developing Database Web Applications using ASP.NET
<Columns>
Chapter 15 - Using ADO.NET in Xml Web Services
<asp:BoundColumn DataField="VideoTapeID"></asp:BoundColumn>
Chapter 16 - ASP.NET Server Controls and Data Binding
<asp:BoundColumn DataField="Title"></asp:BoundColumn>
Chapter </Columns>
17 - Building Real-World Web Applications
Chapter </asp:DataGrid>
18 - Object-Relational Mapping in .NET
Chapter
</td>19 - Mapped Objects: Performance Considerations and Data Binding
Chapter
</tr>20 - COM Interoperability and ADO.NET
Chapter 21 - Messaging
</table>
Chapter
</form>22 - SQL Server and ADO.NET: Notes on Performance
</body>
Appendix A - Relational Databases: Some Basic Concepts
</HTML>
Appendix B - Commonly Used SQL Statements
Appendix C - ADO.NET Frequently Asked Questions
Index
List of Figures
The HTML of this page consists of two main elements. The first is a server-side table that renders the category
List of Tables
tree, and the second is a DataGrid that displays the VideoTapes that belong in the category.
List of Listings
List of Sidebars
Server-side table generation in the code-behind object is obviously not the best solution for rendering a tree
control. When implementing these techniques on an actual system, please be a responsible programmer and
implement your tree views using a Web custom control or subclass Microsoft's Internet Explorer TreeView object.
Listing 19-11 shows the code-behind object of the LazyLoading page.
Imports VideoStoreDataModel.EnterpriseVB.VideoStore.Data
TheDisplayCategoryTree() method delegates the task of building the table to RenderTree() and
GetDepth() methods after loading the data from the database. The GetDepth() method is needed so you
know how deep the deepest element is in the tree to determine what the ColSpan needs to be for each category
to achieve a nice tabbed look for the tree. As the tree is being rendered, it checks each VideoCategory to see if
it matches the SelectedCategoryID property. If it does, it highlights that category.
At the end of the DisplayCategoryTree() method, it checks to see if SelectedCategoryID has a value
provided. If it does, the program makes a call to the FindCategoryByID() method of the VideoCategory
object to get the category that the user has selected. It then sets the DataSource of the VideoTapesGrid to the
Videos array of the VideoCategory object and calls DataBind() to update the display.
As the Videos array is accessed
Applied ADO.NET: forBuilding
the first time, behind the
Data-Driven scenes the VideoCategory object loads the array
Solutions
ofVideoTapes from the database and returns
by Mahesh Chand and David Talbot it. Subsequent attempts to the Videos collection of the
ISBN:1590590732
object will
VideoCategoryApress use the version
2003 (928 pages) already in memory without having to make another round trip to the
database.Figure This
19-8text
shows the LazyLoading page in action.
provides extensive coverage of ADO.NET technology
including ADO.NET internals, namespaces, classes, and
interfaces, and takes a comprehensive look at XML
namespaces and classes, and how to integrate both with
ADO.NET.
Table of Contents
Applied ADO.NETBuilding Data-Driven Solutions
Introduction
Chapter 1 - ADO.NET Basics
Chapter 2 - Data Components in Visual Studio .NET
Chapter 3 - ADO.NET in Disconnected Environments
Chapter 4 - ADO.NET in Connected Environments
Chapter 5 - Handling ADO.NET Events
Chapter 6 - Integrating XML with ADO.NET
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
Chapter 8 - Constraints and Data Relations
Chapter 9 - ADO.NET Exception Handling
Chapter 10 - 19-8:
Figure Working with
The the ODBC
output of the.NET Data Provider
LazyLoading page
Chapter 11 - Stored Procedures and Views
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Implementing an Incremental Lazy Loading Scheme
Chapter 13 - Developing a Custom Data Provider
Chapter 14 - Developing Database Web Applications using ASP.NET
Lazy loading
Chapter as described
15 - Using ADO.NET in
in the
Xmlprevious section works for most purposes, but if you're in a situation where the
Web Services
detail set
Chapter 16 is potentially
- ASP.NET hundreds
Server or thousands
Controls of records, then it becomes necessary to implement an incremental
and Data Binding
lazy loading
Chapter technique.
17 - Building Real-World Web Applications
Chapter 18 - Object-Relational Mapping in .NET
In a nutshell, when the information is first requested from the detail set, a small number of records will be retrieved
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
along with the count of the total number of records. If a request is made for one of the records that's out of range
Chapter
of what20 - COM
was Interoperability
loaded, andrecords
the rest of the ADO.NET will be loaded.
Chapter 21 - Messaging
An example
Chapter of where
22 - SQL Serverthis
andtechnique
ADO.NET:isNotes
useful
onisPerformance
on a "summary page" that displays the first 10 records on the front
page and
Appendix A allows the user
- Relational to click Some
Databases: for more information.
Basic Concepts Most of the time the user will not click the link to see the
additional
Appendix B -records, so itUsed
Commonly doesn't
SQLmake any sense to load them and incur the network overhead between your Web
Statements
server and
Appendix C - database to fetch theAsked
ADO.NET Frequently entireQuestions
result set if it's not necessary.
Index
To implement the incremental lazy loading scheme, you must modify both the stored procedure and the
List of Figures
VideoCategory component. The VideoCategory object needs to get the first 10 records from the database,
List
and itTables
of also needs to know how many records there are total in the database, so the VideoCategory object will
List
knowof Listings
if and when an additional round trip to the database is necessary. Listing 19-12 shows the
List of Sidebars
VideoTapeLoadByCategoryIncrID stored procedure, which loads the first 10 video tapes for a given
category.
To put this stored procedure to work, you need a custom indexer smart enough to transparently know when it
needs
Table of to return to the database to get the remaining records. Listing 19-13 shows the VideoCategoryIndexer.
Contents
Applied ADO.NETBuilding Data-Driven Solutions
Listing 19-13: VideoCategoryIndexer
Introduction
Chapter 1 - ADO.NET Basics
ChapterPublic Class
2 - Data VideoCategoryIndexer
Components in Visual Studio .NET
Chapter 3 - ADO.NET in Disconnected Environments
Chapter 4 -Private
ADO.NET invids As ArrayList
Connected Environments
Chapter 5 -Private cnt AsEvents
Handling ADO.NET Integer
Chapter 6 - Integrating XML with ADO.NET
Public Sub New(ByVal catID As Integer, ByRef conn As SqlConnection)
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
vids = New ArrayList()
Chapter 8 - Constraints and Data Relations
Dim sda As New SqlDataAdapter()
Chapter 9 - ADO.NET Exception Handling
sda.SelectCommand = New SqlCommand(_
Chapter 10 - Working with the ODBC .NET Data Provider
"VideoTapeLoadByCategoryIncrID", conn)
Chapter 11 - Stored Procedures and Views
sda.SelectCommand.CommandType = _
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
CommandType.StoredProcedure
Chapter 13 - Developing a Custom Data Provider
sda.SelectCommand.Parameters.Add(_
Chapter 14 - Developing
"@CategoryID", Database Web Applications
SqlDbType.Int, using ASP.NET
0, "CategoryID")
Chapter 15 - Usingsda.SelectCommand.Parameters.Add(_
ADO.NET in Xml Web Services
Chapter 16 - ASP.NETSqlDbType.Int)
"@TotalRows", Server Controls and Data Binding
sda.SelectCommand.Parameters("@TotalRows").Direction
Chapter 17 - Building Real-World Web Applications = _
ParameterDirection.Output
Chapter 18 - Object-Relational Mapping in .NET
sda.SelectCommand.Parameters("@CategoryID").Value
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding = catID
Dim data As New VideoTapeData()
Chapter 20 - COM Interoperability and ADO.NET
sda.Fill(data)
Chapter 21 - Messaging
cnt = Convert.ToInt32(sda.SelectCommand.Parameters("@TotalRows").Value)
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
vids.AddRange(VideoTapeDataAccess.GetVideoTapeArrayFromData(data))
Appendix A - Relational Databases: Some Basic Concepts
End Sub
Appendix B - Commonly Used SQL Statements
Appendix C - ADO.NET Frequently Asked Questions
Public Function Count() As Integer
Index
Return cnt
List of Figures
End Function
List of Tables
List of Listings
Public Property Videos(ByVal index As Integer) As VideoTape
List of Sidebars Get
If (index >= vids.Count) Then
FullLoad()
End If
Return CType(vids(index), VideoTape)
End Get
Set(ByVal Value As VideoTape)
vids(index) = Value
End Set
End Property
Console.WriteLine("Displaying All")
For i = 0 To iLoadCat.Count() - 1
Console.WriteLine("Item:" + iLoadCat.Videos(i).Title)
Next
Console.WriteLine("Test Complete.")
Applied ADO.NET: Building enter
Console.WriteLine("Press Data-Driven
key Solutions
to quit.")
by Mahesh Chand
Console.ReadLine() and David Talbot ISBN:1590590732
Apress 2003 (928 pages)
End Sub This text provides extensive coverage of ADO.NET technology
including ADO.NET internals, namespaces, classes, and
interfaces, and takes a comprehensive look at XML
End Module namespaces and classes, and how to integrate both with
ADO.NET.
Table
The of Contents lazy loading test case first creates an instance of VideoCategoryIndexer. Second, it displays
incremental
Applied ADO.NETBuilding
the number Data-Driven
of items loaded as well asSolutions
the total count of items to be found in the database. Next, it displays all of
theVideoTape objects currently loaded. Finally, it displays all of the items in the collection. As it does this final
Introduction
step, it 1reaches
Chapter out into
- ADO.NET the database and loads the remaining VideoTape objects as soon as the requested index
Basics
is outside
Chapter 2 of the loaded
- Data range.inFigure
Components 19-9 shows
Visual Studio .NET the output of the incremental lazy loading test case that tests the
LazyLoading
Chapter component.
3 - ADO.NET in Disconnected Environments
Chapter 4 - ADO.NET in Connected Environments
Chapter 5 - Handling ADO.NET Events
Chapter 6 - Integrating XML with ADO.NET
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
Chapter 8 - Constraints and Data Relations
Chapter 9 - ADO.NET Exception Handling
Chapter 10 - Working with the ODBC .NET Data Provider
Chapter 11 - Stored Procedures and Views
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Chapter 13 - Developing a Custom Data Provider
Chapter 14 - Developing Database Web Applications using ASP.NET
Chapter 15 - Using ADO.NET in Xml Web Services
Chapter 16 - ASP.NET Server Controls and Data Binding
Chapter 17 - Building Real-World Web Applications
Chapter 18 - Object-Relational Mapping in .NET
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
Chapter 20 - COM Interoperability and ADO.NET
Chapter 21 - Messaging
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Appendix A - Relational Databases: Some Basic Concepts
Appendix B - Commonly Used SQL Statements
Appendix C - ADO.NET Frequently Asked Questions
Index
List of Figures
List ofFigure
Tables 19-9: The incremental lazy loading test case output
List of Listings
List
The of amazing
Sidebars thing about this test case is that the object's lazy loading functionality is completely transparent. That
said, you can do certain things to enhance the functionality of this system.
If you were to implement IEnumerable, this collection would be capable of being data bound to any of .NET's
many controls. You would also be able to use it transparently as you would any other array.
Another thing you can do to enhance the functionality of VideoCategoryIndexer is to integrate it into the
VideoCategory object to use it as its internal means of loading the VideoTape objects that belong in the
category. This, combined with implementing the IEnumerable interface, would allow you to use incremental lazy
loading without modifying any code you may have written for the VideoCategory object.
You'll want to consider your own problem carefully before using lazy loading. If parts of your application will always
need the whole table, you need to keep VideoCategoryIndexer as a separate object only to be used when
you truly intend to do incremental lazy loading; otherwise you'll have code that calls two stored procedures instead
Applied ADO.NET: Building Data-Driven Solutions
of one.
by Mahesh Chand and David Talbot ISBN:1590590732
Apress 2003 (928 pages)
Loading theThisDetail When the Master Is Loaded
text provides extensive coverage of ADO.NET technology
including ADO.NET internals, namespaces, classes, and
The third main tool at your disposal
interfaces, and takeswhen working withlook
a comprehensive potentially
at XML large master-detail relationships is loading the
detail table whennamespaces
the master table is loaded.
and classes, andThe
howadvantages
to integrate of doing
both withthis are minimizing the round trips required
to the database toADO.NET.
load and work with your objects.
The situation where this strategy is beneficial is when you need to be able to display the master as well as most, or
Table ofthe
all, of Contents
detail. A good example is a page that displays 10 orders per page, and each order has 1 to 20 line items.
Applied ADO.NETBuilding
The master table Order will Data-Driven Solutions
always display the detail table Selection every time the master is displayed throughout
Introduction
the application.
Chapter 1 - ADO.NET Basics
The solution
Chapter is toComponents
2 - Data implement ainGetOrdersByDay()
Visual Studio .NET method (or whatever method of choosing the orders you
need to provide) that automatically calls the
Chapter 3 - ADO.NET in Disconnected Environmentsstored procedures to load the Orders and the Selections for that
day and then assemble them into your mapped
Chapter 4 - ADO.NET in Connected Environments objects in memory.
Chapter 5 - Handling ADO.NET Events
Loading the detail automatically in situations where it's not needed increases the round trips to the database and
Chapter 6 -application
increases Integratinglatency.
XML with ADO.NET
Always make sure that this is what your users will be doing most of the time when
Chapter 7 - Data Binding
using this technique. and Windows Forms Data-Bound Controls
Chapter 8 - Constraints and Data Relations
In situations
Chapter where you're
9 - ADO.NET loading
Exception more detail records than you'll be displaying, but you know that the user will be
Handling
asking 10
Chapter to see them fairly
- Working quickly,
with the ODBC makes this technique
.NET Data Provider a good fit if you have a simple high-performance caching
mechanism.
Chapter 11 - Stored Procedures and Views
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Chapter 13 - Developing a Custom Data Provider
Chapter 14 - Developing Database Web Applications using ASP.NET
Chapter 15 - Using ADO.NET in Xml Web Services
Chapter 16 - ASP.NET Server Controls and Data Binding
Chapter 17 - Building Real-World Web Applications
Chapter 18 - Object-Relational Mapping in .NET
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
Chapter 20 - COM Interoperability and ADO.NET
Chapter 21 - Messaging
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Appendix A - Relational Databases: Some Basic Concepts
Appendix B - Commonly Used SQL Statements
Appendix C - ADO.NET Frequently Asked Questions
Index
List of Figures
List of Tables
List of Listings
List of Sidebars
Using a Near-Zero-Impact Caching
Applied ADO.NET: Building Mechanism
Data-Driven Solutions
by Mahesh Chand and David Talbot ISBN:1590590732
When working with mapped
Apress 2003objects, a number of places and situations call for a fast but not necessarily
(928 pages)
reliable caching mechanism. Although .NETcoverage
This text provides extensive is built toofbeADO.NET
a highlytechnology
scalable stateless model, it doesn't hurt
to use a little caching
including ADO.NET internals, namespaces, classes, and unnecessary resources.
at the Web server as long as it doesn't consume
interfaces, and takes a comprehensive look at XML
A good example namespaces
of where thisand classes,isand
is helpful how something
loading to integrate such
both as
with
an object for the currently logged-in
ADO.NET.
user. For each page view you get a cookie from the user that's their user ID, query the database, load it
into the mapped object, and then display their first and last name in the header of the page. Using a
simple caching mechanism eliminates many of these round trips and thus boosts scalability and reducing
Table of Contents
latency.
Applied ADO.NETBuilding Data-Driven Solutions
Introduction
The problem with using a traditional cache that keeps items cached for a set amount of time is the amount
Chapter 1 - consumed
of memory ADO.NET Basics
by the server increases for each user. The entire point of a stateless model is to
Chapter 2 - Datawhere
avoid situations Components
memory in usage
Visual Studio .NETfor all of the incoming connections to the Web server.
increases
Chapter 3 - ADO.NET in Disconnected Environments
In most4situations
Chapter youincan
- ADO.NET use what
Connected Microsoft gives you by putting the Cache object to work. In situations
Environments
where you
Chapter 5 -have a layer
Handling of abstraction
ADO.NET Events between what you're caching and ASP.NET, this simply isn't
possible without explicitly passing a reference to the Cache object to your data access components. Using
Chapter 6 - Integrating XML with ADO.NET
good OR mapping practices such as abstracting your objects from the presentation layer make the Cache
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
object unusable in a mapped application. This unfortunately means that if you need a caching mechanism
Chapter 8 - Constraints and Data Relations
available in any situation where your code isn't executing on a Web server, you'll need to buy or write your
Chapter 9 - ADO.NET Exception Handling
own caching object. Because you can't use the Cache object in your data access components, the
Chapter 10 - Working with the ODBC .NET Data Provider
solution to implementing a caching system in the stateless model is to use weak references to your
Chapter
objects.11A -weak
Stored Procedures
reference is aand
wayViews
of referring to an object that tells the .NET runtime that if it needs the
Chapter
memory for something else to goOther
12 - Oracle, SQLXML, and ahead.NET
andData Providers
overwrite the space where your object is in memory. If you
Chapter
attempt13to -access
Developing
your aweak
Custom Data Provider
referenced object after its memory has been consumed by another process,
Chapter 14 - Developing
it will return Database
the Visual Basic null Web Applications
constant Nothing.using ASP.NET
Listing 19-15 shows the WeakCache object, a cache
Chapter
that won't15 -consume
Using ADO.NET in Xml
resources Web Services
needed by other parts of the application.
Chapter 16 - ASP.NET Server Controls and Data Binding
Listing17
Chapter 19-15: The WeakCache
- Building Object
Real-World Web Applications
Chapter 18 - Object-Relational Mapping in .NET
Chapter
Imports19 -System
Mapped Objects: Performance Considerations and Data Binding
Imports
Chapter 20 -System.Collections
COM Interoperability and ADO.NET
Chapter 21 - Messaging
Namespace
Chapter EnterpriseVB.VideoStore.Data
22 - SQL Server and ADO.NET: Notes on Performance
Appendix A - Relational Databases: Some Basic Concepts
Public
Appendix Class Used
B - Commonly WeakCache
SQL Statements
Appendix C - ADO.NET Frequently Asked Questions
Private hash As Hashtable
Index
Private lastCleared As DateTime
List of Figures
List of Tables
Public Sub New()
List of Listings
hash = New Hashtable()
List of Sidebars lastCleared = DateTime.Now
End Sub
Table of Contents
Applied ADO.NETBuilding Data-Driven Solutions
Introduction
Chapter 1 - ADO.NET Basics
Chapter 2 - Data Components in Visual Studio .NET
Chapter 3 - ADO.NET in Disconnected Environments
Chapter 4 - ADO.NET in Connected Environments
Chapter 5 - Handling ADO.NET Events
Chapter 6 - Integrating XML with ADO.NET
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
Chapter 8 - Constraints and Data Relations
Chapter 9 - ADO.NET Exception Handling
Chapter 10 - Working with the ODBC .NET Data Provider
Chapter 11 - Stored Procedures and Views
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Chapter 13 - Developing a Custom Data Provider
Chapter 14 - Developing Database Web Applications using ASP.NET
Chapter 15 - Using ADO.NET in Xml Web Services
Chapter 16 - ASP.NET Server Controls and Data Binding
Chapter 17 - Building Real-World Web Applications
Chapter 18 - Object-Relational Mapping in .NET
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
Chapter 20 - COM Interoperability and ADO.NET
Chapter 21 - Messaging
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Appendix A - Relational Databases: Some Basic Concepts
Appendix B - Commonly Used SQL Statements
Appendix C - ADO.NET Frequently Asked Questions
Index
List of Figures
List of Tables
List of Listings
List of Sidebars
Chapter Applied
20: COM Interoperability
by Mahesh Chand and David Talbot
and ADO.NET
ADO.NET: Building Data-Driven Solutions
ISBN:1590590732
Apress 2003 (928 pages)
Overview This text provides extensive coverage of ADO.NET technology
including ADO.NET internals, namespaces, classes, and
The component object Model
interfaces, (COM)
and has
takes a been aroundlook
comprehensive for many
at XMLyears and is used by many Windows
namespaces
applications. Eventually and classes,
the .NET platformand
willhow to integrate
replace COM, but both with
until then you may need to develop COM
ADO.NET.
components from .NET and access them from unmanaged code, or you may want to use COM
components in .NET applications. COM interoperability (also referred to as COM Interop) enables you to
use existing
Table COM components in .NET applications or use .NET components in unmanaged code.
of Contents
Applied ADO.NETBuilding Data-Driven Solutions
Note In this chapter you'll see how to use ADO and other COM-based data access technologies
Introduction
through COM Interop in your .NET applications. However, COM interoperability is a wide area. If
Chapter 1 you
- ADO.NET
want toBasics
learn about COM interoperability in more detail, you may want to read COM and
Chapter 2 .NET
- DataInteroperability
Components inbyVisual Studio
Andrew .NET (Apress, 2002).
Troelsen
Chapter 3 - ADO.NET in Disconnected Environments
The code
Chapter 4 written for the
- ADO.NET .NET Framework
in Connected is also referred to as managed code, and the code written for
Environments
traditional
Chapter 5 -Windows
Handling applications (previous to the .NET Framework) is called unmanaged code. Managed
ADO.NET Events
code contains
Chapter metadataXML
6 - Integrating used byADO.NET
with the Common Language Runtime (CLR).
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
In COM, type libraries stored metadata for a COM component and described the characteristics of a COM
Chapter 8 - Constraints and Data Relations
component. In .NET, an assembly is the primary building block of a .NET application. An assembly is a
Chapter 9 of
collection - ADO.NET Exception
functionality that's Handling
built, versioned, and deployed as a component. An assembly contains an
Chapter 10 - Working with the ODBC .NET
assembly manifest, which performs Data
similar Provider to a COM type library. The assembly manifest
functions
Chapter 11 - Stored Procedures and Views
includes information about an assembly such as the identity, version, culture, digital signature, compile-
Chapter 12 - Oracle, SQLXML,
time dependencies, files thatand Other
make up .NET Data Providers
the assembly implementation, and permissions required to run the
Chapter
assembly13 properly.
- Developing a Custom Data Provider
Chapter 14 - Developing Database Web Applications using ASP.NET
In brief,15
Chapter COM understands
- Using ADO.NET the language
in Xml of type libraries, and the .NET Framework understands the
Web Services
language of assembly manifests. So converting a type library into an assembly manifest provides
Chapter 16 - ASP.NET Server Controls and Data Binding
accessibility to COM components from the managed code, and converting an assembly manifest to a
Chapter 17 - Building Real-World Web Applications
COM type library provides accessibility to .NET assemblies in unmanaged code.
Chapter 18 - Object-Relational Mapping in .NET
Chapter
Interop19 - Mapped are
assemblies Objects:
.NETPerformance
assemblies Considerations and Data
that act as a bridge Binding
between managed and unmanaged code.
Chapter
Interop20 - COM Interoperability
assemblies and ADO.NET
provide mapping COM object members to equivalent .NET managed members.
Chapter 21 - Messaging
The .NET
Chapter 22 -Framework
SQL Serverdefines a common
and ADO.NET: set
Notes onofPerformance
data types. All .NET programming languages use these
commonA data
Appendix types. During
- Relational the import
Databases: process
Some Basic of a COM type library, there may be cases when the
Concepts
parameters and return values of COM objects use data types that do not correspond to .NET data types.
Appendix B - Commonly Used SQL Statements
The Interop marshaler handles these conversions for you. Interoperability marshaling is the process of
Appendix C - ADO.NET Frequently Asked Questions
packaging parameters and returning values into equivalent data types during conversion of a COM type
Index
library to an assembly manifest and an assembly manifest to a COM type library.
List of Figures
List ofTip
Tables
If you're looking for more COM-and Interop-related answers, you may want to look at the
List of Listings
System.Runtime.InteropServices namespace and its classes in the MSDN
List of Sidebars
documentation.
Exploring the .NET
Applied Interop
ADO.NET: Tools
Building Data-Driven Solutions
by Mahesh Chand and David Talbot ISBN:1590590732
The .NET Framework
Apressprovides many
2003 (928 tools for runtime as well as Visual Studio .NET (VS .NET) users.
pages)
We'll use VS .NET for the applications in thiscoverage
This text provides extensive chapter,ofbut it doesn't
ADO.NET hurt to take a look at these options. It's
technology
easy to convert aincluding
COM library
ADO.NET internals, namespaces, classes, and There are three different ways to do
into a .NET assembly using these tools.
so. interfaces, and takes a comprehensive look at XML
namespaces and classes, and how to integrate both with
ADO.NET.
Using Visual Studio .NET
Table of Contents
VS .NET provides a pretty simple way to import a type library in a managed application. The Project Add
Applied ADO.NETBuilding
Reference Data-Driven
menu option allows you toSolutions
access a COM library and add it to the project. This adds a
namespace to the project, so you can access the library members through that namespace.
Introduction
Chapter 1 - ADO.NET Basics
Using the
- DataType
Chapter 2 Library
Components Importer
in Visual Studio .NET and Exporter (Tlbimp.exe)
Chapter 3 - ADO.NET in Disconnected Environments
The Type
Chapter 4 Library Importer,
- ADO.NET known Environments
in Connected as Tlbimp or Tlbimp.exe, is a command-line utility to convert a COM
type library
Chapter 5 - into a .NET
Handling assembly.
ADO.NET Why a command-line utility? Well, this is an obvious question if you're
Events
using VS.
Chapter 6 -You can ignore
Integrating this
XML option
with if you use VS.NET for your development. This option is useful for
ADO.NET
developers
Chapter 7 - who
Data don't have
Binding andVS.NET.
Windows Forms Data-Bound Controls
Chapter 8 - Constraints and Data Relations
Tlbimp.exe takes as a minimum one argument, the filename of the COM type library that you want to
Chapter 9
convert to -an
ADO.NET Exception Handling
equivalent .NET Runtime assembly. The output of Tlbimp.exe is a binary file that contains
Chapter 10 - Working with the ODBC .NET Data Provider
runtime metadata for the types defined in the original COM type library.
Chapter 11 - Stored Procedures and Views
This is 12
Chapter the-syntax:
Oracle, SQLXML, and Other .NET Data Providers
Chapter 13 - Developing a Custom Data Provider
Chapter
tlbimp 14 tlbFile
- Developing Database Web Applications using ASP.NET
[options]
Chapter 15 - Using ADO.NET in Xml Web Services
Chapter 16 - ASP.NET Server Controls and Data Binding
where tlbFile
Chapter is the
17 - Building name of Web
Real-World the COM type library.
Applications
Chapter 18 - Object-Relational Mapping in .NET
Table 20-1 describes some of the Tlbimp.exe options.
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
Chapter 20 - COM
Table 20-1: Interoperability
Tlbimp.exe Optionsand ADO.NET
Chapter 21 - Messaging
OPTION
Chapter DESCRIPTION
22 - SQL Server and ADO.NET: Notes on Performance
Appendix A - Relational Databases: Some Basic Concepts
/asmversion:versionNumber Specifies the version of the assembly to produce
Appendix B - Commonly Used SQL Statements
Displays the available help commands
/helpC - ADO.NET Frequently Asked Questions
Appendix
Index
/namespace Specifies the namespace in which to produce the assembly
List of Figures
List/out:filename
of Tables Specifies the name of output assembly
List/references:filename
of Listings Specifies the namespaces to use to resolve references to
List of Sidebars types defined outside the current type library
/? Displays syntaxes and options for the tool
You can find Tlbimp.exe in the FrameworkSDK\Bin directory of your VS .NET or .NET Software
Development Kit (SDK) installation.
Table
Tableof 20-2:
Contents
Tlbexp.exe Options
Applied ADO.NETBuilding Data-Driven Solutions
OPTION
Introduction
DESCRIPTION
Chapter
/help 1 - ADO.NET Basics
Shows command syntax and options.
Chapter 2 - Data Components in Visual Studio .NET
/out:file
Chapter 3 Specifies
- ADO.NET the nameEnvironments
in Disconnected of the type library to generate equivalent to an assembly. If
there are no options, the default name of the type library is the same as the
Chapter 4 - ADO.NET in Connected Environments
assembly.
Chapter 5 - Handling ADO.NET Events
Chapter
/? 6 - Integrating
Shows XML with ADO.NET
command syntax and options.
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
You can
Chapter 8 find Tlbexp.exe
- Constraints in theRelations
and Data FrameworkSDK\Bin directory of your VS .NET or .NET SDK
installation.
Chapter 9 - ADO.NET Exception Handling
Chapter 10 - Working with the ODBC .NET Data Provider
Caution You can't use Tlbexp.exe to produce a type library from an assembly that was imported
Chapter 11 - Stored Procedures and Views
usingTlbimp.exe.
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Chapter 13 - Developing a Custom Data Provider
Chapter 14 - Developing Database Web Applications using ASP.NET
Chapter 15 - Using ADO.NET in Xml Web Services
Chapter 16 - ASP.NET Server Controls and Data Binding
Chapter 17 - Building Real-World Web Applications
Chapter 18 - Object-Relational Mapping in .NET
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
Chapter 20 - COM Interoperability and ADO.NET
Chapter 21 - Messaging
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Appendix A - Relational Databases: Some Basic Concepts
Appendix B - Commonly Used SQL Statements
Appendix C - ADO.NET Frequently Asked Questions
Index
List of Figures
List of Tables
List of Listings
List of Sidebars
Using the ADO Recordset
Applied in ADO.NET
ADO.NET: Building Data-Driven Solutions
by Mahesh Chand and David Talbot ISBN:1590590732
In this example, you'll
Apresssee how(928
2003 to import
pages) the ADO type library and use the ADO recordset to access a
database. After that, you'll fill data to a DataSet
This text provides extensive fromofthe
coverage ADO recordset
ADO.NET using a DataAdapter.
technology
including ADO.NET internals, namespaces, classes, and
Caution There's a cost and
interfaces, involved
takes in
a terms of performance
comprehensive when you use ADO in managed code because
look at XML
namespaces
of COM Interop. and classes,
Using ADO and how to integrate
in managed both with
code doesn't give you the same performance you can
ADO.NET.
get using and ADO.NET DataSet and DataReader. We use an ADO recordset only when we
have no other option--for example, when you have a library that uses ADO and you need to use
this library in managed applications.
Table of Contents
Applied
To testADO.NETBuilding Data-Driven
this application, create Solutions
a Windows application and drag a DataGrid control to the form from Toolbox.
Introduction
To add a reference to a COM type library, go to the Add Reference option from the Project menu and select
Chapter
the COM1 tab
- ADO.NET Basics
in the Add Reference dialog box. As you can see from the Figure 20-1, we selected Microsoft
Chapter
ActiveX2Data
- Data Components
Objects in Visual
2.7 Library. ClickStudio
Select.NET
to add the selection to the Selected Components list. Now click
Chapter
OK. 3 - ADO.NET in Disconnected Environments
Chapter 4 - ADO.NET in Connected Environments
Chapter 5 - Handling ADO.NET Events
Chapter 6 - Integrating XML with ADO.NET
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
Chapter 8 - Constraints and Data Relations
Chapter 9 - ADO.NET Exception Handling
Chapter 10 - Working with the ODBC .NET Data Provider
Chapter 11 - Stored Procedures and Views
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Chapter 13 - Developing a Custom Data Provider
Chapter 14 - Developing Database Web Applications using ASP.NET
Chapter 15 - Using ADO.NET in Xml Web Services
Chapter 16 - ASP.NET Server Controls and Data Binding
Chapter 17 - Building Real-World Web Applications
Chapter 18 - Object-Relational Mapping in .NET
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
Chapter 20 - COM Interoperability and ADO.NET
Chapter 21 - 20-1:
Figure Messaging
Adding a reference to a COM library
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Appendix A - Relational Databases: Some Basic Concepts
This action adds the ADODB namespace to the project. You can see this namespace now listed in the
Appendix B - Commonly Used SQL Statements
project's namespaces (see Figure 20-2).
Appendix C - ADO.NET Frequently Asked Questions
Index
List of Figures
List of Tables
List of Listings
List of Sidebars
Applied ADO.NET: Building Data-Driven Solutions
by Mahesh Chand and David Talbot ISBN:1590590732
Apress 2003 (928 pages)
This text provides extensive coverage of ADO.NET technology
including ADO.NET internals, namespaces, classes, and
interfaces, and takes a comprehensive look at XML
namespaces and classes, and how to integrate both with
ADO.NET.
Table of Contents
Applied ADO.NETBuilding Data-Driven Solutions
Introduction
Chapter 1 - ADO.NET Basics
Chapter 2 - Data Components in Visual Studio .NET
Chapter 3 - ADO.NET in Disconnected Environments
Chapter 4 - ADO.NET in Connected Environments
Chapter 5
Figure- 20-2:
Handling ADO.NET Events
Namespace after adding ADODB namespace to the project
Chapter 6 - Integrating XML with ADO.NET
Chapter 7 - Data
After adding Binding andreference
a namespace Windows to
Forms Data-Bound
a project, Controls
its members are available for use in your project. You
include this namespace in your application
Chapter 8 - Constraints and Data Relations by calling Imports. You also should add a reference to the
System.Data.OleDb
Chapter namespace
9 - ADO.NET Exception because you'll use the OleDb DataAdapter to fill a DataSet. So, add
Handling
these two
Chapter 10 -name-space
Working withreferences to theData
the ODBC .NET project with this:
Provider
Chapter 11 - Stored Procedures and Views
Chapter
Imports12 -ADODB
Oracle, SQLXML, and Other .NET Data Providers
Imports
Chapter 13 -System.Data.OleDb
Developing a Custom Data Provider
Chapter 14 - Developing Database Web Applications using ASP.NET
Chapter 15 - Using ADO.NET in Xml Web Services
Now you can use the ADO recordset and connection to access a database. As you can see from Listing 20-1,
Chapter 16 - ASP.NET Server Controls and Data Binding
you create a Connection object and set the connection mode and cursor location. After that, you call the
Chapter 17 - Building Real-World Web Applications
connection's Executemethod to execute a SQL statement that returns the _Recordset object. The Fill
Chapter 18 - Object-Relational Mapping in .NET
method of the DataAdapter reads data from a recordset and fills data to a DataSet. As you can see from
Chapter 19 -you
this code, Mapped
createObjects: Performance
a DataSet Considerations
and DataAdapter and
and Data
call theBinding
DataAdapter'sFill method. The Fill
Chapter 20 - COM Interoperability and ADO.NET
method takes three parameters: a DataSet, a recordset, and a DataSet name. Finally, you bind the
Chapter
DataSet21 -toMessaging
a DataGrid to fill data from the DataSet to the DataGrid.
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Listing 20-1:
Appendix Using an
A - Relational ADODB Some
Databases: Namespace to Access a Database
Basic Concepts
Appendix B - Commonly Used SQL Statements
Appendix
Private C -Sub
ADO.NET Frequently Asked Questions
Form1_Load(ByVal sender As System.Object, _
Index
ByVal e As System.EventArgs) Handles MyBase.Load
List
' of Figures SQL and Connection strings
Create
List
Dim of Tables
ConnectionString As String = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data
List Source=c:\\Northwind.mdb"
of Listings
Dim
List sql As String = "SELECT CustomerId, CompanyName, ContactName From Customers"
of Sidebars
' Create a Connection object and open it
Dim conn As Connection = New Connection()
Dim connMode As Integer = CType(ConnectModeEnum.adModeUnknown, Integer)
conn.CursorLocation = CursorLocationEnum.adUseServer
conn.Open(ConnectionString, "", "", connMode)
Dim recAffected As Object = Nothing
Dim cmdType As Integer = CType(CommandTypeEnum.adCmdText, Integer)
Dim rs As _Recordset = conn.Execute(sql, recAffected, cmdType)
' Create dataset and data adapter objects
Dim ds As DataSet = New DataSet("Recordset")
Dim da As OleDbDataAdapter = New OleDbDataAdapter()
' Call data adapter's Fill method to fill data from ADO
Applied
' Recordset to the ADO.NET:
dataset Building Data-Driven Solutions
by Mahesh Chand and David Talbot
da.Fill(ds, rs, "Customers") ISBN:1590590732
Apress
' Now use dataset 2003 (928 pages)
This text provides
DataGrid1.DataSource extensive coverage of ADO.NET technology
= ds.DefaultViewManager
End Sub including ADO.NET internals, namespaces, classes, and
interfaces, and takes a comprehensive look at XML
namespaces and classes, and how to integrate both with
ADO.NET.
To test this, create a new Windows application. After that, add a reference to the Microsoft ADO Ext. 2.7
Table of Contents
for DLL and Security component to the project (see Figure 20-4).
Applied ADO.NETBuilding Data-Driven Solutions
Introduction
Chapter 1 - ADO.NET Basics
Chapter 2 - Data Components in Visual Studio .NET
Chapter 3 - ADO.NET in Disconnected Environments
Chapter 4 - ADO.NET in Connected Environments
Chapter 5 - Handling ADO.NET Events
Chapter 6 - Integrating XML with ADO.NET
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
Chapter 8 - Constraints and Data Relations
Chapter 9 - ADO.NET Exception Handling
Chapter 10 - Working with the ODBC .NET Data Provider
Chapter 11 - Stored Procedures and Views
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Chapter 13 - Developing a Custom Data Provider
Chapter 14 - Developing Database Web Applications using ASP.NET
Chapter 15 - Using ADO.NET in Xml Web Services
Chapter 16 - ASP.NET Server Controls and Data Binding
Figure 20-4: Adding a reference to ADOX library
Chapter 17 - Building Real-World Web Applications
Chapter 18 - Object-Relational
After adding Mapping
the reference, you'll see in .NET
that the ADOX namespace is listed in the available namespaces in
your application
Chapter (seeObjects:
19 - Mapped Figure Performance
20-5). Considerations and Data Binding
Chapter 20 - COM Interoperability and ADO.NET
Chapter 21 - Messaging
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Appendix A - Relational Databases: Some Basic Concepts
Appendix B - Commonly Used SQL Statements
Appendix C - ADO.NET Frequently Asked Questions
Index
List of Figures
List of Tables
List of Listings
List of Sidebars
Now, the only thing you need to do is to use the namespace and its members. The ADOX classes should
be available in your application after adding Imports ADOX to the project. ADOX provides objects that
Applied
you can use to create ADO.NET:
databases, Building
tables, Data-Driven
and columns. TheSolutions
Catalog object represents a database and
by Mahesh Chand and David Talbot
itsCreate method creates a new database. The Table objectISBN:1590590732
represents a database table. You can add
columns to a TableApress 2003
object (928 pages)
using the Columns collection's Append method. Listing 20-2 creates a new
Microsoft AccessThis text provides
database extensive coverage
called Test.mdb with theoftable
ADO.NET technology
MyTable and two columns, col1 and col2, in it.
including ADO.NET internals, namespaces, classes, and
interfaces, and takes a comprehensive look at XML
Listing 20-2: Using ADOX from Managed Code
namespaces and classes, and how to integrate both with
ADO.NET.
Private Sub Form1_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
Table of Contents
' Create SQL and Connection strings
Applied ADO.NETBuilding Data-Driven Solutions
Dim ConnectionString As String = _
Introduction
"Provider=Microsoft.Jet.OLEDB.4.0; Data Source=c:\\Test.mdb"
ChapterTry
1 - ADO.NET Basics
Chapter 2 ' -Create
Data Components in Visual
a Catalog Studio .NET
object
Chapter 3 Dim
- ADO.NET
ct As inCatalog
Disconnected Environments
= New Catalog()
Chapter 4 ct.Create(ConnectionString)
- ADO.NET in Connected Environments
Chapter 5 ' -Create
Handling ADO.NET
a tableEvents
and two columns
Chapter 6 Dim
- Integrating XML with
dt As Table = ADO.NET
New Table()
Chapter 7 dt.Name = "MyTable"
- Data Binding and Windows Forms Data-Bound Controls
Chapter 8 dt.Columns.Append("col1",
- Constraints and Data Relations DataTypeEnum.adInteger, 4)
dt.Columns.Append("col2",
Chapter 9 - ADO.NET Exception Handling DataTypeEnum.adVarWChar, 255)
Chapter 10 - Working with the ODBC .NET Datacollection
' Add table to the tables Provider
Chapter 11ct.Tables.Append(CType(dt,
- Stored Procedures and Views Object))
Catch exp As Exception
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
MessageBox.Show(exp.Message.ToString())
Chapter 13 - Developing a Custom Data Provider
End Try
Chapter 14 - Developing Database Web Applications using ASP.NET
End Sub
Chapter 15 - Using ADO.NET in Xml Web Services
Chapter 16 - ASP.NET Server Controls and Data Binding
Chapter 17 - Building Real-World Web Applications
Chapter 18 - Object-Relational Mapping in .NET
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
Chapter 20 - COM Interoperability and ADO.NET
Chapter 21 - Messaging
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Appendix A - Relational Databases: Some Basic Concepts
Appendix B - Commonly Used SQL Statements
Appendix C - ADO.NET Frequently Asked Questions
Index
List of Figures
List of Tables
List of Listings
List of Sidebars
Accessing Applied
OLAPADO.NET:
ServerBuilding
Data Data-Driven
with ADO.NET
Solutions
by Mahesh Chand and David Talbot ISBN:1590590732
On-Line Analytical Processing
Apress (OLAP)
2003 (928 pages) is a service that represents raw data in a variety of views of
information that'sThis
easily understandable
text provides extensive by the users. of
coverage OLAP
ADO.NETprovides consistent and fast access to the data,
technology
which can be represented in personalized views in the real
including ADO.NET internals, namespaces, classes, andworld without considering the size and complexity
interfaces,
of the database. For example,andOLAP
takes can
a comprehensive
represent data lookin at
theXML
form of three-dimensional cubes and cells.
namespaces
The server involved and classes,
in this processing and how
is called an to integrate
OLAP server. both
Thewith
OLAP server is a high-capacity,
ADO.NET.
multiuser data manipulation engine specifically designed to work on multidimensional data structures. The
ActiveX Data Objects Multi-Dimensional Library (ADOMD) provides access to OLAP server data. OLAP
services
Table extract, summarize, organize, and store data warehouses in multidimensional structures, also
of Contents
known as OLAP server cubes.
Applied ADO.NETBuilding Data-Driven Solutions
Introduction
To test this OLAP sample, you'll use the FoodMart 2000 database that comes with Microsoft SQL Server
Chapter 1 - ADO.NET Basics
Analysis Server. Before testing this sample, you must have SQL Server 2000 Analysis Server running. If you
Chapter 2 - Data Components in Visual Studio .NET
don't have SQL Server 2000 Analysis Server running, you can install it from Microsoft SQL Server CD by
Chapter 3 SQL
selecting - ADO.NET
Serverin2000
Disconnected
ComponentsEnvironments
Install Analysis Services. This option installs SQL Server 2000
Chapter 4 - ADO.NET in Connected
Analysis Server on your machine. Environments
Chapter 5 - Handling ADO.NET Events
Note
Chapter 6 Installing Analysis
- Integrating Services
XML with may not install the FoodMart 2000 database. You may need to restore
ADO.NET
Chapter 7 the database
- Data Bindingfrom the C:\Program
and Windows Files\Microsoft
Forms Data-Bound Controls Analysis Services\Samples\
Chapter 8 foodmart
- Constraints2000.cab file. You can restore a database by using Analysis Manager Meta Data
and Data Relations
Chapter 9 Restore option.
- ADO.NET Exception Handling
Chapter 10 - Working with the ODBC .NET Data Provider
ADOMD functionality is defined in the msadomd.dll library. If this library is not listed in your COM
Chapter 11 - Stored Procedures and Views
components list, you can use the Browse button on the Add Reference dialog box to browse for it. The
Chapter
default 12 - Oracle,
path for thisSQLXML,
library isand Other .NET Data
C:\Program Providers
Files\Common Files\System\ADO (see Figure 20-6).
Chapter 13 - Developing a Custom Data Provider
Chapter 14 - Developing Database Web Applications using ASP.NET
Chapter 15 - Using ADO.NET in Xml Web Services
Chapter 16 - ASP.NET Server Controls and Data Binding
Chapter 17 - Building Real-World Web Applications
Chapter 18 - Object-Relational Mapping in .NET
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
Chapter 20 - COM Interoperability and ADO.NET
Chapter 21 - Messaging
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Appendix A - Relational Databases: Some Basic Concepts
Appendix B - Commonly Used SQL Statements
Appendix C - ADO.NET Frequently Asked Questions
Index
List of Figures
List ofFigure
Tables 20-6: Browsing the msadomd.dll library
List of Listings
List of Sidebars
After adding a reference to the msadomd.dll, the Add Reference dialog box looks like Figure 20-7.
Applied ADO.NET: Building Data-Driven Solutions
by Mahesh Chand and David Talbot ISBN:1590590732
Apress 2003 (928 pages)
This text provides extensive coverage of ADO.NET technology
including ADO.NET internals, namespaces, classes, and
interfaces, and takes a comprehensive look at XML
namespaces and classes, and how to integrate both with
ADO.NET.
Table of Contents
Applied ADO.NETBuilding Data-Driven Solutions
Introduction
Chapter 1 - ADO.NET Basics
Chapter 2 - Data Components in Visual Studio .NET
Chapter 3 - ADO.NET in Disconnected Environments
Chapter 4 - ADO.NET in Connected Environments
Figure 20-7: Adding a reference to msadomd.dll library
Chapter 5 - Handling ADO.NET Events
Chapter 6 - Integrating XML with ADO.NET
Now click
Chapter 7 the OKBinding
- Data button and
to add the reference.
Windows This actionControls
Forms Data-Bound adds the ADOMD namespace to the project (see
Figure 820-8).
Chapter - Constraints and Data Relations
Chapter 9 - ADO.NET Exception Handling
Chapter 10 - Working with the ODBC .NET Data Provider
Chapter 11 - Stored Procedures and Views
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Chapter 13 - Developing a Custom Data Provider
Chapter 14 - Developing Database Web Applications using ASP.NET
Chapter 15 - Using ADO.NET in Xml Web Services
Chapter 16 - ASP.NET Server Controls and Data Binding
Chapter 17 - Building Real-World Web Applications
Chapter 18 - Object-Relational Mapping in .NET
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
Chapter 20 - COM Interoperability and ADO.NET
Chapter 21 - Messaging
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Appendix A - Relational Databases: Some Basic Concepts
Appendix B - Commonly Used SQL Statements
Appendix C - ADO.NET Frequently Asked Questions
Index
List of Figures
List ofFigure
Tables 20-8: ADOMD namespace listed in the project namespaces
List of Listings
Now you can use the Imports directive to include the ADOMD namespace in your project and use ADOMD
List of Sidebars
classes.
To test the source code, create a Windows application and add two ListBox controls, two Button controls,
aTextBox control, and a Label controls and set their properties (see Figure 20-9).
Applied ADO.NET: Building Data-Driven Solutions
by Mahesh Chand and David Talbot ISBN:1590590732
Apress 2003 (928 pages)
This text provides extensive coverage of ADO.NET technology
including ADO.NET internals, namespaces, classes, and
interfaces, and takes a comprehensive look at XML
namespaces and classes, and how to integrate both with
ADO.NET.
Table of Contents
Applied ADO.NETBuilding Data-Driven Solutions
Introduction
Chapter 1 - ADO.NET Basics
Figure
Chapter 2 - 20-9: Windows form
Data Components to testStudio
in Visual ADOMD .NET
Chapter 3 - ADO.NET in Disconnected Environments
Chapter 4 -references
Next, add ADO.NET in
of Connected
ADOMD andEnvironments
ADODB in the application as follows:
Chapter 5 - Handling ADO.NET Events
Chapter
Imports6 -ADODB
Integrating XML with ADO.NET
Chapter
Imports7 -ADOMD
Data Binding and Windows Forms Data-Bound Controls
Chapter 8 - Constraints and Data Relations
Chapter 9 - ADO.NET Exception Handling
Also, add
Chapter 10 the following
- Working withvariables
the ODBC in .NET
the beginning of the form class:
Data Provider
Chapter 11 - Stored Procedures and Views
Private
Chapter 12 -strConn As String
Oracle, SQLXML, and Other .NET Data Providers
Private
Chapter 13 -dbConn Asa Custom
Developing Connection
Data Provider
Private
Chapter 14 -dtCatalog As Catalog
Developing Database Web Applications using ASP.NET
Private
Chapter 15 -cubes As CubeDefs
Using ADO.NET in Xml Web Services
Chapter 16 - ASP.NET Server Controls and Data Binding
Chapter 17 - Building Real-World Web Applications
After that, create Connection and Catalog objects on the form load and use CubeDefs of Catalog to
Chapter 18 -cubes.
get all the Object-Relational
As you canMapping in Listing
see from .NET 20-3, you then add all cubes to the ListBox and the number
Chapter
of cubes19to- the
Mapped Objects: Performance Considerations and Data Binding
TextBox.
Chapter 20 - COM Interoperability and ADO.NET
Listing21
Chapter 20-3: Getting All Available Cubes from the FoodMart 2000 Database
- Messaging
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Appendix
Private A -Sub
Relational Databases: Some Basic
Form1_Load(ByVal Concepts
sender As System.Object, _
Appendix
ByVal B -eCommonly Used SQL StatementsHandles MyBase.Load
As System.EventArgs)
Appendix
' C - ADO.NET Frequently
Construct connectionAskedstring
Questions
Index strConn = "Provider=msolap; Data Source = MCB;" & _
List of Figures
"Initial Catalog = FoodMart 2000; User ID =sa; Pwd="
' Create and open a connection
List of Tables
dbConn = New Connection()
List of Listings
dbConn.Open(strConn, "", "", _
List of Sidebars
CType(ConnectModeEnum.adModeUnknown, Integer))
' Create a Catalog object and set it's active connection
' as connection
dtCatalog = New Catalog()
dtCatalog.ActiveConnection = CType(dbConn, Object)
' Get all cubes
cubes = dtCatalog.CubeDefs
' Set text box text as total number of cubes
TextBox1.Text = cubes.Count.ToString()
Dim cube As CubeDef
For Each cube In cubes
Dim str As String = ""
ListBox1.Items.Add(cube.Name.ToString())
AppliedName
str = "Cube ADO.NET:
:" +Building Data-Driven Solutions
cube.Name.ToString() + ", "
by Mahesh Chand and David Talbot
str += "Description :" + cube.Description.ToString() ISBN:1590590732
+ ", "
str += Apress 2003 (928 pages)
"Dimensions :" + cube.Dimensions.Count.ToString()
Next This text provides extensive coverage of ADO.NET technology
including ADO.NET internals,
ListBox1.SetSelected(0, True)namespaces, classes, and
interfaces, and takes a comprehensive look at XML
End Sub namespaces and classes, and how to integrate both with
ADO.NET.
Table
If youofrun
Contents
the application, the output looks like Figure 20-10.
Applied ADO.NETBuilding Data-Driven Solutions
Introduction
Chapter 1 - ADO.NET Basics
Chapter 2 - Data Components in Visual Studio .NET
Chapter 3 - ADO.NET in Disconnected Environments
Chapter 4 - ADO.NET in Connected Environments
Chapter 5 - Handling ADO.NET Events
Chapter 6 - Integrating XML with ADO.NET
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
Chapter 8 - Constraints and Data Relations
Chapter 9 - ADO.NET Exception Handling
Chapter 10 - Working with the ODBC .NET Data Provider
Chapter 11 - Stored Procedures and Views
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Figure
Chapter 13 - 20-10: All available
Developing a Customcubes in the FoodMart 2000 database
Data Provider
Chapter 14 - Developing Database Web Applications using ASP.NET
The Get Dimensions button gets the dimensions of the selected cube in the left box in Figure 20-10.Listing
Chapter 15 - Using ADO.NET in Xml Web Services
20-4 returns the dimensions of a cube and adds it to the right box of Figure 20-10.
Chapter 16 - ASP.NET Server Controls and Data Binding
Chapter
Listing17 - Building
20-4: GettingReal-World Web Applications
All Dimensions of a Cube
Chapter 18 - Object-Relational Mapping in .NET
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
Private Sub Button1_Click(ByVal sender As System.Object, _
Chapter 20 - COM Interoperability and ADO.NET
ByVal e As System.EventArgs) Handles Button1.Click
Chapter 21 - Messaging
' Get the selected cube
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Dim cube As CubeDef = cubes(ListBox1.SelectedItem.ToString())
Appendix' AGet- Relational
all the Databases: Some Basic
dimensions Concepts
of the selecte cube
AppendixDimB -iCommonly
As IntegerUsed SQL Statements
AppendixFor C -iADO.NET
= 0 ToFrequently Asked Questions
cube.Dimensions.Count - 1 Step i + 1
Index Dim dimen As Dimension = cube.Dimensions(i)
List of Figures
ListBox2.Items.Add(dimen.Name.ToString())
List of Tables
Next
ListBox2.SetSelected(0, True)
List of Listings
End Sub
List of Sidebars
The output of the Get Dimensions button fills the right box with the dimensions (see Figure 20-11).
Applied ADO.NET: Building Data-Driven Solutions
by Mahesh Chand and David Talbot ISBN:1590590732
Apress 2003 (928 pages)
This text provides extensive coverage of ADO.NET technology
including ADO.NET internals, namespaces, classes, and
interfaces, and takes a comprehensive look at XML
namespaces and classes, and how to integrate both with
ADO.NET.
Table of Contents
Applied ADO.NETBuilding Data-Driven Solutions
Introduction
Chapter 1 - 20-11:
Figure ADO.NET Basicsdimensions of a cube
Getting
Chapter 2 - Data Components in Visual Studio .NET
The Get
Chapter 3 Dimension
- ADO.NETMembers button Environments
in Disconnected returns the properties of a dimension such as name, hierarchies,
UniqueName,
Chapter and Properties
4 - ADO.NET (seeEnvironments
in Connected Listing 20-5).
Chapter 5 - Handling ADO.NET Events
Listing 20-5: Getting Dimension Members
Chapter 6 - Integrating XML with ADO.NET
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
Private
Chapter 8 -Sub Button2_Click(ByVal
Constraints and Data Relations sender As System.Object, _
ByVal e As System.EventArgs)
Chapter 9 - ADO.NET Exception Handling
Handles Button2.Click
' Get the selected cube
Chapter 10 - Working with the ODBC .NET Data Provider
Dim cube As CubeDef = cubes(ListBox1.SelectedItem.ToString())
Chapter 11 - Stored Procedures and Views
' Get the selected Dimension
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Dim dimen As Dimension = cube.Dimensions(ListBox2.SelectedItem.ToString())
Chapter 13 - Developing a Custom Data Provider
ChapterMessageBox.Show("Dimension
14 - Developing Database Web Applications using ASP.NET
Properties :: Name=" + dimen.Name.ToString() & _
Chapter 15 ",
- Using ADO.NET in Xml Web Services
Description=" + dimen.Description.ToString() + ", Hierarchies=" & _
Chapter 16 dimen.UniqueName.ToString())
- ASP.NET Server Controls and Data Binding
Chapter 17
End Sub - Building Real-World Web Applications
Chapter 18 - Object-Relational Mapping in .NET
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
Chapter 20 - COM Interoperability and ADO.NET
The output
Chapter 21 - of Listing 20-5 looks like Figure 20-12.
Messaging
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Appendix A - Relational Databases: Some Basic Concepts
Appendix B - Commonly Used SQL Statements
Appendix C - ADO.NET Frequently Asked Questions
Index
List ofFigure
Figures20-12: Viewing dimension properties
List of Tables
List of Listings
List of Sidebars
Summary Applied ADO.NET: Building Data-Driven Solutions
by Mahesh Chand and David Talbot ISBN:1590590732
Even though the Apress
.NET Framework uses a new approach to access data sources (through ADO.NET), it
2003 (928 pages)
provides COM interoperability services to access
This text provides extensive previous
coverage data access
of ADO.NET libraries. In this chapter, you
technology
learned how to use ADO, ADOX, ADOMD, and OLAP services in
including ADO.NET internals, namespaces, classes, and managed applications using the COM
Interop services. interfaces, and takes a comprehensive look at XML
namespaces and classes, and how to integrate both with
ADO.NET.
Messaging service is one more popular topic these days. In the next chapter, you'll get a brief overview of
messaging services and learn how you can access them in the .NET Framework.
Table of Contents
Applied ADO.NETBuilding Data-Driven Solutions
Introduction
Chapter 1 - ADO.NET Basics
Chapter 2 - Data Components in Visual Studio .NET
Chapter 3 - ADO.NET in Disconnected Environments
Chapter 4 - ADO.NET in Connected Environments
Chapter 5 - Handling ADO.NET Events
Chapter 6 - Integrating XML with ADO.NET
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
Chapter 8 - Constraints and Data Relations
Chapter 9 - ADO.NET Exception Handling
Chapter 10 - Working with the ODBC .NET Data Provider
Chapter 11 - Stored Procedures and Views
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Chapter 13 - Developing a Custom Data Provider
Chapter 14 - Developing Database Web Applications using ASP.NET
Chapter 15 - Using ADO.NET in Xml Web Services
Chapter 16 - ASP.NET Server Controls and Data Binding
Chapter 17 - Building Real-World Web Applications
Chapter 18 - Object-Relational Mapping in .NET
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
Chapter 20 - COM Interoperability and ADO.NET
Chapter 21 - Messaging
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Appendix A - Relational Databases: Some Basic Concepts
Appendix B - Commonly Used SQL Statements
Appendix C - ADO.NET Frequently Asked Questions
Index
List of Figures
List of Tables
List of Listings
List of Sidebars
Chapter Applied
21: Messaging
ADO.NET: Building Data-Driven Solutions
by Mahesh Chand and David Talbot ISBN:1590590732
Apress 2003 (928 pages)
Overview This text provides extensive coverage of ADO.NET technology
including ADO.NET internals, namespaces, classes, and
Messaging services are oneand
interfaces, of the most
takes effective and popular
a comprehensive mediums to communicate between two
look at XML
namespaces
machines. It doesn't matter if and classes,
you're and how
a high-tech to integrate
developer, both with
a stockbroker, a high-school student, or a
ADO.NET.
businessperson. In some way, you use messaging services. Some of the common messaging services are
electronic mail (email), instant messenger services, text messaging via phones, or messaging used in
complex
Table distributed applications.
of Contents
Applied ADO.NETBuilding Data-Driven Solutions
We could easily write a book on messaging itself. In this chapter, we'll give you a brief overview of
Introduction
messaging services and how you can access them in the .NET Framework.
Chapter 1 - ADO.NET Basics
The messaging
Chapter 2 - Data functionality
Componentsin inthe .NET
Visual Framework
Studio .NET Library is accessible through the
3 - ADO.NET innamespace.
System.Messaging
Chapter DisconnectedThis chapter starts by introducing you to the basics of messaging and
Environments
theSystem.Messaging
Chapter namespace.
4 - ADO.NET in Connected After that, we'll show you how to use messaging classes to write
Environments
real-world
Chapter 5 -distributed messaging
Handling ADO.NET applications.
Events
Chapter 6 - Integrating XML with ADO.NET
So, what is messaging? A message is some data transferred between two machines. These machines can
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
be two computers or other devices such as cell phones. These machines may be attached to each other
Chapter 8 - Constraints and Data Relations
via the Internet, a local area network, or a wireless network. A message can be a simple text message, a
Chapter 9 - ADO.NET
string, some streamingException Handling
data, some live streaming data, or some complex objects. Messaging is the
Chapter 10 - Working with the ODBC .NET Data from
process of sending and receiving messages Provider
one machine to another.
Chapter 11 - Stored Procedures and Views
Amessage
Chapter 12 - queue
Oracle,isSQLXML,
a mediator
and between two
Other .NET machines.
Data When a sender sends a message, it goes to a
Providers
queue that
Chapter 13 - holds the message
Developing a Customand makes
Data sure the receiver gets the message. A message queue also
Provider
guarantees
Chapter the deliveryDatabase
14 - Developing of the message. One of the
Web Applications simplest
using examples of this is email exchange using
ASP.NET
Microsoft
Chapter 15 Outlook. If you have
- Using ADO.NET anyWeb
in Xml message in your Outbox, Outlook will try to send it until it leaves. The
Services
messaging service that handles message queues in Microsoft Windows is called Microsoft Message
Chapter 16 - ASP.NET Server Controls and Data Binding
Queuing (MSMQ).
Chapter 17 - Building Real-World Web Applications
Chapter 18 - Object-Relational Mapping in .NET
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
Chapter 20 - COM Interoperability and ADO.NET
Chapter 21 - Messaging
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Appendix A - Relational Databases: Some Basic Concepts
Appendix B - Commonly Used SQL Statements
Appendix C - ADO.NET Frequently Asked Questions
Index
List of Figures
List of Tables
List of Listings
List of Sidebars
IntroducingApplied
Types of Queues
ADO.NET: Building Data-Driven Solutions
by Mahesh Chand and David Talbot ISBN:1590590732
You can divide queues
Apressin two categories:
2003 (928 pages) user and system. The user queues are used by a group of
network users, and system queues are used by the system.
This text provides extensive coverage of ADO.NET technology
including ADO.NET internals, namespaces, classes, and
interfaces, and takes a comprehensive look at XML
Using User Queues namespaces and classes, and how to integrate both with
ADO.NET.
You can further categorize the user queues into four categories: public, private, administration, and
response queues.
Table of Contents
The public
Applied queues are published
ADO.NETBuilding on the
Data-Driven network's shared areas, which are available to all the valid users
Solutions
of the network. In other words, all of the authorized users of the network can access these queues.
Introduction
Chapter 1 - ADO.NET Basics
Unlike public queues, the private queues are not published on the network. Instead, they are published
Chapter 2 - Data Components in Visual Studio .NET
and available only on the local machine that contains them. Only the workgroup users can access this
Chapter
type of 3queue.
- ADO.NET in Disconnected
To access Environments
private queues, a user has to pass the path and label of the queue. A path of the
Chapter 4 - ADO.NET in Connected Environments
queue is a folder where queues are stored.
Chapter 5 - Handling ADO.NET Events
The administration
Chapter queues
6 - Integrating XML contain messages acknowledging the receipt of messages, and the response
with ADO.NET
queues7contain
Chapter - Datamessages received
Binding and WindowsbyForms
the destination
Data-Bound applications.
Controls
Chapter 8 - Constraints and Data Relations
Using System
Chapter 9 Queues
- ADO.NET Exception Handling
Chapter 10 - Working with the ODBC .NET Data Provider
You can
Chapter 11also divideProcedures
- Stored the systemand
queues
Views into four categories: journal, dead letter, report, and private system
queues.
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Chapter 13 - Developing a Custom Data Provider
The journal queues can store copies of messages that applications send by using a queue. They also
Chapter 14 - Developing Database Web Applications using ASP.NET
store the messages removed from a queue. Each client machine maintains a journal queue for outgoing
Chapter 15 - and
messages, Using ADO.NET
the in Xml
server also Web Services
maintains a journal queue for each individual queue.
Chapter 16 - ASP.NET Server Controls and Data Binding
The dead
Chapter 17 -letter queues
Building stores undelivered
Real-World and expired messages. This queue is maintained on the client
Web Applications
machine
Chapter 18only.
- Object-Relational Mapping in .NET
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
The report queues contain messages that store the route of a message. These queues are also stored on
Chapter 20 - COM Interoperability and ADO.NET
the client machine, and the private system queues store administrative and notification messages.
Chapter 21 - Messaging
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Appendix A - Relational Databases: Some Basic Concepts
Appendix B - Commonly Used SQL Statements
Appendix C - ADO.NET Frequently Asked Questions
Index
List of Figures
List of Tables
List of Listings
List of Sidebars
Installing Message Queuing
Applied ADO.NET: Building Data-Driven Solutions
by Mahesh Chand and David Talbot ISBN:1590590732
Before you start working
Apress with
2003 MSMQ, you must ensure that you've installed MSMQ on the server. You can
(928 pages)
install MSMQ by This
selecting Control Panel
text provides extensive Add/Remove Programs
coverage of ADO.NET Message Queuing Services. If you
technology
aren't running Windows
including ADO.NET internals, namespaces, classes, and you to insert your Windows CD.
2000 or later versions, the installation may ask
interfaces, and
Windows 2000 (Professional andtakes a comprehensive
Server) installs MSMQ look at XML
with the operating system by default.
namespaces and classes, and how to integrate both with
ADO.NET.
To see if you have MSMQ installed your machine, you can select Control Panel Administrative Tools
Computer Management and then expand the Message Queuing node, as shown in Figure 21-1.
Table of Contents
Applied ADO.NETBuilding Data-Driven Solutions
Introduction
Chapter 1 - ADO.NET Basics
Chapter 2 - Data Components in Visual Studio .NET
Chapter 3 - ADO.NET in Disconnected Environments
Chapter 4 - ADO.NET in Connected Environments
Chapter 5 - Handling ADO.NET Events
Chapter 6 - Integrating XML with ADO.NET
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
Chapter 8 - Constraints and Data Relations
Chapter 9 - ADO.NET Exception Handling
Chapter 10 - Working with the ODBC .NET Data Provider
Chapter 11 - Stored Procedures and Views
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Chapter 13 - Developing a Custom Data Provider
Chapter 14 - Developing Database Web Applications using ASP.NET
Figure 21-1: Viewing the Messaging Queuing node from Computer Management
Chapter 15 - Using ADO.NET in Xml Web Services
Chapter 16 - ASP.NET Server Controls and Data Binding
Caution If you don't see the Message Queuing option here, you must install it.
Chapter 17 - Building Real-World Web Applications
Chapter 18 - Object-Relational Mapping in .NET
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
Chapter 20 - COM Interoperability and ADO.NET
Chapter 21 - Messaging
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Appendix A - Relational Databases: Some Basic Concepts
Appendix B - Commonly Used SQL Statements
Appendix C - ADO.NET Frequently Asked Questions
Index
List of Figures
List of Tables
List of Listings
List of Sidebars
Using the System.Messaging Namespace
Applied ADO.NET: Building Data-Driven Solutions
by Mahesh Chand and David Talbot ISBN:1590590732
Before writing messaging applications,
Apress 2003 (928 pages) let's take a quick look at the key classes provided by the
System.Messaging namespace.
This text provides extensive coverage of ADO.NET technology
including ADO.NET internals, namespaces, classes, and
TheMessageQueue class isand
interfaces, thetakes
mostaimportant class look
comprehensive in theatSystem.Messaging
XML namespace. This
namespaces and classes, and how to integrate both with
class represents a messaging queue in a messaging queuing server. This class provides members to
send messages to ADO.NET.
and receive messages from MSMQ. The Create and Delete static methods of this
class create and delete message queues, respectively. This class also provides methods to retrieve and
filter private and public queues available on the server.
Table of Contents
Applied ADO.NETBuilding
TheMessage Data-Driven
class is another Solutions
important class of the System.Messaging namespace. The Message
Introduction
object represents a message in message queuing. This class provides access to messages of a message
Chapter
queue.1It provides
- ADO.NET Basics that you can use to read a message body, label, priority, posting time,
properties
Chapter
sender,2authentication
- Data Components
mode, in Visual
and Studio .NET
so on.
Chapter 3 - ADO.NET in Disconnected Environments
TheMessageEnumerator
Chapter class represents
4 - ADO.NET in Connected an enumeration, which provides a forward-only cursor
Environments
through5 messages
Chapter - HandlinginADO.NET
a message queue, which you can use to navigate through from the first message to
Events
the last in -a Integrating
Chapter 6
message queue. An enumerator returns information about the message at the current cursor
XML with ADO.NET
position. It doesn't remove the message from the queue.
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
Chapter 8 - Constraints and Data Relations
TheMessagePropertyFilter class controls and filters messages from a message queue. The
Chapter 9 - ADO.NET Exception Handling
MessageReadPropertyFilter property of MessageQueue uses the MessagePropertyFilter
Chapter
object. 10 - Working with the ODBC .NET Data Provider
Chapter 11 - Stored Procedures and Views
TheMessageQueueEnumerator
Chapter class
12 - Oracle, SQLXML, and Other provides
.NET a forward-only cursor that you can use to enumerate
Data Providers
(loop) through
Chapter the messages
13 - Developing in aData
a Custom server.
Provider
Chapter 14 - Developing Database Webclass
TheMessageQueueTransaction Applications usingaASP.NET
represents transaction in message queuing. A complete
Chapter 15 - Using ADO.NET in Xml Web Services
messaging transaction contains a successful send and successful receive. The
Chapter 16 - ASP.NET Server Controls
MessageQueueTransaction canand Data or
commit Binding
roll back transactions. Messages sent to transactional
Chapter 17 - Building Real-World Web Applications
queues are removed if a transaction is rolled back, and messages received from transactional queues are
Chapter 18to- the
returned Object-Relational Mapping in is
queue if the transaction .NET
rolled back.
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
TheTrustee
Chapter class
20 - COM represents aand
Interoperability user or a group account with a set of access rights that is trying to
ADO.NET
access a messaging item. The AccessControlEntry class allows, denies, or revokes access rights to a
Chapter 21 - Messaging
trustee.
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Appendix A - Relational Databases:
TheAccessControlList classSome Basic Concepts
represents a loss of access control entries that specify access rights for
Appendix
trustees.BIt's
- Commonly Used
a collection SQL Statements
of AccessControlEntry objects.
Appendix C - ADO.NET Frequently Asked Questions
TheSystem.Messaging namespace also provides some formatting-related classes. These classes are
Index
ActiveXMessengerFormatter,
List of Figures BinaryMessageFormatter, and XmlMessageFormatter.
List of Tables
Messaging in .NET is compatible with previous versions of MSMQ. ActiveXMessengerFormatter
List of Listings
provides interoperability functionality, so you can use MSMQ ActiveX controls in the .NET Framework.
List of Sidebars
TheBinaryMessageFormatter class serializes and deserializes objects to or from the body of a
message in a binary format.
XML is the default format used by MSMQ and messaging services. XmlMessageFormatter is
responsible for serializing and deserializing objects to or from the body of a message in Extensible Markup
Language (XML) format using XML Schema Definition (XSD).
Finally, the System.Messaging namespace also provides one messaging-related exception handling
class:MessageQueueException. This class represents the exception that is thrown if an MSMQ internal
error occurs.
Working with Message
Applied ADO.NET: Queues
Building Data-Driven Solutions
by Mahesh Chand and David Talbot ISBN:1590590732
TheMessageQueue class
Apress is a(928
2003 wrapper
pages) around MessageQueuing, which defines functionality to access
and manage a queue on an MSMQ server. This
This text provides extensive classofalso
coverage provides
ADO.NET methods to create and delete queues,
technology
send and receiveincluding
messages, and retrieve queues and messages.
ADO.NET internals, namespaces, classes, and
interfaces, and takes a comprehensive look at XML
namespaces and classes, and how to integrate both with
Using the MessageQueue Properties
ADO.NET.
It's always a good idea to know what functionality is provided by a class before using the class. Table 21-1
Table of Contents
describes the MessageQueue class properties.
Applied ADO.NETBuilding Data-Driven Solutions
Table 21-1: The MessageQueue Class Properties
Introduction
Chapter 1 - ADO.NET Basics
PROPERTY DESCRIPTION
Chapter 2 - Data Components in Visual Studio .NET
Chapter 3 - ADO.NET in Disconnected Environments
Authenticate This property represents whether a queue will accept only
Chapter 4 - ADO.NET in Connected Environments
authenticated messages. The queue will reject
Chapter 5 - Handling ADO.NET Events nonauthenticated messages. Both get and set.
Chapter 6 - Integrating XML with ADO.NET
BasePriority This property represents the base priority of messages.
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
Both get and set.
Chapter 8 - Constraints and Data Relations
9 - ADO.NET Exception Handling This property is true if a message queue can be read;
CanRead
Chapter
Chapter 10 - Working with the ODBC .NET otherwise, it's false. Both get and set.
Data Provider
Chapter 11 - Stored Procedures and Views This property is true if a message queue can be written to;
CanWrite
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
otherwise, it's false. Both get and set.
Chapter 13 - Developing a Custom Data Provider
Category This property
Chapter 14 - Developing Database Web Applications usingrepresents
ASP.NET the queue category. Both get and
set.
Chapter 15 - Using ADO.NET in Xml Web Services
Chapter 16 - ASP.NET Server Controls and This
CreateTime Dataproperty
Binding gets the time and date the queue was
Chapter 17 - Building Real-World Web Applications
created.
Chapter 18 - Object-Relational Mapping in .NET
DefaultPropertyToSend This represents the default message property when an
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
application sends a message. Both get and set.
Chapter 20 - COM Interoperability and ADO.NET
DenySharedRecieve
Chapter 21 - Messaging This property is true if the queue has exclusive access to
receive
Chapter 22 - SQL Server and ADO.NET: Notes messages from the MSMQ queue; otherwise, it's
on Performance
false.
Appendix A - Relational Databases: Some Basic Both get and set.
Concepts
Appendix B - Commonly Used SQL Statements
EnableConnectionCache When this property is true, a cache of connections will be
Appendix C - ADO.NET Frequently Asked Questions
maintained by the application; otherwise, they won't. Both
Index get and set.
List of Figures
EncryptionRequired If this property is true, the queue accepts only nonprivate
List of Tables
(nonencrypted) messages. Both get and set.
List of Listings
ListFormatName
of Sidebars This property represents the unique queue name
generated by MSMQ when queue was created. Read only.
Formatter This property represents the formatter used to serialize and
deserialize. Both get and set.
Id This property represents the unique queuing identifier.
Read only.
Label This property represents the queue description. Both get
and set.
LastModifyTime This property represents the last time the properties on a
queue were modified. Read only.
This property
MachineName Applied ADO.NET: Building represents
Data-Driven the name of the computer where
Solutions
queue is located.
by Mahesh Chand and David Talbot Both read and write.
ISBN:1590590732
Apress 2003 (928 pages) This property represents the maximum size of the journal
MaximumJournalSize
This text provides extensive coverage
queue. of ADO.NET
Both get and set. technology
including ADO.NET internals, namespaces, classes, and
interfaces, and takes a comprehensive
MaximumQueueSize look at XMLthe maximum size of the queue.
This property represents
namespaces and classes, andget
Both howand
to integrate
set. both with
ADO.NET.
MessageReadPropertyFilter This is the property filter for receiving or peeking messages.
Both get and set.
Table of Contents
This property represents the queue path. Both get and set.
PathADO.NETBuilding Data-Driven Solutions
Applied
Introduction
QueueName This property represents the queue's user-friendly name.
Chapter 1 - ADO.NET Basics
Both get and set.
Chapter 2 - Data Components in Visual Studio .NET
ReadHandle
Chapter This property represents the native handle used to read
3 - ADO.NET in Disconnected Environments
Chapter 4 messages from the queue. Read only.
- ADO.NET in Connected Environments
Chapter 5 - Handling ADO.NET Events
SynchronizingObject This property represents the object that marshals the event
Chapter 6 - Integrating XML with ADO.NET
handler calls resulting from a ReceiveCompletedor
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
PeekCompleted event. Both get and set.
Chapter 8 - Constraints and Data Relations
Transactional When this property is true, the queue accepts only
Chapter 9 - ADO.NET Exception Handling
transactions.
Chapter 10 - Working with the ODBC .NET Data Provider
11 - Stored Procedures and Views If this property is true, received messages are copied to
UseJournalQueue
Chapter
the journal
Chapter 12 - Oracle, SQLXML, and Other .NET queue. Both get and set.
Data Providers
Chapter 13 - Developing a Custom Data Provider
WriteHandle This property represents the native handle used to send
Chapter 14 - Developing Database Web Applications using ASP.NET
messages to the queue. Read only.
Chapter 15 - Using ADO.NET in Xml Web Services
Chapter 16 - ASP.NET Server Controls and Data Binding
Chapter 17 - Building Real-World Web Applications
Managing Queues Using VS .NET
Chapter 18 - Object-Relational Mapping in .NET
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
In Visual Studio .NET (VS .NET), the Server Explorer provides options to manage messaging queues in
Chapter 20 - COMserver.
the messaging Interoperability and all
You can see ADO.NET
available queues by expanding the
Chapter 21 - Messaging
Servers\MachineName\Message Queues node. The Message Queues node has three children-Private
Chapter
Queues,22Public
- SQL Queues,
Server and ADO.NET:
and System Notes on Performance
Queues-that list private, public, and system queues, respectively.
Appendix
You canAsee
- Relational Databases:available
the corresponding Some Basic Concepts
queues by expanding these nodes (see Figure 21-2).
Appendix B - Commonly Used SQL Statements
Appendix C - ADO.NET Frequently Asked Questions
Index
List of Figures
List of Tables
List of Listings
List of Sidebars
Applied ADO.NET: Building Data-Driven Solutions
by Mahesh Chand and David Talbot ISBN:1590590732
Apress 2003 (928 pages)
This text provides extensive coverage of ADO.NET technology
including ADO.NET internals, namespaces, classes, and
interfaces, and takes a comprehensive look at XML
namespaces and classes, and how to integrate both with
ADO.NET.
Table of Contents
Applied ADO.NETBuilding Data-Driven Solutions
Introduction
Chapter 1 - ADO.NET Basics
Chapter 2 - Data Components in Visual Studio .NET
Chapter 3 - ADO.NET in Disconnected Environments
Chapter 4 - ADO.NET in Connected Environments
Chapter 5 - Handling ADO.NET Events
Chapter 6 - Integrating XML with ADO.NET
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
Chapter 8 - Constraints and Data Relations
Chapter 9 - ADO.NET Exception Handling
Chapter 10 - Working with the ODBC .NET Data Provider
Chapter 11 - Stored Procedures and Views
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Chapter 13 - Developing a Custom Data Provider
Chapter 14 - Developing Database Web Applications using ASP.NET
Chapter 15 - Using ADO.NET in Xml Web Services
Chapter 16 - ASP.NET Server Controls and Data Binding
Figure 21-2: Managing message queues through the Server Explorer
Chapter 17 - Building Real-World Web Applications
Chapter 18 - Object-Relational Mapping in .NET
The Server Explorer also allows you to create and delete queues. To create a queue, right-click the
Chapter
Private19 - Mapped
Queues Objects:
or Public Performance
Queues Considerations
node and and Data
select the Create Binding
Queue option.
Chapter 20 - COM Interoperability and ADO.NET
Note
Chapter 21 You may not be able to view or create public queues if you're a member of a proper domain or
- Messaging
Chapter 22 working on a and
- SQL Server WORKGROUP computer.
ADO.NET: Notes on Performance
Appendix A - Relational Databases: Some Basic Concepts
Now if you expand an available queue, you'll see children: Journal Messages and Queue Messages. You
Appendix B - Commonly Used SQL Statements
can also delete messages from a queue by simply right-clicking and selecting the Clear Messages menu
Appendix C - ADO.NET Frequently Asked Questions
option.
Index
List ofTip
Figures
After creating a message queue using the Server Explorer, you can easily add it to your
application by simply dragging the queue from the Server Explorer to a form. This action adds an
List of Tables
object of type MessageQueue to your project.
List of Listings
List of Sidebars
UsingMessageQueueCriteria, you can simply filter the queues. The following code filters queues
based on a machine name and label:
Table of Contents
Applied ADO.NETBuilding Data-Driven Solutions
Introduction
Chapter 1 - ADO.NET Basics
Chapter 2 - Data Components in Visual Studio .NET
Chapter 3 - ADO.NET in Disconnected Environments
Chapter 4 - ADO.NET in Connected Environments
Chapter 5 - Handling ADO.NET Events
Chapter 6 - Integrating XML with ADO.NET
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
Chapter 8 - Constraints and Data Relations
Chapter 9 - ADO.NET Exception Handling
Chapter 10 - 21-3:
Figure Working with theQueue
Message ODBC .NET Data form
Manager Provider
Chapter 11 - Stored Procedures and Views
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
The Create Queue button reads the name from New Queue Name text box and creates a new queue on
Chapter 13 - Developing a Custom Data Provider
the server. Listing 21-4 shows a Create Queue button event handler, which reads the queue name from a
Chapter 14 - Developing Database Web Applications using ASP.NET
text box and creates a private queue. It also sets the priority of the queue based on the user's option
Chapter 15on
selected - Using ADO.NET
the form. in Xml Web Services
The Transactional check box is responsible for creating a transactional queue.
Chapter 16 - ASP.NET Server Controls and Data Binding
Listing17
Chapter 21-4: Creating
- Building a Queue
Real-World Web Applications
Chapter 18 - Object-Relational Mapping in .NET
Chapter
Private19 -Sub
Mapped Objects: Performance Considerations
CreateQueueBtn_Click(ByVal and DataAs
sender Binding
System.Object, _
Chapter
ByVal20 -eCOM
As Interoperability and ADO.NET
System.EventArgs) Handles CreateQueueBtn.Click
ChapterDim
21 -str
Messaging
As String = String.Empty
ChapterDim
22 -trn
SQL Server and ADO.NET:
As Boolean Notes on Performance
= False
Appendix
' AIf- Relational Databases:type
transactional Some is
Basic Concepts
true
IfB CheckBox1.Checked
Appendix Then
- Commonly Used SQL Statements
trn
Appendix C = TrueFrequently Asked Questions
- ADO.NET
Index End If
' If queue is private
List of Figures
If RadioButton1.Checked Then
List of Tables
str = ".\Private$\"
List of Listings
End If
List of Sidebars
str += TextBox1.Text
If Not MessageQueue.Exists(str) Then
currentQueue = MessageQueue.Create(str, trn)
If currentQueue Is Nothing Then
' Set priority
If RadioButton4.Checked Then
currentQueue.BasePriority = _
Convert.ToInt16(MessagePriority.High)
ElseIf RadioButton5.Checked Then
currentQueue.BasePriority = _
Convert.ToInt16(MessagePriority.Low)
Else
currentQueue.BasePriority = 0
Applied ADO.NET: Building Data-Driven Solutions
End If
by Mahesh Chand and David Talbot
ListBox1.Items.Add(TextBox1.Text) ISBN:1590590732
Apress 2003
ListBox1.Update() (928 pages)
End If This text provides extensive coverage of ADO.NET technology
End If including ADO.NET internals, namespaces, classes, and
interfaces, and takes a comprehensive look at XML
End Sub namespaces and classes, and how to integrate both with
ADO.NET.
Table
The of Contents
Delete Queue button deletes the queue from the server (see Listing 21-5).
Applied ADO.NETBuilding Data-Driven Solutions
Listing 21-5: Deleting a Queue
Introduction
Chapter 1 - ADO.NET Basics
Chapter
Private2 -Sub
Data DeleteQueBtn_Click(ByVal
Components in Visual Studio .NET sender As System.Object, _
Chapter
ByVal3 -eADO.NET in Disconnected Environments
As System.EventArgs) Handles DeleteQueBtn.Click
ChapterDim
4 -str
ADO.NET in Connected
As String Environments
= String.Empty
Chapter'5 If- Handling
queue is private
ADO.NET Events
ChapterIf
6 RadioButton1.Checked Then
- Integrating XML with ADO.NET
Chapter 7 str = ".\Private$\"
- Data Binding and Windows Forms Data-Bound Controls
ChapterEnd
8 -If
Constraints and Data Relations
Chapterstr
9 -+= TextBox2.Text
ADO.NET Exception Handling
' Create and connect to a public Message Queuing queue.
Chapter 10 - Working with the ODBC .NET Data Provider
If MessageQueue.Exists(str) Then
Chapter 11 - Stored Procedures and Views
MessageQueue.Delete(str)
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
End If
Chapter 13 - Developing a Custom Data Provider
End Sub
Chapter 14 - Developing Database Web Applications using ASP.NET
Chapter 15 - Using ADO.NET in Xml Web Services
Chapter 16 - ASP.NET Server Controls and Data Binding
Chapter 17 - Building
The Queue Real-World
Properties Web Applications
button simply returns the current queue properties (see Listing 21-6).
Chapter 18 - Object-Relational Mapping in .NET
Listing19
Chapter 21-6: Getting
- Mapped a Queue's
Objects: Properties
Performance Considerations and Data Binding
Chapter 20 - COM Interoperability and ADO.NET
Chapter
Private21 -Sub
Messaging
QuePropsBtn_Click(ByVal sender As System.Object, _
Chapter
ByVal22 -eSQL
AsServer and ADO.NET: NotesHandles
System.EventArgs) on Performance
QuePropsBtn.Click
Dim
Appendix A -props AsDatabases:
Relational String Some
= "Format Name: " + currentQueue.FormatName
Basic Concepts
props
Appendix += ", Base
B - Commonly Priority:"
Used SQL Statements + currentQueue.BasePriority.ToString()
props
Appendix += ", Frequently
C - ADO.NET Create Time:" + currentQueue.CreateTime.ToString()
Asked Questions
Index props += ", ID:" + currentQueue.Id.ToString()
props += ", Path:" + currentQueue.Path.ToString()
List of Figures
props += ", Max Size:" + currentQueue.MaximumQueueSize.ToString()
List of Tables
props += ", Transaction:" + currentQueue.Transactional.ToString()
List of Listings
MessageBox.Show(props)
List of Sidebars
End Sub
But most of the time you'll be creating a MessageQueue instance programmatically. For that, you create a
MessageQueue object and set its path. For example, the following code creates a MessageQueue
instance programmatically:
Applied ADO.NET: Building Data-Driven Solutions
Dim mq = new MessageQueue()
by Mahesh Chand and David Talbot ISBN:1590590732
mq.Path = ".\mcbQueue"
Apress 2003 (928 pages)
This text provides extensive coverage of ADO.NET technology
Alternatively, youincluding
can alsoADO.NET
pass the internals, namespaces,
path in the classes,constructor
MessageQueue and as follows:
interfaces, and takes a comprehensive look at XML
namespaces and classes, and how to integrate both with
Dim mq = new ADO.NET.
MessageQueue(".\mcbQueue")
Table of Contents
Setting a Queue's Path
Applied ADO.NETBuilding Data-Driven Solutions
Introduction
You can create a MessageQueue instance from a path, from a format name, or from a label. Each of
Chapter 1 - ADO.NET Basics
these methods has their advantages. For example, in XML Web services, the format name method gives
Chapter 2 - Data Components in Visual Studio .NET
you better performance than the path method. When a queue is disconnected, the path method won't
Chapter 3 - ADO.NET in Disconnected Environments
work. You have to use the format method.
Chapter 4 - ADO.NET in Connected Environments
Chapter 5 of
The path - Handling ADO.NET
queue takes Events
the form servername\queuename. Each type of queue has a unique path.
Chapter 6 the
Actually, - Integrating
path is theXML with ADO.NET
combination of machine name and queue name of a queue. You can use the
Chapter 7 - Dataand
MachineName QueueName
Binding properties
and Windows Forms of Controlsand combine them to get the path of a
MessageQueue
Data-Bound
queue.8
Chapter - Constraints and Data Relations
Chapter 9 - ADO.NET Exception Handling
Table 21-3 describes the paths for different types of queues.
Chapter 10 - Working with the ODBC .NET Data Provider
Chapter 11 - Stored Procedures and Views
Table 21-3: Path for Different Types of Queues
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Chapter
QUEUE 13 TYPE
- Developing a Custom Data Provider PATH
Chapter 14 - Developing Database Web Applications using ASP.NET
Public queue MachineName\QueueName
Chapter 15 - Using ADO.NET in Xml Web Services
Chapter 16queue
Private - ASP.NET Server Controls and Data Binding MachineName\Private$\QueueName
Chapter 17 - Building Real-World Web Applications
Journal queue MachineName\QueueName\Journal$
Chapter 18 - Object-Relational Mapping in .NET
Machine
Chapter 19 -journal
Mappedqueue MachineName\Journal$
Objects: Performance Considerations and Data Binding
Chapter 20 - COM Interoperability and ADO.NET
Machine dead-letter queue MachineName\Deadletter$
Chapter 21 - Messaging
Machine
Chapter 22 -transactional dead-letter
SQL Server and ADO.NET: queue
Notes on PerformanceMachineName\XactDeadletter$
Appendix A - Relational Databases: Some Basic Concepts
Appendix B - Commonly Used SQL Statements
Tip The dot (.) represents the current machine in a path. For example,
Appendix C - ADO.NET Frequently Asked Questions
MessageQueue1.Path=".\mcbQueue" represents the mcbQueue queue on the current
Index
machine.
List of Figures
List
The of following
Tables code uses the path of the queue:
List of Listings
List of Sidebars
MessageQueue1.Path=".\mcbQueue"
You can use format names to indicate whether a queue is public or private. The
FORMATNAME:PUBLIC=QueueGUID,FORMATNAME:PRIVATE=MachineGUID\QueueNumber, and
FORMATNAME:PUBLIC=QueueGUID;JOURNAL names represent public, private, and journal queues,
respectively.
The following code sets the path of the queue as a public queue using format names:
MessageQueue1.Path = "FORMATNAME:PUBLIC=queueGUID"
You can also use a label name to refer to a queue. The Label property of MessageQueue represents
Applied ADO.NET: Building Data-Driven Solutions
the label of a queue:
by Mahesh Chand and David Talbot ISBN:1590590732
Apress 2003 (928 pages)
MessageQueue1.Path="LABEL:mcbQueue"
This text provides extensive coverage of ADO.NET technology
including ADO.NET internals, namespaces, classes, and
interfaces, and takes a comprehensive look at XML
namespaces and classes, and how to integrate both with
Sending and Receiving Messages
ADO.NET.
TheSend method of MessageQueue is responsible for sending a message to the queue. Using these
forms,
Table you can even specify the type of MSMQ transaction. The Send message takes the first argument of
of Contents
type Object, which can be
Applied ADO.NETBuilding a Message
Data-Driven object, a text string, or any other message. The Send method
Solutions
has six overloaded forms:
Introduction
Chapter 1 - ADO.NET Basics
Overloads
Chapter Public
2 - Data Sub Send(Object)
Components in Visual Studio .NET
Overloads Public Sub Send(Object,
Chapter 3 - ADO.NET in Disconnected _
Environments
MessageQueueTransaction)
Chapter 4 - ADO.NET in Connected Environments
Overloads
Chapter Public
5 - Handling Sub Send(Object,
ADO.NET Events _
MessageQueueTransactionType)
Chapter 6 - Integrating XML with ADO.NET
Overloads Public Sub Send(Object, String)
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
Overloads Public Sub Send(Object, String, _
Chapter 8 - Constraints and Data Relations
MessageQueueTransaction)
Chapter 9 - ADO.NET Exception Handling
Overloads Public Sub Send(Object, String, _
Chapter 10 - Working with the ODBC .NET Data Provider
MessageQueueTransactionType)
Chapter 11 - Stored Procedures and Views
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Chapter 13 - Developing a Custom Data Provider
TheReceive
Chapter method receives
14 - Developing Databasethe
Webfirst message using
Applications in theASP.NET
queue and removes it from the queue. If there's
no message
Chapter available
15 - Using in theinqueue,
ADO.NET you
Xml Web can even specify a time span, and the method will wait for that
Services
interval16
Chapter or -until the next
ASP.NET message
Server is available
Controls in the queue. The Receive method has six overloaded
and Data Binding
forms: 17 - Building Real-World Web Applications
Chapter
Chapter 18 - Object-Relational Mapping in .NET
Public
Chapter 19 Overloads Function
- Mapped Objects: Receive()
Performance As Message
Considerations and Data Binding
Overloads
Chapter Public
20 - COM Function
Interoperability and Receive
ADO.NET _
(MessageQueueTransaction)
Chapter 21 - Messaging As Message
Overloads
Chapter Public
22 - SQL Function
Server and ADO.NET:Receive _
Notes on Performance
(MessageQueueTransactionType)
Appendix As Concepts
A - Relational Databases: Some Basic Message
Overloads Public Function Receive(TimeSpan) As Message
Appendix B - Commonly Used SQL Statements
Overloads Public Function Receive(TimeSpan, _
Appendix C - ADO.NET Frequently Asked Questions
MessageQueueTransaction) As Message
Index
Overloads
List of Figures
Public Function Receive(TimeSpan, _
List of Tables
MessageQueueTransactionType) As Message
List of Listings
List of Sidebars
Both the Send and Receive methods take an argument of type MessageQueueTransactionType
enumeration, which specify the type of transaction. It can be Automatic,None, or Single. The None
type transaction represents that the operation will not be transactional. The Single option is for single
internal transactions, and the Automatic type is used for Microsoft Transaction Server (MTS) or COM+
1.0 services.
Table of Contents
Applied ADO.NETBuilding Data-Driven Solutions
Introduction
Chapter 1 - ADO.NET Basics
Chapter 2 - Data Components in Visual Studio .NET
Chapter 3 - ADO.NET in Disconnected Environments
Chapter 4 - ADO.NET in Connected Environments
Chapter 5 - Handling ADO.NET Events
Chapter 6 - Integrating XML with ADO.NET
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
Chapter 8 - Constraints and Data Relations
Chapter 9 - ADO.NET Exception Handling
Chapter 10 - Working with the ODBC .NET Data Provider
Chapter 11 - Stored Procedures and Views
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Chapter 13 - Developing a Custom Data Provider
Chapter 14 - Developing Database Web Applications using ASP.NET
Chapter 15 - Using ADO.NET in Xml Web Services
Figure 21-4: A simple messaging application
Chapter 16 - ASP.NET Server Controls and Data Binding
Chapter 17 - Building Real-World Web Applications
After creating
Chapter a Windows application,
18 - Object-Relational open
Mapping in .NETthe Server Explorer and expand the Message Queues node.
Right-click
Chapter 19 -the Private
Mapped Queues
Objects: node and Considerations
Performance click the Createand
Queues menu item. Type mcbQ in the text box
Data Binding
and then
Chapter 20 click
- COMOK. Don't select the
Interoperability andTransactional
ADO.NET check box. To verify the action, you should now have a
mcbQ queue
Chapter listed under your Private Queues node.
21 - Messaging
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Now drag the mcbQ queue to the form. This action adds a reference to the System.Messaging
Appendix A - Relational
namespace and addsDatabases: Some
an object of typeBasic Concepts
MessageQueue called MessageQueue1.
Appendix B - Commonly Used SQL Statements
Finally, the
Appendix C - only thingFrequently
ADO.NET you need to do isQuestions
Asked add code to send and receive messages. Listing 21-7 shows the
code of the Send Message button click event handler. As you can see, the code simply reads the title and
Index
body
List text, creates a Message object, sets its Label and Body properties, and then calls the
of Figures
MessageQueue.Send
List of Tables method.
List of Listings
Listing 21-7: Sending Messages to a Queue
List of Sidebars
Table of Contents
Private Sub RecMsgBtn_Click(ByVal sender As System.Object, _
Applied ADO.NETBuilding
ByVal Data-Driven Solutions
e As System.EventArgs) Handles RecMsgBtn.Click
' Create a DataTable in memory
Introduction
ChapterDim
1 -dtTable As New DataTable()
ADO.NET Basics
ChapterdtTable.Columns.Add("Title")
2 - Data Components in Visual Studio .NET
ChapterdtTable.Columns.Add("Message Body")
3 - ADO.NET in Disconnected Environments
ChapterDim
4 -messages() As System.Messaging.Message
ADO.NET in Connected Environments
messages
Chapter 5
= MessageQueue1.GetAllMessages()
- Handling ADO.NET Events
' Need a formatter to get the text of the message body.
Chapter 6 - Integrating XML with ADO.NET
Dim stringFormatter As System.Messaging.XmlMessageFormatter = _
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
New System.Messaging.XmlMessageFormatter(New String() _
Chapter 8 - Constraints and Data Relations
{"System.String"})
Chapter 9 - ADO.NET Exception Handling
Dim index As Integer
ChapterDim
10 -msg
Working
As with the ODBC .NET Data Provider
System.Messaging.Message
Chapter 11 - Stored Procedures and Views
ChapterFor
12 -index
Oracle, SQLXML,
= 0 To and Other .NET Data Providers
messages.Length - 1
Chapter 13 - Developing a Custom Data Provider
messages(index).Formatter = stringFormatter
Chapter 14 - Developing
msg Database Web Applications using ASP.NET
= messages(index)
Chapter 15 - Using
Dim rowADO.NET in Xml Web
As DataRow Services
= dtTable.NewRow()
row(0)
Chapter 16 = Server
- ASP.NET msg.Label
Controls and Data Binding
row(1)
Chapter 17 = Real-World
- Building msg.Body.ToString()
Web Applications
dtTable.Rows.Add(row)
Chapter 18 - Object-Relational Mapping in .NET
ChapterNext
19 - Mapped Objects: Performance Considerations and Data Binding
ChapterDataGrid1.DataSource = ADO.NET
20 - COM Interoperability and dtTable
End Sub
Chapter 21 - Messaging
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Appendix A - Relational Databases: Some Basic Concepts
Appendix B - Commonly Used SQL Statements
Now, run the application, enter the title and body of the messages, and click Send Message to send
Appendix
messages C -to
ADO.NET Frequently
the queue. Asked Questions
When you're done sending messages, click the Receive Messages button to read
Index
all the messages from the queue (see Figure 21-5).
List of Figures
List of Tables
List of Listings
List of Sidebars
Applied ADO.NET: Building Data-Driven Solutions
by Mahesh Chand and David Talbot ISBN:1590590732
Apress 2003 (928 pages)
This text provides extensive coverage of ADO.NET technology
including ADO.NET internals, namespaces, classes, and
interfaces, and takes a comprehensive look at XML
namespaces and classes, and how to integrate both with
ADO.NET.
Table of Contents
Applied ADO.NETBuilding Data-Driven Solutions
Introduction
Chapter 1 - ADO.NET Basics
Chapter 2 - Data Components in Visual Studio .NET
Chapter 3 - ADO.NET in Disconnected Environments
Chapter 4 - ADO.NET in Connected Environments
Chapter 5 - Handling ADO.NET Events
Chapter 6 - Integrating XML with ADO.NET
Figure
Chapter 7 - 21-5: Messaging
Data Binding application
and Windows in action
Forms Data-Bound Controls
Chapter 8 - Constraints and Data Relations
Chapter 9 - ADO.NET Exception Handling
Chapter 10 - Working with the ODBC .NET Data Provider
Chapter 11 - Stored Procedures and Views
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Chapter 13 - Developing a Custom Data Provider
Chapter 14 - Developing Database Web Applications using ASP.NET
Chapter 15 - Using ADO.NET in Xml Web Services
Chapter 16 - ASP.NET Server Controls and Data Binding
Chapter 17 - Building Real-World Web Applications
Chapter 18 - Object-Relational Mapping in .NET
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
Chapter 20 - COM Interoperability and ADO.NET
Chapter 21 - Messaging
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Appendix A - Relational Databases: Some Basic Concepts
Appendix B - Commonly Used SQL Statements
Appendix C - ADO.NET Frequently Asked Questions
Index
List of Figures
List of Tables
List of Listings
List of Sidebars
Working with Messages
Applied ADO.NET: Building Data-Driven Solutions
by Mahesh Chand and David Talbot ISBN:1590590732
TheMessage class represents
Apress a message
2003 (928 pages) in MSMQ. The Message class provides one static method
calledInfiniteTimeout that specifies that no timeout
This text provides extensive coverage exists. This
of ADO.NET class provides more than 40
technology
properties and someincluding ADO.NET internals, namespaces, classes, and ID, and priority of the message.
of them represent the body text, format, security,
interfaces,
You'll see this class's and takes
properties in theasample
comprehensive look at
applications XML
throughout this chapter.
namespaces and classes, and how to integrate both with
ADO.NET.
Creating and Removing Messages
Table
You of
canContents
use the Message class to create a message. Once you have created a message, you can use it
as an argument
Applied of the Send
ADO.NETBuilding and Receive
Data-Driven methods of MessageQueue to send and receive messages.
Solutions
The following code creates a message and sets its priority, body, and label:
Introduction
Chapter 1 - ADO.NET Basics
Chapter 2 - Data
Dim msg1 Components
As Message = inNew
Visual Studio .NET
Message()
Chapter 3 - ADO.NET
msg1.Priority = inMessagePriority.High
Disconnected Environments
Chapter 4 - ADO.NET
msg1.Body in Connected
= "Body of first Environments
message"
msg1.Label
Chapter = "First
5 - Handling Message"
ADO.NET Events
Chapter 6 - Integrating XML with ADO.NET
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
ThePurge method of MessageQueue removes all the messages from a queue. The following code
Chapter 8 - Constraints and Data Relations
removes messages from MessageQueue1:
Chapter 9 - ADO.NET Exception Handling
Chapter 10 - Working with the ODBC .NET Data Provider
MessageQueue1.Purge()
Chapter 11 - Stored Procedures and Views
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Chapter
You can13remove
- Developing a Custom
a single Data
message Provider
from the queue by calling the Receivemethod of MessageQueue.
Chapter
You can14also
- Developing Database Web Applications
use the ReceiveById using ASP.NET
method to remove a message identified by the ID. You can also call
Chapter 15 - Using
thePeekById ADO.NET
method in Xml
to find Web Services
a specific message and then use the RecieveById method to remove it.
Chapter 16 - ASP.NET Server Controls and Data Binding
Tip17
Chapter You can always
- Building remove
Real-World messages
Web manually from the Server Explorer by selecting the Queue
Applications
Messages
Chapter 18 Clear Messages
- Object-Relational menu
Mapping in .NET option. There's no way you can remove a single message
from
Chapter 19 a queue
- Mapped manually.
Objects: Performance Considerations and Data Binding
Chapter 20 - COM Interoperability and ADO.NET
Setting Queue and Message Priorities
Chapter 21 - Messaging
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
You can set both a queue's and a message's priority. Both MessageQueue and Message classes provide
Appendix A - Relational Databases: Some Basic Concepts
properties to set their priorities. You can use the BasePriority property of MesssageQueue to get and
Appendix B - Commonly Used SQL Statements
set a priority of a queue. It's only applied on public queues. The BasePriority of a private queue is
Appendix C - ADO.NET Frequently Asked Questions
always 0.
Index
List
You of can
Figures
use the Priority property of the Message class to get and set the priority of a message. The
List of Tables
MessagePriority enumeration specifies the value of the Priority property. Table 21-4 describes the
List of Listings
MessagePriority enumeration members.
List of Sidebars
Table 21-4: The MessagePriority Enumeration Members
PROPERTY DESCRIPTION
Applied ADO.NET: Building Data-Driven Solutions
by Mahesh Chand and David Talbot ISBN:1590590732
Lowest Lowest priority
Apress 2003 (928 pages)
VeryLow ThisBetween Low and
text provides Lowest
extensive message
coverage priority technology
of ADO.NET
including ADO.NET internals, namespaces, classes, and
Low Low priority
interfaces, and takes a comprehensive look at XML
namespaces and classes, and how to integrate both with
Normal Normal priority
ADO.NET.
Creating a transactional message queue programmatically is pretty simple. When you use the Create
method of MessageQueue, you pass the second argument as true to create a transactional message
queue. For example, the following code creates a transactional queue:
Applied ADO.NET: Building Data-Driven Solutions
by Mahesh Chand and David Talbot ISBN:1590590732
Dim mq as New MessageQueue
Apress 2003 (928 pages)
mq =MessageQueue.Create(".\mcbTransQueue", True)
This text provides extensive coverage of ADO.NET technology
including ADO.NET internals, namespaces, classes, and
interfaces, and takes a comprehensive look at XML
namespaces and classes, and how to integrate both with
Sending and Receiving Transactional Messages
ADO.NET.
When creating a transactional queue, the Send and Receive methods of MessageQueue take the last
argument
Table as the transaction object. Listing 21-9 shows how to send and receive transactional messages.
of Contents
As you can see from this Data-Driven
Applied ADO.NETBuilding code, the transaction
Solutions is only committed where there were no errors; otherwise,
the transaction
Introduction is aborted.
Chapter 1 - ADO.NET Basics
Listing 21-9: Sending and Receiving Transactional Messages
Chapter 2 - Data Components in Visual Studio .NET
Chapter 3 - ADO.NET in Disconnected Environments
Imports
Chapter 4 -System
ADO.NET in Connected Environments
Imports -System.Messaging
Chapter 5 Handling ADO.NET Events
Chapter 6 - Integrating XML with ADO.NET
Module Module1
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
Chapter 8 - Constraints and Data Relations
Sub Main()
Chapter 9 - ADO.NET Exception Handling
'SendTransactionalMessages()
ChapterRecieveTransactionalMessages()
10 - Working with the ODBC .NET Data Provider
Chapter
End11Sub- Stored Procedures and Views
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Chapter 13 - Developing
Public a Custom Data Provider
Sub SendTransactionalMessages()
ChapterDim
14 -mq
Developing Database Web Applications
As MessageQueue using ASP.NET
= New MessageQueue()
Chaptermq
15 =- Using ADO.NET in Xml Web Services
MessageQueue.Create(".\Private$\mcbTQ", True)
ChapterDim
16 -tran AsServer
ASP.NET MessageQueueTransaction
Controls and Data Binding = _
ChapterNew
17 -MessageQueueTransaction()
Building Real-World Web Applications
ChapterTry
18 - Object-Relational Mapping in .NET
tran.Begin()
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
mq.Send("Body
Chapter 20 of first
- COM Interoperability message", "Message1", tran)
and ADO.NET
mq.Send("Body of second message", "Message2", tran)
Chapter 21 - Messaging
mq.Send("Body of third message", "Message3", tran)
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
tran.Commit()
Appendix A - Relational Databases: Some Basic Concepts
Console.WriteLine("Transaction committed!")
Appendix B - Commonly Used SQL Statements
Catch
Appendix C - ADO.NET Frequently Asked Questions
tran.Abort()
Index Console.WriteLine("Transaction Aborted!")
List of Figures
End Try
List of
EndTables
Sub
List of Listings
List of SidebarsSub RecieveTransactionalMessages()
Public
Dim mq As MessageQueue = New MessageQueue()
mq.Path = ".\Private$\mcbTQ"
Dim tran As MessageQueueTransaction = _
New MessageQueueTransaction()
Try
tran.Begin()
Dim messages() As System.Messaging.Message
messages = mq.GetAllMessages()
' Need a formatter to get the text of the message body.
Dim stringFormatter As System.Messaging.XmlMessageFormatter = _
New System.Messaging.XmlMessageFormatter(New String() _
{"System.String"})
Applied
Dim index As ADO.NET:
Integer Building Data-Driven Solutions
by Mahesh Chand and David Talbot
Dim msg As System.Messaging.Message ISBN:1590590732
Apress 2003 (928 pages)
For indexThis text
= 0provides extensive coverage of
To messages.Length - ADO.NET
1 technology
including ADO.NET internals, namespaces,
messages(index).Formatter = stringFormatter classes, and
interfaces, and takes a comprehensive look at XML
msg =namespaces
messages(index)
and classes, and how to integrate both with
Console.WriteLine(msg.Label
ADO.NET. + "," + msg.Body)
Next
tran.Commit()
Table of Contents
Console.WriteLine("Transaction committed!")
AppliedCatch
ADO.NETBuilding Data-Driven Solutions
Introduction
tran.Abort()
Chapter 1 Console.WriteLine("Transaction
- ADO.NET Basics Aborted!")
ChapterEnd
2 -TryData Components in Visual Studio .NET
End3 Sub
Chapter - ADO.NET in Disconnected Environments
End Module
Chapter 4 - ADO.NET in Connected Environments
Chapter 5 - Handling ADO.NET Events
Chapter 6 - Integrating XML with ADO.NET
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
Tip Transactional processing is useful when you want to make sure that all messages in a transaction
Chapter 8 - Constraints and Data Relations
are delivered or none of them are.
Chapter 9 - ADO.NET Exception Handling
Chapter 10 - Working with the ODBC .NET Data Provider
Chapter 11 - Stored Procedures and Views
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Chapter 13 - Developing a Custom Data Provider
Chapter 14 - Developing Database Web Applications using ASP.NET
Chapter 15 - Using ADO.NET in Xml Web Services
Chapter 16 - ASP.NET Server Controls and Data Binding
Chapter 17 - Building Real-World Web Applications
Chapter 18 - Object-Relational Mapping in .NET
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
Chapter 20 - COM Interoperability and ADO.NET
Chapter 21 - Messaging
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Appendix A - Relational Databases: Some Basic Concepts
Appendix B - Commonly Used SQL Statements
Appendix C - ADO.NET Frequently Asked Questions
Index
List of Figures
List of Tables
List of Listings
List of Sidebars
EncryptingApplied
Messages
ADO.NET: Building Data-Driven Solutions
by Mahesh Chand and David Talbot ISBN:1590590732
There are certainApress
requirements when
2003 (928 pages)you need to send encrypted messages to make sure the data you're
sending is secure.
This text provides extensiveincoverage
You can use encryption two ways.of First,
ADO.NET you technology
can encrypt a message itself. Second,
you can use queuing services to encrypt a message through the
including ADO.NET internals, namespaces, classes, and MessageQueue class.
interfaces, and takes a comprehensive look at XML
To encrypt a message, you can
namespaces anduse the DestinationSymmetricKey
classes, and how to integrate both with property of a message and then
ADO.NET.
send this message to the queue. The DestinationSymmetricKeyproperty represents the symmetric
key used to encrypt application-encrypted messages.
Table of Contents
TheEncryptionRequired property of MessageQueue sets whether a queue accepts nonencrypted or
Applied ADO.NETBuilding
encrypted messages. TheData-Driven Solutions
EncryptionRequired enumeration provides the value of the
Introduction
EncryptionRequired property, which has three values: Body,None, and Optional. The Body option
Chapter
makes 1sure- ADO.NET Basics
the queue only accepts private (encrypted) messages. The None option means the queue
Chapter
accepts2 only
- Data Components
nonencrypted in Visual Studio
messages. .NET
The Optional option means the queue accepts both encrypted
Chapter 3 - ADO.NET
and nonencrypted in Disconnected Environments
messages.
Chapter 4 - ADO.NET in Connected Environments
TheEncryptionAlgorithm
Chapter 5
property of the Message class represents the type of encryption applied
- Handling ADO.NET Events
on a message. This property is represented by the EncryptionAlgorithm enumeration, which has
Chapter 6 - Integrating XML with ADO.NET
three values: None,RC2, and RC4. The value None means no encryption. RC2 is a 64-bit block encryption,
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
andRC4 is the stream encryption. The block mode encrypts a block of data at a time, and the stream
Chapter 8 - Constraints and Data Relations
mode encrypts a bit at a time.
Chapter 9 - ADO.NET Exception Handling
Chapter
Listing 10 - Working
21-10 sends with the ODBC
encrypted .NET Data
messages. AsProvider
you can see, it sets the UseEncryption property of a
Chapter
Message 11 -object
StoredtoProcedures
activate theand
encryption.
Views
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Listing13
Chapter 21-10: Sending
- Developing a Encrypted
Custom DataMessages
Provider
Chapter 14 - Developing Database Web Applications using ASP.NET
Chapter
Try 15 - Using ADO.NET in Xml Web Services
Dim
Chapter 16 msg As
- ASP.NET System.Messaging.Message
Server Controls and Data Binding = _
Chapter 17 -New System.Messaging.Message(titleTextBox.Text)
Building Real-World Web Applications
MessageQueue1.EncryptionRequired
Chapter 18 - Object-Relational Mapping in .NET = _
Messaging.EncryptionRequired.Body
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
msg.UseEncryption
Chapter 20 = True
- COM Interoperability and ADO.NET
If (rc4RadioBtn.Checked) Then
Chapter 21 - Messaging
msg.EncryptionAlgorithm = Messaging.EncryptionAlgorithm.Rc4
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
ElseIf (rc2RadioBtn.Checked) Then
Appendix A - Relational Databases: Some Basic Concepts
msg.EncryptionAlgorithm = Messaging.EncryptionAlgorithm.Rc2
Appendix B - Commonly Used SQL Statements
Else
Appendix C - ADO.NET Frequently Asked Questions
msg.EncryptionAlgorithm = Messaging.EncryptionAlgorithm.None
Index End If
List of Figures
List of Tables
msg.Label = titleTextBox.Text
List of Listings
msg.Body = bodyTextBox.Text
List of Sidebars
MessageQueue1.Send(msg)
Catch exp As Exception
MessageBox.Show(exp.Message)
End Try
Summary Applied ADO.NET: Building Data-Driven Solutions
by Mahesh Chand and David Talbot ISBN:1590590732
In this chapter, we covered
Apress some
2003 basic programming of messaging services. The System.Messaging
(928 pages)
namespace offers much more than we're able
This text provides extensive to discuss
coverage in this chapter.
of ADO.NET Still, this chapter should give you
technology
a quick jump startincluding
on MSMQ using .NET.
ADO.NET internals, namespaces, classes, and
interfaces, and takes a comprehensive look at XML
We also discussed namespaces and
the classes classes,by
provided and how
the to integrate
.NET FrameworkbothLibrary
with to work with messaging services.
ADO.NET.
We discussed how to create, delete, and manage queues. Additionally, we discussed how to send and
receive normal messages and transaction messages. Finally, we discussed the security, encryption, and
authentication issues involved in messaging and the classes provided by the .NET Framework Library to
Table of Contents
implement messaging.
Applied ADO.NETBuilding Data-Driven Solutions
Introduction
In the next chapter, we cover performance and optimization issues and how to handle these issues when
Chapter
working1 with
- ADO.NET
ADO.NET Basics
and SQL Server.
Chapter 2 - Data Components in Visual Studio .NET
Chapter 3 - ADO.NET in Disconnected Environments
Chapter 4 - ADO.NET in Connected Environments
Chapter 5 - Handling ADO.NET Events
Chapter 6 - Integrating XML with ADO.NET
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
Chapter 8 - Constraints and Data Relations
Chapter 9 - ADO.NET Exception Handling
Chapter 10 - Working with the ODBC .NET Data Provider
Chapter 11 - Stored Procedures and Views
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Chapter 13 - Developing a Custom Data Provider
Chapter 14 - Developing Database Web Applications using ASP.NET
Chapter 15 - Using ADO.NET in Xml Web Services
Chapter 16 - ASP.NET Server Controls and Data Binding
Chapter 17 - Building Real-World Web Applications
Chapter 18 - Object-Relational Mapping in .NET
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
Chapter 20 - COM Interoperability and ADO.NET
Chapter 21 - Messaging
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Appendix A - Relational Databases: Some Basic Concepts
Appendix B - Commonly Used SQL Statements
Appendix C - ADO.NET Frequently Asked Questions
Index
List of Figures
List of Tables
List of Listings
List of Sidebars
Chapter Applied
22: SQL Server and ADO.NET:
ADO.NET: Building Data-Driven Solutions
by Mahesh Chand and David Talbot ISBN:1590590732
Notes on
Performance
Apress 2003 (928 pages)
This text provides extensive coverage of ADO.NET technology
including
Ever since the early days ofADO.NET internals,
relational namespaces,
databases, classes,
optimizing and performance has always been as
database
interfaces, and takes a comprehensive look at XML
much an art as anamespaces
science. Even today, you'll often hear of new "secrets"
and classes, and how to integrate both with
through professional relationships
that take on the air of furtive
ADO.NET. backalley exchanges more reminiscent of a Le Carr novel than a sober
discussion between colleagues. This chapter discusses some SQL Server and ADO.NET performance
issues. It also discusses some best practices to make sure you get the most out of your code.
Table of Contents
Applied ADO.NETBuilding Data-Driven Solutions
Improving SQL Server Performance
Introduction
Chapter 1 - ADO.NET
The following Basics
sections provide some of the "back-alley" secrets we've accumulated over the years, as well
Chapter
as some2 of
- the
Datamore
Components in Visual
methodical Studio .NET
approaches for examining your database and determining the best course
Chapter 3 to- achieve
of action ADO.NETthe
in Disconnected Environments
best performance.
Chapter 4 - ADO.NET in Connected Environments
Chapter 5
- Handling ADO.NET Events
Using Indexes
Chapter 6 - Integrating XML with ADO.NET
Chapter 7 selecting
Properly - Data Binding and Windows
and managing yourForms Data-Bound
indexes can have Controls
the single biggest impact on performance using
any database-and
Chapter Microsoft
8 - Constraints SQLRelations
and Data Server is no different. Indexes are like little optimized tables that organize
the data
Chapter 9 you'll most commonly
- ADO.NET use so that you can find rows in the main table optimally.
Exception Handling
Chapter 10 - Working with the ODBC .NET Data Provider
To manage the indexes on a table, simply right-click the table in Enterprise Manager, choose All Tasks
Chapter 11 - Stored Procedures and Views
from the menu that pops up, and then select Manage Indexes (see Figure 22-1).
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Chapter 13 - Developing a Custom Data Provider
Chapter 14 - Developing Database Web Applications using ASP.NET
Chapter 15 - Using ADO.NET in Xml Web Services
Chapter 16 - ASP.NET Server Controls and Data Binding
Chapter 17 - Building Real-World Web Applications
Chapter 18 - Object-Relational Mapping in .NET
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
Chapter 20 - COM Interoperability and ADO.NET
Chapter 21 - Messaging
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Appendix A - Relational Databases: Some Basic Concepts
Appendix B - Commonly Used SQL Statements
Figure 22-1: The Manage Indexes menu in Enterprise Manager
Appendix C - ADO.NET Frequently Asked Questions
Index
From
List the dialog box that appears, you can manage any of the tables in any of the databases running in the
of Figures
current
List instance of Microsoft SQL Server (see Figure 22-2). You can change databases by choosing a
of Tables
different database from the Database drop-down list, or you can change the table you're managing your
List of Listings
indexes on by choosing another table from the Table drop-down list.
List of Sidebars
Applied ADO.NET: Building Data-Driven Solutions
by Mahesh Chand and David Talbot ISBN:1590590732
Apress 2003 (928 pages)
This text provides extensive coverage of ADO.NET technology
including ADO.NET internals, namespaces, classes, and
interfaces, and takes a comprehensive look at XML
namespaces and classes, and how to integrate both with
ADO.NET.
Table of Contents
Applied ADO.NETBuilding Data-Driven Solutions
Introduction
Chapter 1 - ADO.NET Basics
Chapter 2 - Data Components in Visual Studio .NET
Chapter 3 - ADO.NET in Disconnected Environments
Chapter 4 - ADO.NET in Connected Environments
Chapter 5 - Handling ADO.NET Events
Figure
Chapter 6 - 22-2: The Manage
Integrating XML withIndexes
ADO.NETdialog box
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
Once you have the database and table selected that you would like to manage the index on, the current
Chapter 8 - Constraints and Data Relations
indexes that exist on the table display in the Existing Indexes area.
Chapter 9 - ADO.NET Exception Handling
Chapter
To add10 - Working
a new index with
to thethe ODBC
table, .NET
click theData
NewProvider
button at the bottom of this dialog box. This opens the Create
Chapter 11 - Stored Procedures and Views
New Index dialog box (see Figure 22-3). Having a good understanding of this dialog box and its implications
Chapter 12to- Oracle,
is critical creatingSQLXML, and Other application.
a top-performing .NET Data Providers
Determining which columns you should index in different
Chapter
contexts 13will
- Developing
be covereda later
Custom Data
in this Providerso for now you'll focus on the options for determining the
chapter,
behavior
Chapter 14of
- the index you'd
Developing like toWeb
Database create.
Applications using ASP.NET
Chapter 15 - Using ADO.NET in Xml Web Services
Chapter 16 - ASP.NET Server Controls and Data Binding
Chapter 17 - Building Real-World Web Applications
Chapter 18 - Object-Relational Mapping in .NET
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
Chapter 20 - COM Interoperability and ADO.NET
Chapter 21 - Messaging
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Appendix A - Relational Databases: Some Basic Concepts
Appendix B - Commonly Used SQL Statements
Appendix C - ADO.NET Frequently Asked Questions
Index
List of Figures
List of Tables
List of Listings
List of Sidebars
Checking the Unique Values box tells SQL Server that this index will be unique. If you're creating an index
on a single-column identity column or any other type of single column where you know the value will always
be unique, check this box. The index then knows that once it has found the item it's looking for, it shouldn't
look any further, which makes for a faster index.
The real value of this option comes into play when dealing with a multiple-column index that, when
Applied ADO.NET: Building Data-Driven Solutions
combined, produces a unique value. For example, a complicated join table may not have any single column
that represents aby Mahesh
unique Chand
value, butand David Talbotof two of theISBN:1590590732
a combination columns is unique.
Apress 2003 (928 pages)
The Pad Index and Filltext
This Factor options
provides are related.
extensive coverageWhen you buildtechnology
of ADO.NET an index, the index pages contain as
much data as possibleincludingby ADO.NET internals, ifnamespaces,
default. However, classes,add
you subsequently anddata to the table, then it takes a little
longer because new interfaces, and takes
index pages havea comprehensive
to be created fromlook scratch.
at XML Setting the Fill Factor option allows you
namespaces and classes, and how to integrate both with
to control how much spare space is left in each index page; a frequently updated table might have a Fill
ADO.NET.
Factor option as low as 20 or even 10 percent. An index with a lower Fill Factor takes up more space, but it
provides better performance. Note, though, that once the spare space is fully used, subsequent index
Table
pages of are
Contents
completely filled as if their Fill Factor was zero-regardless of what the setting was when the index
was created.
Applied At this point,Data-Driven
ADO.NETBuilding you shouldSolutions
recompile the index to recover the performance enhancement. At
installation, the default Fill Factor option for a server is set at 0, meaning each index page is completely
Introduction
filled, but
Chapter 1 you can alter
- ADO.NET this either through the SQL Server Enterprise Manager Server Properties dialog box
Basics
or by using the sp_configure
Chapter 2 - Data Components in Visual system stored
Studio .NETprocedure.
Chapter 3 - ADO.NET in Disconnected Environments
The Pad Index option performs a similar function and in fact uses the same percentage as the Fill Factor
Chapter 4 - ADO.NET in Connected Environments
option. SQL Server indexing uses an indexing method called b-trees, which means the index contains a
Chapter 5 - Handling ADO.NET Events
number of nodes where each node acts as a parent to two or more subnodes. The lowest pages of the
Chapter 6 - Integrating
index, beyond XMLare
which there with
noADO.NET
further nodes, are called leaf pages, and it is these that the Fill Factor
Chapter 7 - Data Binding and Windows
option affects. Padding the index allocatesFormsspare
Data-Bound Controls
space in the intermediate nodes, allowing for much
Chapter
greater8expansion
- Constraints
to theand Data data
table's Relations
than the Fill Factor option alone would support. Typically, however,
Chapter
setting 9the-Fill
ADO.NET
Factor Exception Handling
option provides enough optimization, and you should pad the index only in high-use
Chapter 10 - Working with the ODBC .NET Data Provider
scenarios.
Chapter 11 - Stored Procedures and Views
The Clustered
Chapter Index
12 - Oracle, option internally
SQLXML, and Othersorts
.NETthe data
Data in a way that is optimal for a number of queries,
Providers
especially those involving GROUP BY,ORDER BY,BETWEEN, or join clauses. A clustered index also
Chapter 13 - Developing a Custom Data Provider
provides a large boost for queries that involve aggregate functions such as MIN or MAX.
Chapter 14 - Developing Database Web Applications using ASP.NET
Chapter 15 -indexes
Clustered Using ADO.NET in on
don't help Xmlcolumns
Web Services
that contain data with little variability such as bit columns or
Chapter
columns that join to something finiteand
16 - ASP.NET Server Controls Data
such Bindingrepresenting states. Unless the country goes on a huge
as values
Chapter 17 - Building Real-World Web Applications
annexation binge, this number will remain relatively small compared to other things that are better
Chapter 18 - for
candidates Object-Relational
your clusteredMapping
index. in .NET
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
You can
Chapter 20have only
- COM one clusteredand
Interoperability index on any given table, so think about what you want to take advantage
ADO.NET
of the potential performance boost. This may sound trivial; however, if you closely examine a table, you'll
Chapter 21 - Messaging
see a number of options. You'll have to determine which ones your queries will use the most.
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Appendix
The Do A - Relational
Not Recompute Databases:
StatisticsSome Basic
option Concepts
comes with a warning that it is not recommended. In almost all
Appendix B - Commonly
circumstances, Used
heed this SQL Statements
warning or you could get some unexpected results. The only situation where you
Appendix C - this
should use ADO.NET
optionFrequently
is where aAsked
tableQuestions
is read only and will never be altered.
Index
List of Figures
Choosing Which Columns to Index
List of Tables
List of Listings
Knowing which columns to index is as important as knowing what options to use when indexing them. This
List
is aofgood
Sidebars
place to start: Any column you frequently query is probably a good candidate for an index.
The best candidates for indexes are usually the primary keys of your tables. The reason for this is when
you're doing a multiple table join, you'll usually do the join on your primary key. If most of your queries use a
particular column, then it's probably optimal to make that column a clustered index. It's never necessary to
create an index for your primary keys because of the nature of how SQL Server stores data relating to auto-
numbered primary keys.
SQL Server works well when storing data. Its overall goal is to make sure that when a row is inserted, it
can be placed physically between rows above and below your primary key in terms of sort order. By
ensuring that the rows are stored in the order of your primary key, primary key searches are very fast.
For tables where you're providing your own value for your primary key, you'll want to use table padding.
Applied ADO.NET: Building Data-Driven Solutions
by Mahesh
If your table uses Chand and David
an auto-numbered Talbot
primary key, your records will automatically be in the correct order
ISBN:1590590732
as you insert Apress
them because
2003 (928ofpages)
the auto numbering that SQL Server uses to store your data. In this
case, it's not This
beneficial to use table
text provides padding.
extensive coverage of ADO.NET technology
including ADO.NET internals, namespaces, classes, and
interfaces, and takes a comprehensive look at XML
namespaces and classes, and how to integrate both with
ADO.NET.
Also, when choosing what columns to index, remember that you only get one clustered index. The clustered
index groups and orders your index in a manner that it can quickly find what is being queried against.
Table of Contents
Also, don't waste your clustered index on a finite state column. This includes bits and numbers with little
Applied ADO.NETBuilding Data-Driven Solutions
variance (for example, an integer between 1 and 10). The clustered index shines on columns with broad
Introduction
variances in data, not in situations where most of the data in the column is the same from row to row.
Chapter 1 - ADO.NET Basics
Chapter 2 - Data Components in Visual Studio .NET
Understanding
Chapter 3
the SQL Server Profiler
- ADO.NET in Disconnected Environments
Chapter 4 - ADO.NET in Connected Environments
You can learn quite a few things about how to optimize your database by using the SQL Server Profiler. The
Chapter 5 - Handling
SQL Server ADO.NET
Profiler allows youEvents
to see what the database is doing, when it is doing it, and how long it takes.
Chapter 6 - Integrating XML with ADO.NET
You can
Chapter 7 launch
- Data the SQLand
Binding Server Profiler
Windows fromData-Bound
Forms the Microsoft SQL Server submenu in the Start menu or from
Controls
the Tools
Chapter 8 menu of Enterprise
- Constraints Manager.
and Data Once you've launched the SQL Server Profiler, you can start a new
Relations
trace by9 choosing
Chapter - ADO.NET NewTrace.
FileException This opens the Trace Properties dialog box (see Figure 22-4).
Handling
Chapter 10 - Working with the ODBC .NET Data Provider
Chapter 11 - Stored Procedures and Views
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Chapter 13 - Developing a Custom Data Provider
Chapter 14 - Developing Database Web Applications using ASP.NET
Chapter 15 - Using ADO.NET in Xml Web Services
Chapter 16 - ASP.NET Server Controls and Data Binding
Chapter 17 - Building Real-World Web Applications
Chapter 18 - Object-Relational Mapping in .NET
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
Chapter 20 - COM Interoperability and ADO.NET
Chapter 21 - Messaging
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Appendix A - Relational Databases: Some Basic Concepts
Appendix B - Commonly Used SQL Statements
Appendix C - ADO.NET Frequently Asked Questions
Index
List of Figures
List of Tables
List of Listings
List of Sidebars
Figure 22-4: The Trace Properties dialog box
Once you've launched the Trace Properties dialog box, you'll see a number of important options. If you
intend on being able to run the optimizer (which can automatically perform a number of optimizations on
your database), you'll need to save the output to a trace file. You can do this by checking the Capture to File
box and then choosing a file by clicking the folder icon to the right of the box.
The Events tab allows you to manually choose the events you'd like to include in the trace. These events
include table scans, stored procedures being called, and more. It's worth your time to look through this
menu and identify the types of events in which you're interested.
The Data Columns tab provides you with the ability to choose the kind of information you want captured
when each of the selected events occurs. Some of the options included are the Application Name, CPU
Applied ADO.NET: Building Data-Driven Solutions
Time Used, IO, and Duration.
by Mahesh Chand and David Talbot ISBN:1590590732
Apress
The Filters tab allows you to choose
2003 the items you would like excluded from your trace. Generally, you don't
(928 pages)
need this tab when working
This againstextensive
text provides a development database
coverage whose
of ADO.NET traffic is limited to your usage, but it's
technology
helpful in buildingincluding ADO.NET
a trace against a internals, namespaces,
large server classes, databases
that has multiple and on it. In other words, it's helpful
to be able to filterinterfaces, and takes a comprehensive look at XML
out the "noise."
namespaces and classes, and how to integrate both with
ADO.NET.
Once you've started your trace, you'll be able to watch the activity on your database in real time and
understand how long each query and stored procedure takes to execute (see Figure 22-5).
Table of Contents
Applied ADO.NETBuilding Data-Driven Solutions
Introduction
Chapter 1 - ADO.NET Basics
Chapter 2 - Data Components in Visual Studio .NET
Chapter 3 - ADO.NET in Disconnected Environments
Chapter 4 - ADO.NET in Connected Environments
Chapter 5 - Handling ADO.NET Events
Chapter 6 - Integrating XML with ADO.NET
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
Chapter 8 - Constraints and Data Relations
Chapter 9 - ADO.NET Exception Handling
Chapter 10 - Working with the ODBC .NET Data Provider
Chapter 11 - Stored Procedures and Views
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Chapter 13 - Developing a Custom Data Provider
Chapter 14 - Developing Database Web Applications using ASP.NET
Figure 22-5: The SQL Server Profiler with a trace running
Chapter 15 - Using ADO.NET in Xml Web Services
Chapter 16 - ASP.NET Server Controls and Data Binding
If you're17watching
Chapter a trace
- Building on a live
Real-World Webproduction system, you should be able to quickly identify any stored
Applications
procedures
Chapter that are taking a Mapping
18 - Object-Relational long timeinto.NET
run by looking at the Duration column. Any stored procedure
taking longer
Chapter than 50
19 - Mapped milliseconds
Objects: is a potential
Performance danger and
Considerations to your
Dataapplication's
Binding scalability.
Chapter 20 - COM Interoperability and ADO.NET
Optimizing Automatically with the SQL Server Profiler
Chapter 21 - Messaging
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
The SQLA Server
Appendix Profiler
- Relational also provides
Databases: Some an outstanding
Basic Concepts tool that can automatically optimize your database for
you. Database
Appendix veterans
B - Commonly are SQL
Used probably cringing as they read this after having been burned by one of the
Statements
variety of applications that promised to do this and delivered marginal results. However, SQL Server's Index
Appendix C - ADO.NET Frequently Asked Questions
Tuning Wizard provides most of the optimization that applications need as long as you understand a few
Index
caveats.
List of Figures
List of Tablesit's important to keep in mind that the Index Tuning Wizard does nothing for optimizing the
Foremost,
List of Listings
database for queries contained in stored procedures. This is a bit of a problem given that it's a good
List of Sidebars
practice to keep all of your database queries wrapped in stored procedures for optimal performance.
Note For more information about SQL Server performance, see Brad M. McGehee's site at www.sql-
server-performance.com. You can also refer to William R. Vaughn's books, notably ADO.NET
and ADO Examples and Best Practices for VB Programmers, Second Edition (Apress, 2002) or
the classic Hitchhiker's Guide to Visual Basic and SQL Server (Microsoft Press, 1998), which
discusses Visual Basic 6, SQL Server 7, and SQL Server 2000, Microsoft Data Engine (MSDE),
and ADO 2.0.
Fortunately, there are some workarounds to this particular problem. You can copy and paste queries from
your stored procedures into the Query Analyzer and have it assess the load you're putting on the database
and make an informed decision on what indexes should be added.
Once you've pasted your query into the Query Analyzer, choose Query Perform Index Analysis, and the
Applied ADO.NET: Building Data-Driven Solutions
Query Analyzer will use the SQL Server Profiler to show you the best course of action (see Figure 22-6).
by Mahesh Chand and David Talbot ISBN:1590590732
Apress 2003 (928 pages)
This text provides extensive coverage of ADO.NET technology
including ADO.NET internals, namespaces, classes, and
interfaces, and takes a comprehensive look at XML
namespaces and classes, and how to integrate both with
ADO.NET.
Table of Contents
Applied ADO.NETBuilding Data-Driven Solutions
Introduction
Figure 22-6: The Query Analyzer's recommendations for the current query
Chapter 1 - ADO.NET Basics
Chapter 2 - Data Components in Visual Studio .NET
If the Query Analyzer has recommendations on what you should do, a second dialog box will pop up and
Chapter 3 - ADO.NET in Disconnected Environments
ask if you want it to automatically implement the recommendations. Often, it recommends adding an index
Chapter 4 - ADO.NET in Connected Environments
to a particular column that is causing a table scan because table scans take significantly longer to run than
Chapter 5 - Handling ADO.NET Events
indexed queries (see Figure 22-7).
Chapter 6 - Integrating XML with ADO.NET
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
Chapter 8 - Constraints and Data Relations
Chapter 9 - ADO.NET Exception Handling
Chapter 10 - Working with the ODBC .NET Data Provider
Chapter 11 - Stored Procedures and Views
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Chapter 13 - Developing a Custom Data Provider
Chapter 14 - Developing Database Web Applications using ASP.NET
Chapter 15 - Using ADO.NET in Xml Web Services
Chapter 16 - 22-7:
Figure ASP.NETTheServer
QueryControls and recommendation
Analyzer's Data Binding to create an index that would help the query run
Chapter 17
faster - Building Real-World Web Applications
Chapter 18 - Object-Relational Mapping in .NET
You can
Chapter 19also attachObjects:
- Mapped the SQLPerformance
Server Profiler to run a trace
Considerations andagainst your production database to identify
Data Binding
stored procedures
Chapter that are taking
20 - COM Interoperability longer
and to execute than you would like. Then, launch the wizard and
ADO.NET
choose21
Chapter Profile the Performance of a Stored Procedure; the tool will test that particular stored procedure
- Messaging
and recommend
Chapter what you
22 - SQL Server and can do to optimize
ADO.NET: Notes on its performance.
Performance
Appendix A - Relational Databases: Some Basic Concepts
It's largely a matter of personal preference as to how you want to work to improve the performance of your
Appendix B - Commonly Used SQL Statements
stored procedures. Although the wizard makes suggestions, you don't have the opportunity to tweak and
Appendix
alter theCstored
- ADO.NET Frequently
procedure Asked
the way youQuestions
do with the Query Analyzer.
Index
List of Figures
Optimizing Your Transact-SQL Queries for Performance
List of Tables
List
You of can
Listings
tune your Transact-SQL queries and stored procedures for performance in a number of ways.
List of Sidebars
Think of your queries as asking the database a question and think of the optimizations you make on the
query as asking the question in a way that requires the database less thought. Listing 22-1 shows an
inefficient query that you can optimize.
Table of Contents
Applied ADO.NETBuilding Data-Driven Solutions
Introduction
Chapter 1 - ADO.NET Basics
Chapter 2 - Data Components in Visual Studio .NET
Figure 22-8: The estimated execution plan of the query in Listing 22-1
Chapter 3 - ADO.NET in Disconnected Environments
Chapter 4 - ADO.NET in Connected Environments
By using
Chapter 5 NOT IN to test
- Handling the subqueries,
ADO.NET Events SQL Server has to do a comparison to make sure that the
VideoTapeID
Chapter doesn'tXML
6 - Integrating match atADO.NET
with each level of the subquery. To understand what SQL Server is doing to
perform7 this
Chapter query,
- Data it's helpful
Binding to be able
and Windows to see
Forms the execution
Data-Bound path and examine it for comparisons and
Controls
table scans
Chapter that you can
8 - Constraints eliminate.
and Data Relations
Chapter 9 - ADO.NET Exception Handling
You can view this in the Query Analyzer by choosing Query Display Estimated Execution Path. This tool is
Chapter 10 - Working with the ODBC .NET Data Provider
an especially powerful weapon in the war against inefficient queries.
Chapter 11 - Stored Procedures and Views
Next to12
Chapter each item inSQLXML,
- Oracle, the execution path.NET
and Other is a Data
cost in terms of the percentage of the overall execution time
Providers
(always13adding
Chapter up to 100
- Developing percent).
a Custom DataAsProvider
you follow the execution path and move your mouse over each item,
you should
Chapter 14 - pay attention
Developing to a fewWeb
Database key Applications
items in theusing
pop-up text. The three most critical factors to pay
ASP.NET
attention
Chapter 15to- Using
are Estimated
ADO.NETNumber of Executes,
in Xml Web Services Estimated CPU, and Estimated IO.
Chapter 16 - ASP.NET Server Controls and Data Binding
Estimated Number of Executes lets you know how many times the comparison will be performed. If you can
Chapter 17 - Building Real-World Web Applications
think of a way to keep the logic of your query and still reduce the number of times this comparison must be
Chapter 18 - Object-Relational Mapping in .NET
performed, you can have an excellent impact on performance.
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
The Estimated
Chapter 20 - COMCPU and Estimated
Interoperability and IO columns let you know how much CPU usage and disk IO is resulting
ADO.NET
for a single
Chapter 21 - step in the process of executing your stored procedure.
Messaging
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Using the information derived from the estimated execution plan, you can identify a few areas that are ripe
Appendix A - Relational Databases: Some Basic Concepts
for optimization. You can significantly reduce the table scan icon that is taking up 60 percent of the
Appendix B - Commonly Used SQL Statements
execution time if you use a narrowing item in the WHERE clause.
Appendix C - ADO.NET Frequently Asked Questions
Index
One of the biggest impacts you can have on the speed of your query execution is keeping the result set as
small
List as possible. To this end, you can modify the SelectVideosCheckedIn stored procedure to include
of Figures
a simple
List way to reduce the number of rows that must be compared to the subquery. In this case, narrowing
of Tables
theofresults
List based upon the CategoryID vastly reduces the number of rows that will be analyzed and
Listings
returned.
List Listing 22-2 lists an optimized version of SelectVideosCheckedIn.
of Sidebars
Table of Contents
Applied ADO.NETBuilding Data-Driven Solutions
Introduction
Chapter 1 - ADO.NET Basics
Chapter 2 - Data Components in Visual Studio .NET
Chapter 3 - ADO.NET in Disconnected Environments
Chapter 4 - 22-9:
Figure ADO.NET
Theinestimated
Connectedexecution
Environments
plan of the query in Listing 22-2
Chapter 5 - Handling ADO.NET Events
A second
Chapter 6 strategy you can
- Integrating XML use
withto reduce the number of rows returned is to use SELECT TOP to reduce the
ADO.NET
number7 of-rows
Chapter Data you expect
Binding andtoWindows
be returned.
FormsThis can provide
Data-Bound an enormous performance boost, especially in
Controls
situations where
Chapter 8
you don't care precisely what records from the larger result set are required.
- Constraints and Data Relations
Chapter 9 - ADO.NET
An example of whereException Handling
this behavior is beneficial is in an unordered queue situation. For example, if you had
Chapter 10 - Working with the ODBC .NET to
a table that tracks tasks for employees Data Provider
perform and you wanted a query that would return 10 tasks for
Chapter 11 - Stored
the employee Procedures
to do, you couldand Views
write a query like this one:
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Chapter
SELECT 13 TOP
- Developing a Custom
10 TaskID, Data FROM
Name Provider
Tasks WHERE Assigned=0
Chapter 14 - Developing Database Web Applications using ASP.NET
Chapter 15 - Using ADO.NET in Xml Web Services
The performance
Chapter increase
16 - ASP.NET Server comes
Controlsfrom
and two
Dataelements.
Binding First, the number of rows that have to be piped
across 17
Chapter the-network
Building is significantly
Real-World Web less. Second, the query can stop running as soon as it has any 10
Applications
records18that
Chapter meet the criteria.Mapping in .NET
- Object-Relational
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
If the query had to have the tasks in some type of order, such as Date Due column, then the query would
Chapter 20 - COM Interoperability and ADO.NET
lose the benefit of being able to stop executing as soon as it identified 10 items meeting the criteria. Adding
Chapter
an ORDER21 -BY
Messaging
clause forces the query to completely execute to return the top 10 items in the correct order
Chapter
in which youSQL
22 - Server
expect and ADO.NET: Notes on Performance
them.
Appendix A - Relational Databases: Some Basic Concepts
Understanding
Appendix the execution
B - Commonly plans
Used SQL of your queries can help you devise effective strategies for producing
Statements
better stored
Appendix procedures.
C - ADO.NET Frequently Asked Questions
Index
Avoiding Excessive Stored Procedure Recompilation
List of Figures
List of Tables
One
List of of the reasons stored procedures are faster than simply executing SQL directly against the database is
Listings
thatofstored
List procedures are interpreted and compiled into a structure that SQL Server can execute
Sidebars
efficiently. The danger that comes from this is excessive recompilation if SQL Server thinks something has
changed in your stored procedure.
A simple way to avoid excessive recompilations is to keep all of your variable and temporary table
declarations together in your stored procedure. Some types of declarations, such as the creation of a
temporary table, cause the stored procedure to recompile, but if it surrounded by other such statements,
they will all be compiled at the same time instead of breaking execution as each statement is compiled.
Another cause of your stored procedure being frequently recompiled is if the contents of the tables the
stored procedure is querying change frequently. If you have a table that is constantly changing, using
sp_executesql can keep your stored procedure from recompiling (see Listing 22-3). The downside of
this particular approach is that SQL Server won't be able to cache the execution plan of the query you run in
your stored procedure.
Applied ADO.NET: Building Data-Driven Solutions
by Mahesh
Listing 22-3: Using Chand and David
sp_executesql Talbot a DatabaseISBN:1590590732
to Execute Query
Apress 2003 (928 pages)
This text provides extensive coverage of ADO.NET technology
EXEC dbo.sp_executesql N'
including ADO.NET internals, namespaces, classes, and
SELECT VideoTapeID,
interfaces, and takes Description
Title, a comprehensive FROM
look at VideoTape
XML WHERE
VideoTapeID NOT IN
namespaces and classes, and how to integrate both with
( ADO.NET.
SELECT VideoTapeID FROM VideoCheckOut as vco WHERE VideoTapeID NOT IN
(SELECT VideoTapeID From VideoCheckIn as vci WHERE
Table of Contents
vco.VideoCheckOutID=vci.VideoCheckOutID)
Applied ADO.NETBuilding Data-Driven Solutions
)'
Introduction
Chapter 1 - ADO.NET Basics
Chapter 2 - Data Components in Visual Studio .NET
Chapter 3 -what
To identify ADO.NET in procedures
stored DisconnectedinEnvironments
your database are recompiling excessively, use the SQL Server
Profiler4and
Chapter make sure
- ADO.NET you have the
in Connected SP:Recompile event selected. The SQL Server Profiler shows you
Environments
when each
Chapter 5 - recompilation occurs.
Handling ADO.NET If you're able to identify any stored procedures that recompile often, you'll
Events
have an6 excellent
Chapter placeXML
- Integrating to start
with tuning your database performance.
ADO.NET
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
Avoiding
Chapter 8 Locksand Data Relations
- Constraints
Chapter 9 - ADO.NET Exception Handling
To avoid
Chapter 10two threadswith
- Working accessing the.NET
the ODBC same resource
Data at the same time, SQL Server has a locking system. If
Provider
your CPU
Chapter 11 -usage
Storedand IO are low
Procedures andbut your database is performing slowly, it's likely you have some bad
Views
locking12
Chapter conditions
- Oracle,occurring.
SQLXML, and Other .NET Data Providers
Chapter 13 - Developing a Custom Data Provider
If you have a stored procedure that needs frequent recompilation, make sure you include the table owner in
Chapter 14 - Developing Database Web Applications using ASP.NET
all of your statements. When a stored procedure is being recompiled, it's in a locked state and can't be
Chapter 15 - Using ADO.NET in Xml Web Services
called by another process until it has finished recompiling. If it has to look up who owns each table as it
Chapter
does the16recompile,
- ASP.NET it'll
ServertakeControls
longer. and Data Binding
Chapter 17 - Building Real-World Web Applications
Also, avoid
Chapter 18 - using cursors at all
Object-Relational costs. in
Mapping A cursor
.NET allows row-by-row processing on a result set. Sometimes a
cursor is
Chapter 19necessary, but it can
- Mapped Objects: put a lock on
Performance the table while
Considerations anditData
executes. You can rewrite most queries that
Binding
use a cursor
Chapter using
20 - COM either a CASEand
Interoperability clause or at least a TABLE variable if you're using SQL Server 2000.
ADO.NET
Chapter 21 - Messaging
Finally, only use transactions when you need to-and keep transactions short. Because a transaction can't
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
have any data modified outside of the transaction while it's occurring, it'll lock almost everything it touches. If
Appendix A - Relational Databases: Some Basic Concepts
you think through the execution of your transaction and come up with any way to keep your transactional
Appendix
integrity Bwithout
- Commonly Used
actually SQL
using a Statements
transaction, then you can reduce the number of locks that occur.
Appendix C - ADO.NET Frequently Asked Questions
Index
Designing Your Tables for Optimal Performance
List of Figures
List
To of Tables the best performance from your database, you'll need to start thinking about performance as
achieve
List
youofdesign
Listings
your table schema. In every step of the process, think about how you'll query the data in the
List of Sidebars
table and how you'll run updates on it. Unfortunately, sometimes you'll have to break away from clean
design and choose one that is not as clean as you would like it to be to achieve optimal performance.
A common myth in designing a database for performance is that every table must have a primary key. In
general, it's a good idea for every table to have a primary key-unless the primary key will never be used. A
good example of this is a join table that sits between two tables and expresses a relationship between the
two. Adding an extra column to a table that represents a many-to-many relationship is like having a fifth
wheel on your car-it won't break anything, but it might hurt your gas mileage just a little. Figure 22-10 shows
a join table.
Applied ADO.NET: Building Data-Driven Solutions
by Mahesh Chand and David Talbot ISBN:1590590732
Apress 2003 (928 pages)
This text provides extensive coverage of ADO.NET technology
including ADO.NET internals, namespaces, classes, and
interfaces, and takes a comprehensive look at XML
namespaces and classes, and how to integrate both with
ADO.NET.
Figure 22-10: A join table that doesn't need a primary key
Table oftable
In the Contents
structure shown in Figure 22-10, the VideoTapeType table doesn't need a primary key. If you
Applied
added ADO.NETBuilding Data-Driven
another VideoTapeTypeID Solutions
column as an autonumbered primary key, it would be completely
Introduction
superfluous and add a useless piece of data to the database.
Chapter 1 - ADO.NET Basics
If performance
Chapter 2 - DataisComponents
absolutely critical down
in Visual to the
Studio last cycle and you're willing to commit to an unclean
.NET
database design,
Chapter 3
denormalizing your data can be an effective means of achieving that performance. This
- ADO.NET in Disconnected Environments
type of situation comes up fairly often when dealing with a system that allows people to log in and search
Chapter 4 - ADO.NET in Connected Environments
for companies. In this situation, you're working on a database that has two types of companies-companies
Chapter 5 - Handling ADO.NET Events
with people who can log into your system and companies that are just searchable data. It'll provide better
Chapter 6 - Integrating XML with ADO.NET
performance for the companies that can log in to have the companies that can't in a separate table. The
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
reason for this is it's likely that the number of companies that can't log in is significantly greater than those
Chapter 8 but
that can, - Constraints
at the same and Data
time Relations
you'll likely be doing many more queries on the companies that can log in. It's
Chapter 9 - ADO.NET Exception Handling
definitely a convoluted situation and bad practice to track the same data in two places. However, if you can
Chapter
keep the10amount
- Working with the
of data ODBC
in one .NET
table Data
that willProvider
be frequently accessed small to the detriment of good design,
Chapter 11 - Stored Procedures
it can help quite a bit. and Views
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Chapter 13 - Developing a Custom Data Provider
Checking the Size of Database Pages
Chapter 14 - Developing Database Web Applications using ASP.NET
Chapter
In SQL15 - Using
Server ADO.NET
2000, data isininternally
Xml Web stored
Servicesas a collection of 8KB pages. The more rows that can be
Chapter 16 a
stored on - ASP.NET Server
single 8KB page, Controls and all
the faster Data Binding
queries run on the database will be and the less space the table
will take17up.
Chapter - Building Real-World Web Applications
Chapter 18 - Object-Relational Mapping in .NET
A simple way to find out how many bytes each row takes up is to look at the Size column in design view. If
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
you add up the size of each of these columns and it's perfectly divisible by 8KB, then you have a perfect
Chapter 20 - COM Interoperability and ADO.NET
situation where no space will be wasted in the pages. This doesn't mean you should intentionally make your
Chapter 21 - Messaging
tableslarger just to be divisible by 8KB-but in general smaller tables are better for your application's design.
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
If you have a table with more than 10 columns, make sure your requirements are best served by what
Appendix A - Relational Databases: Some Basic Concepts
you're doing.
Appendix B - Commonly Used SQL Statements
Database
Appendix C -page size isFrequently
ADO.NET one of theAsked
reasons why it's generally better to have multiple small tables as opposed
Questions
to a denormalized table that contains a large number of columns.
Index
List of Figures
Understanding Denormalization
List of Tables
List of Listings
The
List of opposite
Sidebars of normalization is denormalization, which essentially amounts to creating large, flat table
structures that have all of the columns you need on a single row. Denormalized tables are generally used
for reporting, for derived tables, or for data warehousing. In general, it's not recommended to use a
denormalized schema unless it's for one of those reasons-generally in a data warehouse or "business
intelligence" environment.
The performance benefit of these tables comes from the fact that the database doesn't need to join
multiple tables together. Denormalization is useful for situations where you need most of the data that's in
the table. If a denormalized table has 40 columns, and you really only need the data in two of the columns
the majority of the time, you're likely better off just using a regular normalized table schema to achieve
optimal performance.
Understanding
Appliedthe Dangers
ADO.NET: ofData-Driven
Building Database Design Slippage
Solutions
by Mahesh Chand and David Talbot ISBN:1590590732
You have to maintain a fine balance when creating a database schema between three main elements:
Apress 2003 (928 pages)
This text
Clean normalized provides extensive coverage of ADO.NET technology
design
including ADO.NET internals, namespaces, classes, and
Performanceinterfaces, and takes a comprehensive look at XML
namespaces and classes, and how to integrate both with
ADO.NET.
Speed of development
If you're designing a large, complicated application, a good normalized design is probably the way to go. If
Table of Contents
scalability is the prime consideration, then performance comes first. If the application you're developing is
Applied ADO.NETBuilding Data-Driven Solutions
small and doesn't have scalability requirements, obviously speed of development is at the top of your list.
Introduction
Chapter 1 -make
Above all, ADO.NET
sureBasics
you're designing the application the way it's needed, and as with all professional
applications,
Chapter make
2 - Data the right tool
Components for theStudio
in Visual job and avoid architectural "gold plating" (creating a system that is
.NET
beautifully
Chapter 3 -geeky to ainprogrammer
ADO.NET but
Disconnected doesn't solve the business problem any better than a less-geeky
Environments
solution).
Chapter 4 The peopleinwho
- ADO.NET pay yourEnvironments
Connected salary probably don't know or care that your application uses an
absolutely
Chapter 5 -perfect normal
Handling form.
ADO.NET Events
Chapter 6 - Integrating XML with ADO.NET
With this consideration, you have to be careful when you start slipping from clean design because without
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
discipline it can become a "slippery slope." Sometimes doing the "wrong" thing because it's fast can make
Chapter 8 - Constraints and Data Relations
development slow later as you work to cover up the sins of your past. Always think in terms of both
Chapter
longterm9 lazy
- ADO.NET Exceptionlazy
and short-term Handling
(described in Chapters 18 and 19).
Chapter 10 - Working with the ODBC .NET Data Provider
Chapter 11 - Stored Procedures and Views
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Chapter 13 - Developing a Custom Data Provider
Chapter 14 - Developing Database Web Applications using ASP.NET
Chapter 15 - Using ADO.NET in Xml Web Services
Chapter 16 - ASP.NET Server Controls and Data Binding
Chapter 17 - Building Real-World Web Applications
Chapter 18 - Object-Relational Mapping in .NET
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
Chapter 20 - COM Interoperability and ADO.NET
Chapter 21 - Messaging
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Appendix A - Relational Databases: Some Basic Concepts
Appendix B - Commonly Used SQL Statements
Appendix C - ADO.NET Frequently Asked Questions
Index
List of Figures
List of Tables
List of Listings
List of Sidebars
Understanding
AppliedADO.NET
ADO.NET: BuildingPerformance Issues and Using Best
Data-Driven Solutions
by Mahesh Chand and David Talbot ISBN:1590590732
Practices Apress 2003 (928 pages)
This text
The following sections provides
discuss someextensive coverage
performance of ADO.NET
strategies and technology
best practices when working with
including ADO.NET internals, namespaces, classes, and
ADO.NET.
interfaces, and takes a comprehensive look at XML
namespaces and classes, and how to integrate both with
ADO.NET.
Selecting Data Providers
Many data providers are available to work with a single database, and selecting a best-suited data provider
Table of Contents
is the first step to designing performance-oriented, datadriven solutions. Some of the common data
Applied ADO.NETBuilding Data-Driven Solutions
providers discussed in this book are Sql, OleDb, ODBC, OracleClient, and SQLXML.
Introduction
Chapter 1 -provider
Each data ADO.NETacts
Basics
in a different way because of its internal architecture and the way it's designed.
Chapter 2 - Data
For example, theComponents
ODBC data in Visual Studio
provider .NET drivers, and the OleDb data provider uses OLE DB
uses ODBC
providers
Chapter 3 to connect to
- ADO.NET different dataEnvironments
in Disconnected sources. Each of these technologies works differently internally.
Chapter 4 - ADO.NET in Connected Environments
Selecting a- data
Chapter 5
provider depends on your application's requirements. This section discusses the different
Handling ADO.NET Events
scenarios and the best solutions.
Chapter 6 - Integrating XML with ADO.NET
Chapter
To work7 with
- Data
SQLBinding
Serverand Windows you
databases, Forms
canData-Bound
use any ofControls
these three data providers: Sql, OleDb, and
Chapter
ODBC.8But- Constraints andwith
when working Data Relations
SQL Server 7.0 or later databases, the Sql data provider is the best choice.
Chapter 9 data
No other - ADO.NET
providerException
can beatHandling
the performance of the Sql data provider in this case. The Sql data
Chapter 10can
provider - Working
providewith
much thefaster
ODBCdata
.NETaccess
Data Provider
than the OleDb and ODBC data providers. That said, the
Sql data
Chapter 11provider
- Storedisn't the bestand
Procedures choice to work with SQL Server 6.5 or prior versions of SQL Server.
Views
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
When working with Access databases, OleDb is the obvious choice. You can even use ODBC data
Chapter 13 - Developing a Custom Data Provider
providers, but OleDb provides better performance.
Chapter 14 - Developing Database Web Applications using ASP.NET
Chapter 15 - data
The ODBC Usingprovider
ADO.NETisin Xml Web
useful whenServices
your application needs to access an ODBC data source or there
Chapter 16 - ASP.NET Server Controls and Data
aren't OleDb or other providers available. ForBinding
example, if you need to access Excel or text data sources,
Chapter
you can17simply
- Building Real-World
do this Web Applications
using ODBC data sources.
Chapter 18 - Object-Relational Mapping in .NET
Now let's
Chapter 19 say your application
- Mapped needs to access
Objects: Performance an Oracle
Considerations database.
and There are different ways you can work
Data Binding
with Oracle
Chapter databases.
20 - COM You can and
Interoperability useADO.NET
the ODBC data provider. Microsoft already has released an Oracle
.NET data provider called OracleClient. Oracle offers another .NET provider developed for Oracle
Chapter 21 - Messaging
databases. Besides these three data providers, CoreLab offers an Oracle .NET data provider called
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
OraDirect. So, now the question is this: Which one do you choose? Obviously, using an Oracle .NET data
Appendix A - Relational Databases: Some Basic Concepts
provider (either Microsoft, Oracle, or CoreLab) is better than using an ODBC data provider to access
Appendix B - Commonly Used SQL Statements
Oracle databases. Performance-wise, the Oracle data provider is faster than the ODBC data provider
Appendix C - ADO.NET Frequently Asked Questions
because there's no overhead ODBC layer.
Index
List ofNote The .NET Framework 1.1 (or Visual Studio 2003) installs the Oracle and ODBC data providers.
Figures
The OleDb, Sql, Odbc, and Oracle data providers are defined in the System.Data.OleDb,
List of Tables
System.Data.SqlClient,System.Data.Odbc, and System.Data.OracleClient
List of Listings
namespaces (respectively).
List of Sidebars
Choosing from different Oracle .NET data providers depends on your options. Microsoft's Oracle .NET
data provider is available free as a part of ADO.NET. If you want to use a third-party data provider such as
OraDirect, you need to pay for it.
So, what's the solution when you need to work with different databases? Developing custom data access
code is definitely a good idea. A custom data provider can consume all data providers to find out the best
solution. Because all data providers implement ADO.NET interfaces, you can write some generic code
based on the interfaces that will work with any data provider. The following section shows you how to write
a generic data access component that utilizes multiple data providers to give you the best options.
Writing a Generic Data Access
Applied ADO.NET: Component
Building Data-Driven Solutions
by Mahesh Chand and David Talbot ISBN:1590590732
In this section, you'll create a simple generic data access class that allows you to select a DataAdapter
Apress 2003 (928 pages)
at runtime. Based on the similar theory, you can extend this class by adding other common functionality to
This text provides extensive coverage of ADO.NET technology
it.
including ADO.NET internals, namespaces, classes, and
interfaces, and takes a comprehensive look at XML
Listing 22-4 lists the generic class.
namespaces As youand
and classes, canhow
see,tothis code uses
integrate both interfaces
with to create a connection and
DataAdapter objects.
ADO.NET.This class has two methods: GetConnection and GetDataAdapter. The
GetConnection method returns an IDbConnection object created using different data providers
based on the connection type and connection string passed in the method. The code also provides
Table of Contents
functionality for the Sql, OleDb, ODBC, and Oracle data providers.
Applied ADO.NETBuilding Data-Driven Solutions
Listing 22-4: Generic Data Access Class
Introduction
Chapter 1 - ADO.NET Basics
Chapter 2 - Data
' Generic Components
Data Access incomponent
Visual Studio class
.NET
Chapter
Public 3 Class
- ADO.NET in Disconnected Environments
GenericDataAccessComp
Chapter 4 - ADO.NET
Private idbConnin Connected Environments = Nothing
As IDbConnection
Chapter 5 - Handling
Private ADO.NETAs
idbAdapter Events
IDbDataAdapter = Nothing
Private
Chapter dbAdapter
6 - Integrating As DbDataAdapter
XML with ADO.NET = Nothing
' Default
Chapter 7 - Data connection type Forms
Binding and Windows exposed through
Data-Bound Controls
' ConnectionType
Chapter 8 - Constraints and Data Relations
' 19 - -Sql;
Chapter 2 -Exception
ADO.NET OleDb,Handling
3 - Odbc
' 410- -Oracle
Chapter Working with the ODBC .NET Data Provider
Private DefConnType As Int16 = 1
Chapter 11 - Stored Procedures and Views
' Default connection string exposed through
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
' ConnString property
Chapter 13 - Developing a Custom Data Provider
Private DefConnStr As String
Chapter 14 - Developing Database Web Applications using ASP.NET
Chapter 15 - Using ADO.NET in Xml Web Services
Public Sub GenericDataAccessComp()
Chapter 16 - ASP.NET Server Controls and Data Binding
Chapter
End17Sub
- Building Real-World Web Applications
Chapter 18 - Object-Relational Mapping in .NET
Chapter 19 - Mapped Objects:
' GetConnection Performance
returns Considerations and Data Binding
IDbConnection
Chapter 20 - COM
Public Interoperability
Function and ADO.NET
GetConnection(ByVal connType As Integer, _
Chapter
ByVal21 -connString
Messaging As String) As IDbConnection
ChapterSelect
22 - SQLCase
ServerconnType
and ADO.NET: Notes on Performance
Case
Appendix A 1
- Relational Databases: Some Basic Concepts
Appendix B -'Commonly
OleDb Data Provider
Used SQL Statements
Appendix C -idbConn = New SqlConnection(connString)
ADO.NET Frequently Asked Questions
Index Case 2
List of Figures
' Sql Data Provider
idbConn = New OleDbConnection(connString)
List of Tables
Case 3
List of Listings
' ODBC Data Provider
List of Sidebars
idbConn = New OdbcConnection(connString)
Case 4
' Oracle data provider
idbConn = New OracleConnection(connString)
Case Else
Exit Function
End Select
Return idbConn
End Function
First, define some variables that you use in the application (see Listing 22-5). As you can see, this code
defines connection strings for different data providers.
Note For more information, read "Building Distributed Applications with Microsoft .NET" at
http://msdn.microsoft.com/library/default.asp?url=/library/en-
us/dnbda/html/bdadotnetarch13.asp.
Table of Contents
Applied ADO.NETBuilding Data-Driven Solutions
Introduction
Chapter 1 - ADO.NET Basics
Chapter 2 - Data Components in Visual Studio .NET
Chapter 3 - ADO.NET in Disconnected Environments
Chapter 4 - ADO.NET in Connected Environments
Chapter 5 - Handling ADO.NET Events
Chapter 6 - Integrating XML with ADO.NET
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
Chapter 8 - Constraints and Data Relations
Chapter 9 - ADO.NET Exception Handling
Chapter 10 - Working with the ODBC .NET Data Provider
Chapter 11 - Stored Procedures and Views
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Chapter 13 - Developing a Custom Data Provider
Chapter 14 - Developing Database Web Applications using ASP.NET
Chapter 15 - Using ADO.NET in Xml Web Services
Chapter 16 - ASP.NET Server Controls and Data Binding
Chapter 17 - Building Real-World Web Applications
Chapter 18 - Object-Relational Mapping in .NET
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
Chapter 20 - COM Interoperability and ADO.NET
Chapter 21 - Messaging
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Appendix A - Relational Databases: Some Basic Concepts
Appendix B - Commonly Used SQL Statements
Appendix C - ADO.NET Frequently Asked Questions
Index
List of Figures
List of Tables
List of Listings
List of Sidebars
AppendixApplied
A: ADO.NET:
Relational Databases:
Building Data-Driven Solutions
by Mahesh Chand and David Talbot
Some Basic
ISBN:1590590732
Figure A-1 shows the design of a Customers table. As you can see, it's been designed to store up to three
orders for any customer-sort of mimicking an array structure in spreadsheet format. There are obvious
problems with this design. As you can see from Figure A-2, there are many columns related to orders
(that's a classic giveaway of a poorly designed table-mixing two or more entities, or kinds of data).
Whenever a customer posts a new order, a new column will be added to the table. Not only that, if the
Applied ADO.NET: Building Data-Driven Solutions
same customer posts more than one order, the duplicate Address and City column data will be added to
by Mahesh
the table. This scenario addsChand and David
duplicate Talbot
data to ISBN:1590590732
the table. This table isn't in 1NF because the 1NF rule says
Apress 2003 (928 pages)
that a table is in 1NF if and only if a table's columns have no repeating values.
This text provides extensive coverage of ADO.NET technology
You apply 1NF onincluding ADO.NET
this table internals,
by eliminating thenamespaces, classes,
details about and providing just enough relational
the orders,
information to linkinterfaces, and takes
the Customers a comprehensive
table look table.
with a new Orders at XMLThe new format of this table after 1NF
namespaces and classes, and how to integrate both with
looks like Figure ADO.NET.
A-3. You still have some information about orders in this Customers table but only basic
link information: OrderNumber. You've fixed the repeating fields problem by jamming all the other order
information into a single OrderDescription field.
Table of Contents
Applied ADO.NETBuilding Data-Driven Solutions
Introduction
Chapter 1 - ADO.NET Basics
Chapter 2 - Data Components in Visual Studio .NET
Chapter 3 - ADO.NET in Disconnected Environments
Chapter 4 - ADO.NET in Connected Environments
Chapter 5 - Handling ADO.NET Events
Chapter 6 - Integrating XML with ADO.NET
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
Chapter 8 - A-3:
Figure Constraints and Data
Customers tableRelations
schema after 1NF
Chapter 9 - ADO.NET Exception Handling
Chapter 10 - Working with the ODBC .NET Data Provider
The data of the table now looks like Figure A-4.
Chapter 11 - Stored Procedures and Views
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Chapter 13 - Developing a Custom Data Provider
Chapter 14 - Developing Database Web Applications using ASP.NET
Chapter 15 - Using ADO.NET in Xml Web Services
Chapter 16 - ASP.NET Server Controls and Data Binding
Chapter 17 - Building Real-World Web Applications
Chapter 18 - Object-Relational Mapping in .NET
Chapter 19 - A-4:
Figure Mapped Objects:
Data Performancetable
of the Customers Considerations
after 1NF and Data Binding
Chapter 20 - COM Interoperability and ADO.NET
Chapter 21 - Messaging
Second Normal Form (2NF)
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Appendix A - Relational Databases: Some Basic Concepts
2NF eliminates
Appendix redundant
B - Commonly Useddata. A table is in 2NF if it's in 1NF and every nonkey column (not a key
SQL Statements
column-primary
Appendix or foreign)
C - ADO.NET is fully
Frequently dependent
Asked upon the primary key.
Questions
Index
Applying 2NF on a table removes duplicate data on multiple rows, places data in separate rows, places
List of Figures
grouped data in new tables, and creates relationships between the original tables and new tables through
List of Tables
foreign keys. As you can see from Figure A-4, there are six records for two customers and three columns-
List of Listings
CustomerName, Address, and City has the same information three times. 2NF eliminate these cases.
List
UnderSidebars
of 2NF, you separate data into two different tables and relate these tables using a foreign key.
Records in tables should not depend on anything other than the table's primary key.
In this example, you now create a separate Orders table. As you can probably guess, the Orders table
stores information related to customer orders. It relates back to the correct customer via the CustomerId
column. Now the two tables, Customers and Orders, look like Figure A-5 and Figure A-6.
Applied ADO.NET: Building Data-Driven Solutions
by Mahesh Chand and David Talbot ISBN:1590590732
Apress 2003 (928 pages)
This text provides extensive coverage of ADO.NET technology
including ADO.NET internals, namespaces, classes, and
Figure A-5: Customers table
interfaces, and aftera 2NF
takes comprehensive look at XML
namespaces and classes, and how to integrate both with
ADO.NET.
Table of Contents
Applied ADO.NETBuilding Data-Driven Solutions
Introduction
Chapter 1 - ADO.NET Basics
Chapter 2 - Data Components in Visual Studio .NET
Chapter 3 - ADO.NET in Disconnected Environments
Chapter 4 - ADO.NET in Connected Environments
Figure A-6: Orders table after 2NF
Chapter 5 - Handling ADO.NET Events
Chapter 6 - Integrating XML with ADO.NET
As you 7can- Data
Chapter see from Figures
Binding A-5 and Forms
and Windows A-6, both tables now
Data-Bound have a primary key-denoted by the key icon to
Controls
the left 8of the
Chapter column name.
- Constraints ThisRelations
and Data key will be unique for each record. The CustomerId column of the
Customers
Chapter 9 - table is mapped
ADO.NET to the
Exception CustomerId column of the Orders table. The CustomerId column of the
Handling
Orders10
Chapter table is a foreign
- Working with key. The relationship
the ODBC between the Customers and Orders tables looks like Figure
.NET Data Provider
A-7.
Chapter 11 - Stored Procedures and Views
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Chapter 13 - Developing a Custom Data Provider
Chapter 14 - Developing Database Web Applications using ASP.NET
Chapter 15 - Using ADO.NET in Xml Web Services
Chapter 16 - ASP.NET Server Controls and Data Binding
Chapter 17 - Building Real-World Web Applications
Chapter 18 - Object-Relational Mapping in .NET
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
Chapter 20 - COM Interoperability and ADO.NET
Chapter 21 - Messaging
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Appendix A - Relational Databases: Some Basic Concepts
Figure
Appendix B - A-7: Relationship
Commonly between
Used SQL the Customers and Orders tables
Statements
Appendix C - ADO.NET Frequently Asked Questions
Now the data in these tables look like Figure A-8 and Figure A-9.
Index
List of Figures
List of Tables
List of Listings
List of Sidebars
For example, as you can see from Figure A-10, CustomerId, UnitPrice, and Quantity depend on OrderId
Table
(the of Contents
primary key). But the Total column doesn't depend on the OrderId column; it depends upon the
Applied ADO.NETBuilding
UnitPrice and the QuantityData-Driven
columns. Solutions
Introduction
Chapter 1 - ADO.NET Basics
Chapter 2 - Data Components in Visual Studio .NET
Chapter 3 - ADO.NET in Disconnected Environments
Chapter 4 - ADO.NET in Connected Environments
Chapter 5 - Handling ADO.NET Events
Chapter 6 - Integrating XML with ADO.NET
Chapter 7 - A-10:
Figure Data Binding
Ordersand Windows
table Forms Data-Bound Controls
after 3NF
Chapter 8 - Constraints and Data Relations
The data
Chapter 9 of the Orders
- ADO.NET table look
Exception like Figure A-11 after applying the 3NF rule on it, and you can calculate
Handling
Total as
Chapter 10the multiplication
- Working of ODBC
with the UnitPrice
.NETand Quantity
Data in your SQL statement.
Provider
Chapter 11 - Stored Procedures and Views
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Chapter 13 - Developing a Custom Data Provider
Chapter 14 - Developing Database Web Applications using ASP.NET
Chapter 15 - Using ADO.NET in Xml Web Services
Chapter 16 - ASP.NET Server Controls and Data Binding
Chapter 17 - A-11:
Figure Building Real-World
Data Web Applications
of the Orders table after 3NF
Chapter 18 - Object-Relational Mapping in .NET
For example:
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
Chapter 20 - COM Interoperability and ADO.NET
Chapter
SELECT 21 UnitPrice
- Messaging * Quantity AS Total FROM Orders
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Appendix A - Relational Databases: Some Basic Concepts
Appendix B - Commonly Used SQL Statements
TheDataSet and Command objects enable you to work with data as a disconnected source, which is
similar to ADO client-side behavior. This method is useful when you need to write data-bound, control-
based applications.
ADO.NET doesn't support server-side cursors. However, you can use server-side cursors through ADO by
adding a reference to the ADODB type library by generating a .NET wrapper for its objects.
Using Locking
Applied ADO.NET: Building Data-Driven Solutions
by Mahesh Chand and David Talbot ISBN:1590590732
In database terms, locking
Apress is a(928
2003 mechanism
pages) used to avoid inconsistency when multiple users access and
update data simultaneously. Using the locking technique,
This text provides extensive coverage you cantechnology
of ADO.NET lock records or a database table when a
user is modifying including
the records
ADO.NET internals, namespaces, classes, and for other users until the current user
or table, and the data will be unavailable
interfaces,
calls the update method and takes
to make finalachanges.
comprehensive look at XML
For example, say user A is updating a record. During this
operation, user Bnamespaces
deletes thatand classes,
record. Thisand how tomay
scenario integrate both
lead to with
inconsistency in the table. You can avoid
ADO.NET.
this inconsistency by making that record unavailable when user A is updating it and make it available when
user A is done updating it. The only drawback of this is user B has to wait until user A is done updating the
record.
Table Oh well, waiting is better than having inconsistencies and inaccurate data.
of Contents
Applied ADO.NETBuilding Data-Driven Solutions
Isolation Levels
Introduction
Chapter 1 - ADO.NET Basics
Anisolation
Chapter 2 - level represents ainparticular
Data Components locking
Visual Studio strategy applied on a database. It's basically a way of
.NET
Chapter 3 - ADO.NET in Disconnected Environmentsthe complexity of locking. There are four isolation levels,
representing the stages of locking depending on
starting4from
Chapter level 0 to
- ADO.NET in 3. ApplyingEnvironments
Connected these levels on transactions is also called determining Transaction
Isolation Levels (TILs).
Chapter 5 - Handling ADO.NET Events
Chapter 6 - Integrating XML with ADO.NET
TILs provide consistency during data manipulation when multiple users are accessing data
Chapter 7 - Data There
simultaneously. Binding and
are Windows
three casesForms Data-Bound
that apply Controls
to the transactions:
Chapter 8 - Constraints and Data Relations
Chapter 9 read:
Dirty - ADO.NET Exception
A dirty Handling
read occurs when a user reads data that have not yet been committed. For
Chapter 10 - Working with the ODBC
example, user 1 changes a row. .NET Data
User Provider
2 reads the row before user 1 commits the changes. What if
Chapter 11 - Stored Procedures and Views
user 1 rolls back the changes? User 2 will have data that never existed.
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Chapter 13 - Developing a Custom Data Provider
Nonrepeatable read: A nonrepeatable read occurs when a user reads the same record twice but
Chapter 14 - Developing Database Web Applications using ASP.NET
gets different data each time. The simple case for this situation is when user 1 reads a record. User 2
Chapter 15 - Using ADO.NET in Xml Web Services
goes and either changes a record or deletes a record and commits the changes. Now if user 1 tries to
Chapter 16 the
read - ASP.NET Server Controls
same records and1Data
again, user getsBinding
different data.
Chapter 17 - Building Real-World Web Applications
Chapter 18 - Object-Relational Mapping in .NET
Phantom: A phantom is a record that matches the search criteria but isn't initially seen. For example,
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
say user 1 searches for records and gets some records. Now user 2 adds new rows with user 1's
Chapter 20 - COM Interoperability and ADO.NET
search criteria. Now if user 1 searches again using the same criteria, user 1 gets different results than
Chapter 21 - Messaging
the previous one.
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Appendix A -describes
Table A-2 Relationalthe
Databases:
isolationSome
levelsBasic Concepts
defined by OLE DB.
Appendix B - Commonly Used SQL Statements
Appendix C - Isolation
Table A-2: ADO.NET Frequently
Levels Asked Questions
Index
LEVEL DEFINITION
List of Figures
ListRead
of Tables A user can read uncommitted changes made by other users. At this level all
ListUncommitted
of Listings three cases (dirty reads, nonrepeatable reads, and phantoms) are possible.
List of Sidebars
Read A user can't see changes made by other users until the changes are
Committed committed. At this level of isolation, dirty reads aren't possible, but
nonrepeatable reads and phantoms are possible.
Repeatable A user can't see the changes made by other users. At this level of isolation,
Read dirty reads and nonrepeatable reads aren't possible, but phantoms are
possible.
Serializable A user sees only changes that are finalized and committed to the database. At
this isolation level, dirty reads, nonrepeatable reads, and phantoms aren't
possible.
Applied
Note The definitive ADO.NET:
book Building
on transaction Data-Driven
processing Solutions Control and Recovery in Database
is Concurrency
Systems byby
Mahesh
Philip Chand and David
A. Bernstein, TalbotHadzilacos, and
Vassos Nathan Goodman (Addison-Wesley,
ISBN:1590590732
1987).YouApress
can download it in its entirety as a 22.9MB self-extracting ZIP file from
2003 (928 pages)
http://research.microsoft.com/pubs/ccontrol/.
This text provides extensive coverage ofYou can also
ADO.NET find related information at
technology
including ADO.NET internals, namespaces, classes, and
http://research.microsoft.com/~philbe/.
interfaces, and takes a comprehensive look at XML
namespaces
Table A-3 summarizes andconsistency
the data classes, andbehaviors
how to integrate both with
and isolation level relationship. (Read Committed is
ADO.NET.
SQL Server's default isolation level.)
Table
Table of A-3: Isolation Levels and Data Consistency
Contents
Applied ADO.NETBuilding Data-Driven Solutions
LEVEL DIRTY READ? NONREPEATABLE READ? PHANTOM?
Introduction
Read 1Uncommitted
Chapter (0)
- ADO.NET Basics Yes Yes Yes
Chapter 2 - Data Components in Visual Studio .NET
Read Committed (1) No Yes Yes
Chapter 3 - ADO.NET in Disconnected Environments
Repeatable
Chapter Read (2)
4 - ADO.NET NoEnvironments
in Connected No Yes
Chapter 5 - Handling ADO.NET Events
Serializable (3) No No No
Chapter 6 - Integrating XML with ADO.NET
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
Chapter 8 - Constraints and Data Relations
Locking
Chapter 9
Modes
- ADO.NET Exception Handling
Chapter 10 - Working with the ODBC .NET Data Provider
In general, locking avoids the consequences of multiple users accessing the same data simultaneously
Chapter 11to- Stored
and tries maintainProcedures
the data'sand Views
consistency and integrity. There are two locking modes: shared and
Chapter 12 - Oracle, SQLXML, and Other
exclusive. The shared mode lets multiple .NET Dataaccess
users Providers
the same data simultaneously. However, an
Chapter 13 mode
exclusive - Developing a Custom
won't let Data Provider
user 2 access the data until user 1 unlocks the data. Depending on the database,
Chapter
you can14implement
- Developing Database
locking on a Web Applications
record, using
a table, or ASP.NET
a page level. In table locking, a user can lock the entire
Chapter 15 -he
table until Using ADO.NET
commits in Xml Web
the changes andServices
unlocks the table. The same method applies on a page as well as
on a record
Chapter for page-level
16 - ASP.NET Serverand record-level
Controls and Datalocking.
Binding
Chapter 17 - Building Real-World Web Applications
Note Chapters 4 and 5 discuss ADO.NET concurrency.
Chapter 18 - Object-Relational Mapping in .NET
Chapter
Based 19 - Mapped
on these Objects:
general Performance
locking Considerations
modes, ADO anddifferent
provides two Data Binding
types of locking on recordsets and the
Chapter 20 - COM Interoperability and ADO.NET
combination of them: optimistic locking and pessimistic locking. Optimistic locking is based on the
Chapter 21 - Messaging
assumption that there won't be any other users when a user is accessing some records of a table.
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
In optimistic
Appendix locking, locking
A - Relational only Some
Databases: occursBasic
during the final update of records. If any changes were made to
Concepts
the dataBsince
Appendix it was last
- Commonly accessed,
Used the application must read data again and update the data.
SQL Statements
Appendix C - ADO.NET Frequently Asked Questions
In pessimistic locking, records are unavailable to other users when a user is accessing records until the
Index
user makes the final changes.
List of Figures
You
List of can pass an argument when you create a recordset to specify the type of locking. Table A-4
Tables
describes
List these values.
of Listings
List of Sidebars
Table A-4: Locking Types
CONSTANT VALUE DESCRIPTION
adLockReadOnly 1 Read-only
adLockPessimistic 2 Pessimistic locking
adLockOptimistic 3 Optimistic locking
adLockBatchOptimistic 4 Optimistic locking with batch updates
You set the LockType variable in the recordset to 1 when you need to read data. It doesn't allow you to
add or update data.
Applied ADO.NET: Building Data-Driven Solutions
You use LockType=3, or optimistic
by Mahesh Chand and locking, when you need toISBN:1590590732
David Talbot lock records and only when ADO physically
Apress
updates the record. Otherwise, records
2003 (928 pages) are available when you're editing them. In contrast to the optimistic
locking, pessimistic
Thislocking locks the
text provides recordscoverage
extensive when you of start editing
ADO.NET records. You set LockType=2 in that
technology
including
case. Before applying ADO.NET
optimistic internals,
locking, you namespaces,
need to makeclasses, anddatabase manufacturer supports it.
sure that
interfaces, and takes
Some database manufacturers a comprehensive
don't support optimisticlook at XML
locking.
namespaces and classes, and how to integrate both with
ADO.NET.
Optimistic locking with batch updates, LockType=4, enables you to access multiple records, update them
locally, and update the database as a single batch operation. Again, before using this type of locking, you
needoftoContents
Table make sure the database manufacturer supports this type of locking. Many don't.
Applied ADO.NETBuilding Data-Driven Solutions
Note For more information on locking and concurrency levels, you may want to read Jim Gray's article
Introduction
on isolation levels at http://research.microsoft.com/~gray/Isolation.doc or Transaction
Chapter 1 - ADO.NET Basics
Processing: Concepts and Techniques by Jim Gray and Andreas Reuter (Morgan Kaufmann,
Chapter 2 1993).
- Data Components in Visual Studio .NET
Chapter 3 - ADO.NET in Disconnected Environments
Chapter 4 - ADO.NET in Connected Environments
What Are Deadlocks?
Chapter 5 - Handling ADO.NET Events
If you've
Chapter heard about
6 - Integrating concurrency
XML and different kinds of locks, you've probably also heard about
with ADO.NET
deadlocks.
Chapter 7 - DataUnfortunately, they're Forms
Binding and Windows an inevitable fact ofControls
Data-Bound life in the database world. But, fortunately,
today's- Constraints
Chapter 8
Database Management Systems (DBMSs) are typically designed to handle deadlocks-usually
and Data Relations
by selecting a "victim" whose transaction gets rolled back (or undone).
Chapter 9 - ADO.NET Exception Handling
Chapter 10 -users
When Working with
share the ODBC
access .NET Data
to database Provider
tables, they may prevent each other from completing
Chapter 11 - Stored Procedures and Views
transactions. That's because a user who locks a table or a single record during an update may
Chapter 12 - Oracle,
prevent SQLXML, andfrom
other transactions Other .NET Data
acquiring theProviders
locks they need to complete their task. As a result, the
Chapter 13 transactions
other - Developing enter
a Custom Data
a wait Provider
state, waiting their turn. Sometimes, the locks are unresolvable, though.
For14
Chapter example, if transaction
- Developing DatabaseAWeb
can't complete until
Applications usingit ASP.NET
acquires a lock being used by transaction B, and
transaction
Chapter B ADO.NET
15 - Using can't complete
in Xml until
Web itServices
acquires a lock being used by transaction A, the transactions enter
a deadlock
Chapter stateServer
16 - ASP.NET and neither canand
Controls complete unless the other is terminated.
Data Binding
Chapter 17 - Building Real-World Web Applications
Microsoft describes deadlocks by noting the following: "A deadlock occurs when there is a cyclic
Chapter 18 - Object-Relational Mapping in .NET
dependency between two or more threads for some set of resources." It adds that deadlocks can
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
occur on any system with multiple threads, not just on a relational DBMS.
Chapter 20 - COM Interoperability and ADO.NET
Chapter 21 - Messaging
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Appendix A - Relational Databases: Some Basic Concepts
Appendix B - Commonly Used SQL Statements
Appendix C - ADO.NET Frequently Asked Questions
Index
List of Figures
List of Tables
List of Listings
List of Sidebars
Summary Applied ADO.NET: Building Data-Driven Solutions
by Mahesh Chand and David Talbot ISBN:1590590732
In this appendix, we discussed
Apress some
2003 (928 of the basic concepts of relational databases. To learn more, you can
pages)
access the following resources online:
This text provides extensive coverage of ADO.NET technology
including ADO.NET internals, namespaces, classes, and
"Database Normalization Basics":
interfaces, and takes a comprehensive look at XML
namespaces and classes, and how to integrate both with
http://support.microsoft.com/default.aspx?scid=KB;en-us;q209534
ADO.NET.
Table of Contents
Applied ADO.NETBuilding Data-Driven Solutions
Introduction
Chapter 1 - ADO.NET Basics
Chapter 2 - Data Components in Visual Studio .NET
Chapter 3 - ADO.NET in Disconnected Environments
Chapter 4 - ADO.NET in Connected Environments
Figure
Chapter 5 - B-3: TheADO.NET
Handling Query Editor of Access 2000
Events
Chapter 6 - Integrating XML with ADO.NET
Chapter 7 take
Now let's - Data Binding
a look andNorthwind
at the Windows Forms Data-Bound
database's Controls
Customers table. Figure B-4 shows the table schema (the
Chapter 8 with
structure) - Constraints
its columnand Data Relations
names and their data types (all of type Text in this case). Note that the CustomerID
Chapter 9 -primary
field is the ADO.NET Exception
key field. Handling
Chapter 10 - Working with the ODBC .NET Data Provider
Chapter 11 - Stored Procedures and Views
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Chapter 13 - Developing a Custom Data Provider
Chapter 14 - Developing Database Web Applications using ASP.NET
Chapter 15 - Using ADO.NET in Xml Web Services
Chapter 16 - ASP.NET Server Controls and Data Binding
Chapter 17 - Building Real-World Web Applications
Chapter 18 - Object-Relational Mapping in .NET
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
Chapter 20 - COM Interoperability and ADO.NET
Chapter 21 - Messaging
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Appendix A - Relational Databases: Some Basic Concepts
Appendix B - Commonly Used SQL Statements
Appendix C - ADO.NET Frequently Asked Questions
Index
Figure B-4: Customers table schema of the Northwind database
List of Figures
List of Tables
List
The of Orders
Listingstable columns and their data types look like Figure B-5. OrderID is the primary key in the Orders
table.
List CustomerID and EmployeeID function as foreign keys and provide the "glue" that links data in the
of Sidebars
Customers table to data stored in Orders and Employees. (Employees is another table in the Northwind
database that stores employee records.)
Applied ADO.NET: Building Data-Driven Solutions
by Mahesh Chand and David Talbot ISBN:1590590732
Apress 2003 (928 pages)
This text provides extensive coverage of ADO.NET technology
including ADO.NET internals, namespaces, classes, and
interfaces, and takes a comprehensive look at XML
namespaces and classes, and how to integrate both with
ADO.NET.
Table of Contents
Applied ADO.NETBuilding Data-Driven Solutions
Introduction
Chapter 1 - ADO.NET Basics
Chapter 2 - Data Components in Visual Studio .NET
Chapter 3 - ADO.NET in Disconnected Environments
Chapter 4 - ADO.NET in Connected Environments
Chapter 5 - Handling ADO.NET Events
Figure B-5: Orders table schema of the Northwind database
Chapter 6 - Integrating XML with ADO.NET
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
Chapter 8 - Constraints and Data Relations
Using the
Chapter 9
SELECT Statement
- ADO.NET Exception Handling
Chapter 10 - Working
TheSELECT withisthe
statement theODBC .NET Data
workhorse Provider
of the SQL language; it enables you to retrieve data from database
Chapter 11 - Stored Procedures and Views
tables and views. If you want to retrieve data from selected columns, you list the column names in the SELECT
Chapter 12 - You
statement. Oracle,
useSQLXML, andclause
the WHERE Other .NET Data Providers
to retrieve data from selected rows.
Chapter 13 - Developing a Custom Data Provider
The simplest
Chapter form of the
14 - Developing SELECT
Database statement
Web is SELECT...FROM,
Applications using ASP.NET which returns records from a table defined
after FROM.
Chapter 15 - This
UsingisADO.NET
the syntax:
in Xml Web Services
Chapter 16 - ASP.NET Server Controls and Data Binding
SELECT
Chapter 17 column1, column2,
- Building Real-World Web.., FROM table
Applications
Chapter 18 - Object-Relational Mapping in .NET
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
Chapter 20 - COM Interoperability and ADO.NET
For example, the following SELECT statement returns all records from the CustomerID, CompanyName,
Chapter 21 - Messaging
Address, and City columns of the Customers table:
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Appendix A - Relational Databases: Some Basic Concepts
SELECT CustomerID, CompanyName, Address, City FROM Customers
Appendix B - Commonly Used SQL Statements
Appendix C - ADO.NET Frequently Asked Questions
Index
The output looks like Figure B-6.
List of Figures
List of Tables
List of Listings
List of Sidebars
Note You can switch back to the SQL view be selecting View SQL View.
You use SELECTApplied
* to return all columns
ADO.NET: fromData-Driven
Building a table (the asterisk
Solutions is a handy wildcard character in most
dialects of SQL). by
ForMahesh
example, theand
Chand following
David statement
Talbot returnsISBN:1590590732
all records from the Customers table:
Apress 2003 (928 pages)
SELECT * FROMThis text provides extensive coverage of ADO.NET technology
Customers
including ADO.NET internals, namespaces, classes, and
interfaces, and takes a comprehensive look at XML
namespaces and classes, and how to integrate both with
The output looks ADO.NET.
like Figure B-7.
Table of Contents
Applied ADO.NETBuilding Data-Driven Solutions
Introduction
Chapter 1 - ADO.NET Basics
Chapter 2 - Data Components in Visual Studio .NET
Chapter 3 - ADO.NET in Disconnected Environments
Chapter 4 - ADO.NET in Connected Environments
Chapter 5 - Handling ADO.NET Events
Chapter 6 - Integrating XML with ADO.NET
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
Chapter 8 - Constraints and Data Relations
Figure B-7: Output of SELECT * FROM Customers statement
Chapter 9 - ADO.NET Exception Handling
Chapter 10 - Working with the ODBC .NET Data Provider
There are
Chapter 11 -some occasions
Stored when
Procedures and the database table stores redundant records, but you generally don't want
Views
duplicate
Chapter 12 records
- Oracle,returned.
SQLXML, You
and can use
Other theData
.NET SELECT DISTINCT statement for this purpose. This is the
Providers
syntax: 13 - Developing a Custom Data Provider
Chapter
Chapter 14 - Developing Database Web Applications using ASP.NET
SELECT
Chapter 15 DISTINCT column1,
- Using ADO.NET column2,
in Xml Web Services .., FROM table
Chapter 16 - ASP.NET Server Controls and Data Binding
Chapter 17 - Building Real-World Web Applications
For example, the following statement returns only unique records from the Customers table:
Chapter 18 - Object-Relational Mapping in .NET
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
SELECT DISTINCT CompanyName FROM Customers
Chapter 20 - COM Interoperability and ADO.NET
Chapter 21 - Messaging
Chapter 22 -to
In addition SQL Server and
restricting ADO.NET:
columns Notes
to those on Performance
you're interested in, you can also restrict rows by using the
Appendix A - Relational Databases: Some
SELECT...FROM ...WHERE statement. The Basic Concepts
WHERE clause takes a conditional statement:
Appendix B - Commonly Used SQL Statements
Appendix C - ADO.NET Frequently Asked Questions
SELECT column1, column2, .., FROM table WHERE condition
Index
List of Figures
Forofexample,
List Tables the following query:
List of Listings
List of Sidebars
SELECT * FROM Customers WHERE CustomerID = "BOTTM"
returns records only having a CustomerID that equals BOTTM. The output of the Northwind database's
Customers table looks like Figure B-8.
Applied ADO.NET: Building Data-Driven Solutions
by Mahesh Chand and David Talbot ISBN:1590590732
Apress 2003 (928 pages)
This text provides extensive coverage of ADO.NET technology
including ADO.NET internals, namespaces, classes, and
interfaces, and takes a comprehensive look at XML
namespaces and classes, and how to integrate both with
ADO.NET.
Table of Contents
Applied ADO.NETBuilding Data-Driven Solutions
Figure B-8: Output of the SELECT...WHERE statement
Introduction
Chapter 1 - ADO.NET Basics
Chapter 2 -summarizes
Table B-1 Data Components in Visual Studio
the conditional .NET used in SQL.
statements
Chapter 3 - ADO.NET in Disconnected Environments
Table B-1:
Chapter 4 - Conditional Statements
ADO.NET in Connected Used in SQL
Environments
Chapter 5 - Handling ADO.NET Events
OPERATOR MEANING
Chapter 6 - Integrating XML with ADO.NET
Chapter
< 7 - Data Binding and Windows Forms Data-BoundLess
Controls
Than
Chapter 8 - Constraints and Data Relations
> Greater Than
Chapter 9 - ADO.NET Exception Handling
<> 10 - Working with the ODBC .NET Data Provider
Chapter Not Equal To
Chapter 11 - Stored Procedures and Views
= Equal To
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Chapter 13 - Developing a Custom Data Provider
You can also use the SUM and AVG functions to return the sum and average of numeric columns, respectively:
Chapter 14 - Developing Database Web Applications using ASP.NET
Chapter 15 - Using ADO.NET in Xml Web Services
SELECT function(column) FROM table
Chapter 16 - ASP.NET Server Controls and Data Binding
Chapter 17 - Building Real-World Web Applications
Chapter 18 - Object-Relational
For example, Mapping
the following query in .NET
returns the sum of the Freight column in the Orders table:
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
Chapter
SELECT 20 SUM(Freight)
- COM Interoperability
FROM and ADO.NET
Orders
Chapter 21 - Messaging
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
SeeFigure
Appendix A -B-9 for theDatabases:
Relational output of this
Somestatement.
Basic Concepts
Appendix B - Commonly Used SQL Statements
Appendix C - ADO.NET Frequently Asked Questions
Index
List of Figures
List of Tables
List of Listings
List of Sidebars
Figure B-9: Output of query that uses the SQL SUM function
SELECT OrderDate FROM Orders GROUP BY(OrderDate) HAVING SUM(Freight) > 900
Table of Contents
Applied ADO.NETBuilding Data-Driven Solutions
Introduction
Using the
Chapter 1 UPDATE
- ADO.NET Basics Statement
Chapter 2 - Data Components in Visual Studio .NET
TheUPDATE statement makes changes to existing records in a database table. The UPDATE statement takes
Chapter 3 - ADO.NET in Disconnected Environments
database table names and table columns and their values.
Chapter 4 - ADO.NET in Connected Environments
Chapter 5 - for
The syntax Handling
UPDATEADO.NET Events
statement is as follows:
Chapter 6 - Integrating XML with ADO.NET
Chapter 7
- Data Binding and Windows Forms Data-Bound Controls
UPDATE table SET column1 = [new value], column2 =[new value],.,WHERE {condition}
Chapter 8 - Constraints and Data Relations
Chapter 9 - ADO.NET Exception Handling
For example,
Chapter the following
10 - Working with thequery
ODBCupdates theProvider
.NET Data Freight column value to 500 in the Orders table where OrderId is
10248:11 - Stored Procedures and Views
Chapter
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Chapter
UPDATE 13 Orders
- Developing
SETa Custom
Freight Data
= Provider
500 WHERE OrderId = 10248
Chapter 14 - Developing Database Web Applications using ASP.NET
Chapter 15 - Using ADO.NET in Xml Web Services
Using a16comma,
Chapter youServer
- ASP.NET can update as and
Controls many as Binding
Data columns as you want. If you want to update all the rows of a
column or more than one column, you don't use the WHERE clause. For example, the following query updates
Chapter 17 - Building Real-World Web Applications
all the rows of the Freight column with the value of 500:
Chapter 18 - Object-Relational Mapping in .NET
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
UPDATE
Chapter 20 Orders SET Freight
- COM Interoperability and = 500
ADO.NET
Chapter 21 - Messaging
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Using the DELETE Statement
Appendix A - Relational Databases: Some Basic Concepts
Appendix B - Commonly Used SQL Statements
TheDELETE statement removes records from a database table. Using the DELETE statement, which is
Appendix C - ADO.NET Frequently Asked Questions
dangerously simple, you can either delete records based on certain criteria or delete all the records of a
Index
database table.
List of Figures
List
The of syntax
Tables of the DELETE statement is as follows:
List of Listings
List of Sidebars
DELETE FROM table WHERE {condition}
For example, the following statement deletes all rows of OrderId 10248 (there should be only one because
OrderID is the primary key):
If you want to delete all of a table's rows, retaining an empty table, you can use the following statement:
DELETE FROM Orders
Applied ADO.NET: Building Data-Driven Solutions
by Mahesh Chand and David Talbot ISBN:1590590732
(In Access, DELETE statements
Apress can
2003 (928 impact more than one table's rows depending on whether cascading
pages)
deletes are enabled.)
This text provides extensive coverage of ADO.NET technology
including ADO.NET internals, namespaces, classes, and
interfaces, and takes a comprehensive look at XML
Using the CREATE TABLE Statement
namespaces and classes, and how to integrate both with
ADO.NET.
A database table is a collection of rows and columns. Each field in a table is represented as a column. Each
field of a table must have a defined data type and a unique name. You can use the CREATE TABLE statement
Table of Contents
to create database tables programmatically.
Applied ADO.NETBuilding Data-Driven Solutions
The syntax for CREATE TABLE is as follows:
Introduction
Chapter 1 - ADO.NET Basics
Chapter
CREATE 2 TABLE
- Data Components in Visual Studio
table (column1 .NET
column1_datatype,
Chapter
column23 -column2_datetype,
ADO.NET in Disconnected..,
Environments
column column_datatype)
Chapter 4 - ADO.NET in Connected Environments
Chapter 5 - Handling ADO.NET Events
The following
Chapter 6
statement creates a myTable table with the columns myId, myName, myAddress, and
- Integrating XML with ADO.NET
myBalance, which can store integer, character 50, character 255, and floating values, respectively. The
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
CONSTRAINT...PRIMARY KEY syntax makes a column a primary key column:
Chapter 8 - Constraints and Data Relations
Chapter 9 - ADO.NET Exception Handling
CREATE TABLE myTable (myId INTEGER CONSTRAINT PKeyMyId PRIMARY KEY,
Chapter 10 - Working with the ODBC .NET Data Provider
myName CHAR(50), myAddress CHAR(255), myBalance FLOAT)
Chapter 11 - Stored Procedures and Views
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Chapter 13 - Developing a Custom Data Provider
Using the DROP TABLE Statement
Chapter 14 - Developing Database Web Applications using ASP.NET
Chapter 15 - Using ADO.NET in Xml Web Services
There might be some occasions when either you need to delete a table permanently or you need to create
Chapter 16 - ASP.NET Server Controls and Data Binding
temporary, "scratch" tables and then delete them. The DROP TABLE statement deletes a database table.
Chapter 17 - Building Real-World Web Applications
Chapter 18 - for
The syntax Object-Relational
DROP TABLEMapping in .NET
is as follows:
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
Chapter 20 - COMtable
DROP TABLE Interoperability and ADO.NET
Chapter 21 - Messaging
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Appendix A - Relational Databases: Some Basic Concepts
For example,
Appendix the following
B - Commonly Usedstatement deletes myTable from the database:
SQL Statements
Appendix C - ADO.NET Frequently Asked Questions
Index
DROP TABLE myTable
List of Figures
List of Tables
TRUNCATE TABLE doesn't remove the table structure, columns, constraints, or indexes. If you want to remove
a table definition and its data, use DROP TABLE instead.
Table Note
of Contents
Access databases don't natively support TRUNCATE TABLE.
Applied ADO.NETBuilding Data-Driven Solutions
Introduction
Using the
Chapter 1
INSERT Statement
- ADO.NET Basics
Chapter 2 - Data
In the previous Components
sections in Visual
you saw how toStudio .NETinformation from tables. But how do these rows of data get
retrieve
Chapter
into the3tables
- ADO.NET in Disconnected
in the first place? This Environments
is what this section, covering INSERT INTO, and the next section,
covering
Chapter 4 UPDATE, areinabout.
- ADO.NET Connected Environments
Chapter 5 - Handling ADO.NET Events
There are
Chapter 6 -basically twoXML
Integrating ways to insert
with ADO.NETdata into a table. One way is to insert them one row at a time, and the
other way -isData
Chapter 7
to insert the data several rows at a time. First let's look at how you can insert data one row at a
Binding and Windows Forms Data-Bound Controls
time.
Chapter 8 - Constraints and Data Relations
Chapter 9 - for
The syntax ADO.NET Exception
inserting Handling
data into a table one row at a time is as follows:
Chapter 10 - Working with the ODBC .NET Data Provider
Chapter 11 - Stored Procedures and Views
INSERT INTO table (column1, column2, .., columnn)
Chapter
VALUES 12 (value1,
- Oracle, SQLXML, and Other
value2, ...,.NET Data Providers
valunen)
Chapter 13 - Developing a Custom Data Provider
Chapter 14 - Developing Database Web Applications using ASP.NET
For example,
Chapter the following
15 - Using ADO.NET inquery
Xml adds a new record to the Customers table columns with their corresponding
Web Services
values:16 - ASP.NET Server Controls and Data Binding
Chapter
Chapter 17 - Building Real-World Web Applications
Chapter
INSERT 18 INTO
- Object-Relational Mapping in .NET
Customers(CompanyName, ContactName, ContactTitle,
Address,
Chapter City, Objects:
19 - Mapped Phone)Performance
VALUES ("New Name","New
Considerations and DataContact","New
Binding Title",
"New Address",
Chapter "New City",
20 - COM Interoperability "New Phone")
and ADO.NET
Chapter 21 - Messaging
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
You can also insert records in a table by selecting records from another table. You can do that by mixing
Appendix A - Relational Databases: Some Basic Concepts
INSERT INTO and SELECT statements. The only condition is that the data type of the columns must match in
Appendix B - Commonly Used SQL Statements
both tables.
Appendix C - ADO.NET Frequently Asked Questions
Index
The syntax for this is as follows:
List of Figures
List of Tables
INSERT INTO table1 (column1, column2, ...)
List of Listings
SELECT column1, column2, ... FROM table2
List of Sidebars
The previous syntax selects data from table2 and inserts it in table1. The data types of column1 in table1 must
match with the data type of column1 in table2 and so on.
The following query reads CustName and ContName from NewTable and inserts data to the Customers table:
You can also apply WHERE and other clauses on this query as you have applied them on the previous SELECT
statements.
Applied ADO.NET: Building Data-Driven Solutions
Using Joinsby and Aliases
Mahesh Chand and David Talbot ISBN:1590590732
Apress 2003 (928 pages)
You can represent a table and column in a SQL statement using their alias names. Aliases are frequently
This text provides
used as shorthand-especially extensive
in join queries.coverage of syntax:
This is the ADO.NET technology
including ADO.NET internals, namespaces, classes, and
interfaces, and takes a comprehensive look at XML
namespaces and classes,
SELECT aliastable.column1 and how to FROM
aliascolumn integrate both with
table aliastable
ADO.NET.
For example, this code uses A1 as the alias for the Customers table:
Table of Contents
Applied ADO.NETBuilding Data-Driven Solutions
SELECT A1.CustomerID FROM Customers A1;
Introduction
Chapter 1 - ADO.NET Basics
Chapter
Figure 2B-12
- Data Components
shows the outputinofVisual Studio .NET
this statement. You can use the same syntax for multiple tables by separating
Chapter 3 -commas.
them with ADO.NET in Disconnected Environments
Chapter 4 - ADO.NET in Connected Environments
Chapter 5 - Handling ADO.NET Events
Chapter 6 - Integrating XML with ADO.NET
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
Chapter 8 - Constraints and Data Relations
Chapter 9 - ADO.NET Exception Handling
Chapter 10 - Working with the ODBC .NET Data Provider
Chapter 11 - Stored Procedures and Views
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Chapter 13 - Developing a Custom Data Provider
Chapter 14 - Developing Database Web Applications using ASP.NET
Chapter 15 - Using ADO.NET in Xml Web Services
Chapter 16 - ASP.NET Server Controls and Data Binding
Figure B-12: Output of the Alias statement
Chapter 17 - Building Real-World Web Applications
Chapter 18 useful
Joins are - Object-Relational
when you need Mapping in .NET
to select data from multiple tables based on selection criteria from more than
Chapter 19 -For
one table. Mapped Objects:
example, you Performance Considerations
want to select data from theand Data and
Orders Binding
Customers tables where the CustomerID
column20
Chapter in -the Customers
COM table exists
Interoperability in the CustomerID column of the Orders table as a foreign key. The
and ADO.NET
following
Chapter 21 statement returns you the result:
- Messaging
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Appendix
SELECTA DISTINCT
- Relational Databases: Some Basic Orders.CustomerID,
Orders.OrderID, Concepts Orders.EmployeeID,
Appendix B - Commonly Used SQL Customers.Address,
Customers.CompanyName, Statements Customers.City
FROM Customers
Appendix C - ADO.NET INNER JOIN
Frequently Orders
Asked ON Customers.CustomerID = Orders.CustomerID;
Questions
Index
List of Figures
The output of this statement looks like Figure B-13.
List of Tables
List of Listings
List of Sidebars
Table of Contents
Applied ADO.NETBuilding Data-Driven Solutions
Introduction
Chapter 1 - ADO.NET Basics
Chapter 2 - Data Components in Visual Studio .NET
Chapter 3 - ADO.NET in Disconnected Environments
Chapter 4 - ADO.NET in Connected Environments
Chapter 5 - Handling ADO.NET Events
Chapter 6 - Integrating XML with ADO.NET
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
Chapter 8 - Constraints and Data Relations
Chapter 9 - ADO.NET Exception Handling
Chapter 10 - Working with the ODBC .NET Data Provider
Chapter 11 - Stored Procedures and Views
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Chapter 13 - Developing a Custom Data Provider
Chapter 14 - Developing Database Web Applications using ASP.NET
Chapter 15 - Using ADO.NET in Xml Web Services
Chapter 16 - ASP.NET Server Controls and Data Binding
Chapter 17 - Building Real-World Web Applications
Chapter 18 - Object-Relational Mapping in .NET
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
Chapter 20 - COM Interoperability and ADO.NET
Chapter 21 - Messaging
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Appendix A - Relational Databases: Some Basic Concepts
Appendix B - Commonly Used SQL Statements
Appendix C - ADO.NET Frequently Asked Questions
Index
List of Figures
List of Tables
List of Listings
List of Sidebars
Using SQL Applied
Server's SELECT...FOR
ADO.NET: XML
Building Data-Driven Clause
Solutions
by Mahesh Chand and David Talbot ISBN:1590590732
Most of today's databases support
Apress 2003 Extensible Markup Language (XML). In SQL Server, for example, you
(928 pages)
can execute SQLThis queries to return results ascoverage
text provides extensive XML rather than standard
of ADO.NET rowsets. You can execute these
technology
queries directly orincluding
from within stored procedures. To retrieve results
ADO.NET internals, namespaces, classes, and directly, you use the FOR XML clause
interfaces,Within
of the SELECT statement. and takes a comprehensive
the FOR XML clause,look
you at XML one of three XML modes: RAW, AUTO,
specify
or EXPLICIT. (You namespaces and classes,
can also work anddata
with XML howintoAccess,
integrate both with
Oracle, MySQL, and other databases, but the
ADO.NET.
techniques vary.)
For example, this SQL Server SELECT statement retrieves information from the Customers and Orders
Table of Contents
tables in the Northwind database:
Applied ADO.NETBuilding Data-Driven Solutions
Introduction
SELECT
Chapter 1 Customers.CustomerID,
- ADO.NET Basics ContactName, CompanyName,
Chapter 2
Orders.CustomerID, OrderDate
- Data Components in Visual Studio .NET
FROM Customers, Orders
Chapter 3 - ADO.NET in Disconnected Environments
WHERE Customers.CustomerID = Orders.CustomerID
Chapter 4 - ADO.NET in Connected Environments
AND (Customers.CustomerID = "NALFKI"
Chapter 5 - Handling ADO.NET Events
OR Customers.CustomerID = "NXYZAA")
Chapter 6 - Integrating XML with ADO.NET
ORDER BY Customers.CustomerID
Chapter
FOR XML7 -AUTO
Data Binding and Windows Forms Data-Bound Controls
Chapter 8 - Constraints and Data Relations
Chapter 9 - ADO.NET Exception Handling
Chapter 10 - Working with the ODBC .NET Data Provider
Chapter 11 - Stored Procedures and Views
Understanding
Chapter 12 - Oracle, SQLXML, and Other .NET SQL Injection
Data Providers
Chapter 13 - Developing a Custom Data Provider
SQL injection is the process of using SQL queries and failing because of invalid user input. SQL
Chapter 14 - Developing Database Web Applications using ASP.NET
injection is usually caused by the code written by developers. For example, let's say a form has a
Chapter 15 - Using ADO.NET in Xml Web Services
TextBox1 control and developers use the text of TextBox1 as one of the SQL query variables:
Chapter 16 - ASP.NET Server Controls and Data Binding
Chapter 17 - Building Real-World Web Applications
string str = "SELECT * FROM Table WHERE Name ='"
Chapter 18 - Object-Relational Mapping in .NET
+ TextBox1.Text + "'";
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
Chapter 20 - COM Interoperability and ADO.NET
Chapter 21 what
Now, - Messaging
happens when Amie O'Donell enters her name in TextBox1? The execution of the SQL
Chapter
query -will
22 SQL failServer and of
because ADO.NET: Notes
invalid SQL on Performance
syntax. You have to be careful when building and executing
Appendix A -SQL
direct Relational Databases:
queries. You can Some
simplyBasic
avoidConcepts
this by checking if the user input has an invalid character in
Appendix
it. B - Commonly Used SQL Statements
Appendix C - ADO.NET Frequently Asked Questions
IndexAnother common scenario is when the database server is expecting a number value and the user
enters a string value or vice versa. This could lead to a failure if you don't have a check in the code.
List of Figures
For example, you could use the ToString method to make sure the input is a valid query (using the
List of Tables
Convert class to convert from one data type to another).
List of Listings
List of Sidebars
Summary Applied ADO.NET: Building Data-Driven Solutions
by Mahesh Chand and David Talbot ISBN:1590590732
In this appendix, we discussed
Apress some
2003 (928 commonly used SQL statements. You can access the following
pages)
resources online:This text provides extensive coverage of ADO.NET technology
including ADO.NET internals, namespaces, classes, and
"A Gentle Introduction
interfaces, to SQL"
and byaAndrew
takes Cumming:
comprehensive lookhttp://sqlzoo.net
at XML
namespaces and classes, and how to integrate both with
Microsoft SQL Server product documentation:
ADO.NET.
www.microsoft.com/sql/techinfo/productdoc/2000/default.asp
Table of Contents
Peter Gulutzan's Ocelot SQL site: www.ocelot.ca
Applied ADO.NETBuilding Data-Driven Solutions
"SQL Tutorial" at W3Schools: www.w3schools.com/sql/default.asp
Introduction
Chapter 1
"Trees- in
ADO.NET Basics
SQL" by Joe Celko: www.intelligententerprise.com/001020/celko1_1.shtml
Chapter 2 - Data Components in Visual Studio .NET
The
Chapter 3 SQL Tutorialinsite
- ADO.NET by Chuo-Han
Disconnected Lee: www.1keydata.com/sql/sql.html
Environments
Chapter 4 - ADO.NET in Connected Environments
Chapter 5 - Handling ADO.NET Events
Chapter 6 - Integrating XML with ADO.NET
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
Chapter 8 - Constraints and Data Relations
Chapter 9 - ADO.NET Exception Handling
Chapter 10 - Working with the ODBC .NET Data Provider
Chapter 11 - Stored Procedures and Views
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Chapter 13 - Developing a Custom Data Provider
Chapter 14 - Developing Database Web Applications using ASP.NET
Chapter 15 - Using ADO.NET in Xml Web Services
Chapter 16 - ASP.NET Server Controls and Data Binding
Chapter 17 - Building Real-World Web Applications
Chapter 18 - Object-Relational Mapping in .NET
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
Chapter 20 - COM Interoperability and ADO.NET
Chapter 21 - Messaging
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Appendix A - Relational Databases: Some Basic Concepts
Appendix B - Commonly Used SQL Statements
Appendix C - ADO.NET Frequently Asked Questions
Index
List of Figures
List of Tables
List of Listings
List of Sidebars
AppendixApplied
C: ADO.NET:
ADO.NET Frequently
by Mahesh Chand and David Talbot
Asked Questions
Building Data-Driven Solutions
ISBN:1590590732
Apress 2003 (928 pages)
Overview This text provides extensive coverage of ADO.NET technology
including ADO.NET internals, namespaces, classes, and
In this appendix, we'll answer
interfaces, some
and takesofathe commonly asked
comprehensive look atquestions
XML related to ADO.NET. Most of these
namespaces
questions were originally andon
asked classes, and how
C# Corner to integrate
discussion forumsboth with
(www.c-sharpcorner.com) or other
ADO.NET.
newsgroups.
Q: FAQ 16: How can I obtain ODBC Data Source Names (DSNs)?
Q: FAQ 17: How can I read and write bitmaps or BLOB data?
Q: FAQ 18: What are DiffGrams and how do they relate to DataSets? How do I
read and write DiffGrams using a DataSet?
TheGetSchemaTable method returns meta-data about each column. Table C-1 defines the metadata
and column order.
Table of Contents
or you
Applied can use the following:
ADO.NETBuilding Data-Driven Solutions
Introduction
Chapter 1 - ADO.NET Basics
dataGrid1.DataSource = ds.Tables[index];
Chapter 2 - Data Components in Visual Studio .NET
Chapter 3 - ADO.NET in Disconnected Environments
A: The4Columns
Chapter property
- ADO.NET of a DataTable
in Connected represents a collection of columns in a DataTable. You can get
Environments
aDataColumn
Chapter 5
from this collection by using a column index or the name of the column. Setting the
- Handling ADO.NET Events
Visible property to false hides a column, and setting it to true displays the column:
Chapter 6 - Integrating XML with ADO.NET
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
DataTable.Columns(index).Visible
Chapter 8 - Constraints and Data Relations = false;
Chapter 9 - ADO.NET Exception Handling
Chapter 10 - Working with the ODBC .NET Data Provider
A: The following code shows how to construct a SQL statement with date values in it. You can simply execute
Chapter 11 - Stored Procedures and Views
this query:
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Chapter 13 - Developing a Custom Data Provider
Dim sql As String = "INSERT INTO Table (col1, [date], col2)" & _
Chapter 14 - Developing Database Web Applications using ASP.NET
" VALUES(4588, #01/02/02#, 'some value')"
Chapter 15 - Using ADO.NET in Xml Web Services
Chapter 16 - ASP.NET Server Controls and Data Binding
Chapter 17common
A: It's a - Building Real-World
need Webwant
when you Applications
to find out how many columns (and their names and data types) that a
Chapter 18 - Object-Relational
DataSet or a DataTable Mapping in .NET
contains. You can get DataTable columns through the Columns property,
Chapter 19 returns
which - MappedallObjects:
columnsPerformance Considerations
as a collection. and has
If a DataSet Datamultiple
Binding tables, you use the DataSet.Tables
Chapter 20 - COM
property, Interoperability
which and ADO.NET
returns a collection of DataTable objects as a collection of DataTables. To get a
Chapter from a collection, you can either use the table name or use the table index.
21 - Messaging
DataTable
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Once you get a collection of columns of a DataTable, you can read each column one by one and get
Appendix A - Relational Databases: Some Basic Concepts
DataColumn member values. To find out the data type of a DataColumn, you can use the DataType
Appendix B - Commonly Used SQL Statements
property. If you want to compare whether a column is a string, integer, or other type, you can compare its
Appendix C - ADO.NET Frequently Asked Questions
DataType property with Type.GetType().
Index
List ofListing
Figures
C-2 reads a DataTable's columns and checks if a column is a string type.
List of Tables
List ofListing
ListingsC-2: ReadingDataSet Columns and Their Data Types
List of Sidebars
' Add Table columns to the dropdownlistbox
Dim cols As DataColumnCollection = ds.Tables(0).Columns
Dim col As DataColumn
For Each col In cols
searchDropDown.Items.Add(col.ColumnName)
' add only string type columns, otherwise
If (col.DataType Is Type.GetType("System.String")) Then
' do something
Else
' else do something
End If
Next
Applied ADO.NET: Building Data-Driven Solutions
by Mahesh Chand and David Talbot ISBN:1590590732
Apress 2003 (928 pages)
This a
A: Each control has text provides extensiveobject
BindingManager coverage of ADO.NET
associated withtechnology
it. You can use the Count property of
including
BindingManager: ADO.NET internals, namespaces, classes, and
interfaces, and takes a comprehensive look at XML
namespaces and classes, and how to integrate both with
Dim rowsADO.NET.
As Integer = _
dtGrid.BindingContext(dtGrid.DataSource, _
dtGrid.DataMember).Count
Table of Contents
Applied ADO.NETBuilding Data-Driven Solutions
Introduction
A: Paging is a processing of fetching a number of rows as a page (a subset of data) instead of all rows from a
Chapter
data1 source.
- ADO.NET
You Basics
can achieve paging in two ways in ADO.NET: by using a DataAdapter and by using a
Chapter
SQL 2 statement.
- Data Components in Visual Studio .NET
Chapter 3 - ADO.NET in Disconnected Environments
Paging
Chapter 4 - Using a DataAdapter
ADO.NET in Connected Environments
Chapter 5 - Handling ADO.NET Events
TheFill method of DataAdapter provides an overloaded form where you can ask the DataAdapter to
Chapter 6 - Integrating XML with ADO.NET
return only a selected number of rows in a DataSet. The overloaded form of the Fill method is as
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
follows:
Chapter 8 - Constraints and Data Relations
Chapter 9 - ADO.NET Exception Handling
Overloads Public Function Fill(ByVal dataSet As DataSet, _
Chapter 10 - Working with the ODBC .NET Data Provider
ByVal startRecord As Integer, _
Chapter 11 - Stored Procedures and Views
ByVal maxRecords As Integer, _
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
ByVal srcTable As String _
Chapter
) As13 -Integer
Developing a Custom Data Provider
Chapter 14 - Developing Database Web Applications using ASP.NET
Chapter 15 - Using ADO.NET in Xml Web Services
where
Chapter - ASP.NET is
16 dataSet a DataSet
Server Controlstoand
fill with
Datarecords
Binding and, if necessary, schema; startRecord is the zero-
based
Chapter 17 -record number
Building to start
Real-World Webwith; maxRecords is the maximum number of records to retrieve; and
Applications
srcTable
Chapter is the name ofMapping
18 - Object-Relational the source table to use for table mapping. Listing C-3 shows a function that
in .NET
returns
Chapter 19 - aMapped
DataSet filled Performance
Objects: with the records based on the
Considerations andpage
Data size passed in the method.
Binding
Chapter 20 - COM Interoperability and ADO.NET
Listing C-3: GetPageData Method
Chapter 21 - Messaging
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Function
Appendix GetPagedData(ByVal
A - Relational daConcepts
Databases: Some Basic As SqlDataAdapter, _
ByVal idx As Integer, ByVal size As Integer) As DataSet
Appendix B - Commonly Used SQL Statements
Dim ds As DataSet = New DataSet()
Appendix C - ADO.NET Frequently Asked Questions
Try
Index
da.Fill(ds, idx, size, "Orders")
List of Figures
Catch e As Exception
List of Tables
MessageBox.Show(e.Message.ToString())
List of Listings
End Try
List of Sidebars
Return ds
End Function
Besides the Fill method of a DataAdapter, you can even use a SELECT SQL statement to retrieve the
number of records from a table. You use the SELECT TOP statement for this purpose. The following
statement selects the top 10 records from the Customers table. You set the SELECT statement as the
SELECT TOP statement:
"SELECT TOP 10 CustomerID, CompanyName, " & _
Applied ADO.NET:
" ContactName FROMBuilding Data-Driven
Customers ORDER Solutions
BY CustomerID"
by Mahesh Chand and David Talbot ISBN:1590590732
Apress 2003 (928 pages)
ImplementingThis
Paging
text provides extensive coverage of ADO.NET technology
including ADO.NET internals, namespaces, classes, and
interfaces,
Finally, let's see and takes
how to use a comprehensive
both the look at XML
previously discussed methods to implement paging in ADO.NET. The
namespaces
sample application and Figure
looks like classes,C-1.
and In
how
thistofigure,
integrate
youboth
can with
enter the number of rows you want to load
ADO.NET.
in a page. The Load Page button loads the first page. The Previous Page and Next Page buttons load those
pages from database. When you check the SELECT TOP check box, the program uses the SELECT TOP
Tablemethod; otherwise, it uses the DataAdapter'sFill method.
of Contents
Applied ADO.NETBuilding Data-Driven Solutions
Introduction
Chapter 1 - ADO.NET Basics
Chapter 2 - Data Components in Visual Studio .NET
Chapter 3 - ADO.NET in Disconnected Environments
Chapter 4 - ADO.NET in Connected Environments
Chapter 5 - Handling ADO.NET Events
Chapter 6 - Integrating XML with ADO.NET
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
Chapter 8 - Constraints and Data Relations
Chapter 9 - ADO.NET Exception Handling
Chapter 10 - Working with the ODBC .NET Data Provider
Chapter 11 - Stored Procedures and Views
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Chapter 13 - Developing a Custom Data Provider
Figure C-1: Paging in an ADO.NET application
Chapter 14 - Developing Database Web Applications using ASP.NET
Chapter 15 - Using ADO.NET in Xml Web Services
Listing C-4 implements paging using both methods. As you can see from this code, the Load Page button
Chapter
click16event
- ASP.NET Server
handler Controls
reads andsize,
the page Datacreates
Bindingand opens a new connection, and checks whether the
Chapter 17 - Building Real-World Web Applications
SELECT TOP check box is checked. If it is, it calls the GetTopData method; otherwise, it calls the
Chapter 18 - Object-Relational
GetPagedData method.Mapping in .NET
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
Listing
Chapter 20 - C-4:
COM Implementing
Interoperability Paging in ADO.NET
and ADO.NET
Chapter 21 - Messaging
Chapter 22 - SQLSub
Private Server and ADO.NET: Notes on Performance
LoadPageBtn_Click(ByVal sender As System.Object, _
Appendix A - Relational Databases:
ByVal e As System.EventArgs) Some BasicHandles
Concepts LoadPageBtn.Click
Appendix B - Commonly
pageSize Used SQL Statements
= Convert.ToInt32(TextBox1.Text.ToString())
' CCreate
Appendix and
- ADO.NET open aAsked
Frequently connection
Questions
Index conn = New SqlConnection(connectionString)
conn.Open()
List of Figures
' Find out total number of records
List of Tables
Dim cmd As SqlCommand = New SqlCommand()
List of Listings
' Assign the SQL Insert statement we want to execute to the CommandText
List of Sidebars
cmd.CommandText = "SELECT Count(*) FROM Customers"
cmd.Connection = conn
' Call ExecuteNonQuery on the Command Object to execute insert
totalRecords = cmd.ExecuteScalar()
' Create data adapter
sql = "SELECT CustomerID, CompanyName, ContactName " & _
"FROM Customers ORDER BY CustomerID"
adapter = New SqlDataAdapter(sql, conn)
ds = New DataSet()
' If SELECT TOP check box is checked
If CheckBox1.Checked Then
selectTop = True
Else
Applied
selectTop = ADO.NET:
False Building Data-Driven Solutions
End If by Mahesh Chand and David Talbot ISBN:1590590732
Apress 2003 (928 pages)
This text
' if SELECT TOPprovides extensive coverage of ADO.NET technology
is checked
including
If selectTop Then ADO.NET internals, namespaces, classes, and
interfaces, and takes a comprehensive look at XML
GetTopData("",
namespaces and0) classes, and how to integrate both with
DataGrid1.DataSource
ADO.NET. = custTable
Else
ds = GetPagedData(adapter, curIndex, pageSize)
Table of Contents
curIndex = curIndex + pageSize
Applied ADO.NETBuilding Data-Driven Solutions
DataGrid1.DataSource = ds.DefaultViewManager
Introduction
End If
Chapter
End1 Sub
- ADO.NET Basics
Chapter 2 - Data Components in Visual Studio .NET
' Get
Chapter a page in
3 - ADO.NET using SELECT
Disconnected TOP statement
Environments
Public
Chapter Sharedin Sub
4 - ADO.NET GetTopData(ByVal
Connected Environments selectCmd As String, ByVal type As Integer)
Chapter '5 First time
- Handling load Events
ADO.NET first TOP pages
Chapter If
6 -(selectCmd.Equals(String.Empty))
Integrating XML with ADO.NET Then
Chapter 7 selectCmd
- Data Binding= and
"SELECT
WindowsTOP " Data-Bound
Forms & pageSize & " CustomerID, CompanyName, " & _
Controls
Chapter 8
"- Constraints
ContactName FROM Customers ORDER BY CustomerID"
and Data Relations
End If
Chapter 9 - ADO.NET Exception Handling
Chapter 10 - Working with the ODBC .NET Data Provider
totalPages = CInt(Math.Ceiling(CDbl(totalRecords) / pageSize))
Chapter 11 - Stored Procedures and Views
adapter.SelectCommand.CommandText = selectCmd
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Dim tmpTable As DataTable = New DataTable("Customers")
Chapter Dim
13 - Developing a Custom Data
recordsAffected As Provider
Integer = adapter.Fill(tmpTable)
Chapter '14If - Developing
the table does notApplications
Database Web exist, using ASP.NET
create it.
Chapter If15 -custTable
Using ADO.NET in Xml Web Services
Is Nothing Then custTable = tmpTable.Clone()
Chapter '16Refresh
- ASP.NET the
Server Controls
table ifand
atData Binding
least one record is returned.
Chapter If17 -recordsAffected
Building Real-World Web Applications
> 0 Then
Chapter 18Select
- Object-Relational
Case type Mapping in .NET
Case 1Objects: Performance Considerations and Data Binding
Chapter 19 - Mapped
Chapter 20 - COM currentPage
Interoperability=and
currentPage
ADO.NET + 1
Case 2
Chapter 21 - Messaging
Chapter 22 - SQLcurrentPage = currentPage
Server and ADO.NET: - 1
Notes on Performance
Case Else
Appendix A - Relational Databases: Some Basic Concepts
currentPage = 1
Appendix B - Commonly Used SQL Statements
End Select
Appendix C - ADO.NET Frequently Asked Questions
' Clear the rows and add new results.
Index
custTable.Rows.Clear()
List of Figures
' Import rows from temp tabke to custTable
List of Tables
Dim myRow As DataRow
List of Listings
For Each myRow In tmpTable.Rows
List of SidebarscustTable.ImportRow(myRow)
Next
' Preserve the first and last primary key values.
Dim ordRows() As DataRow = custTable.Select("", "CustomerID ASC")
firstVisibleCustomer = ordRows(0)(0).ToString()
lastVisibleCustomer = ordRows(custTable.Rows.Count - 1)(0).ToString()
End If
End Sub
For example, in a banking application where funds are transferred from one account to another, one
account is credited an amount and another account is debited the same amount simultaneously. Because
computers can fail because of power outages, network outages, and so on, it's possible to update a row in
one table but not in the related table. If your database supports transactions, you can group database
operations into a transaction to prevent database inconsistency resulting from these outages.
In ADO.NET, the Connection and Transaction objects handle transactions. Follow these steps to
1.
perform transactions:
Appliedan
1. After creating ADO.NET:
instance Building Data-Driven
of a Connection Solutions
class (no matter what data provider you choose), you
by Mahesh Chand and David Talbot ISBN:1590590732
call the BeginTransaction method to start a transaction. The BeginTransaction method
Apress 2003 (928 pages)
returns a Transaction object:
This text provides extensive coverage of ADO.NET technology
including ADO.NET internals, namespaces, classes, and
Dim tran As OleDbTransaction
interfaces, = conn.BeginTransaction()
and takes a comprehensive look at XML
namespaces and classes, and how to integrate both with
ADO.NET.
2. Create Command objects with the active transaction, set its Transaction property as the current
transaction, and call its Execute method:
Table of Contents
Applied ADO.NETBuilding Data-Driven Solutions
Dim cmd As OleDbCommand = New OleDbCommand()
Introduction
cmd.Connection = conn
Chapter 1 - ADO.NET Basics
cmd.Transaction = tran
Chapter 2 - Data Components in Visual Studio .NET
Chapter 3 - ADO.NET in Disconnected Environments
3. -Call
Chapter 4 the Commit
ADO.NET and Rollback
in Connected methods to commit and roll back transactions using this code:
Environments
Chapter 5 - Handling ADO.NET Events
Chapter 6 -tran.Commit()
Integrating XML with ADO.NET
Chapter 7 -tran.Rollback()
Data Binding and Windows Forms Data-Bound Controls
Chapter 8 - Constraints and Data Relations
Chapter 9 - ADO.NET Exception Handling
Chapter 10 - Working with the ODBC .NET Data Provider
Chapter 11 -Listing
StoredC-5 shows you
Procedures andhow to use transactions in the OleDb data provider.
Views
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Listing C-5: Transactions in the OleDb Data Provider
Chapter 13 - Developing a Custom Data Provider
Chapter 14 - Developing Database Web Applications using ASP.NET
Chapter 15 - Using ADO.NET in Xml Web Services
Chapter 16 Sub
- ASP.NET Server Controls and Data Binding
Main()
Chapter 17 Dim
- Building Real-World
str As String Web Applications
Chapter 18 Dim
- Object-Relational Mapping inAs
connectionString .NET
String = _
Chapter 19 - Mapped Objects: Performance Considerations and DataData
"Provider=Microsoft.Jet.OLEDB.4.0; Binding
Source=F:\\AppliedAdoNet.mdb"
Chapter 20 '- COM Interoperability
Create and open and
a ADO.NET
connection
Chapter 21 Dim
- Messaging
conn As OleDbConnection = _
NewServer
Chapter 22 - SQL OleDbConnection(connectionString)
and ADO.NET: Notes on Performance
Appendix A conn.Open()
- Relational Databases: Some Basic Concepts
Appendix B '- Commonly
Start a Used
transaction
SQL Statements
Appendix C Dim tran Frequently
- ADO.NET As OleDbTransaction
Asked Questions = conn.BeginTransaction()
Index Dim cmd As OleDbCommand = New OleDbCommand()
List of
cmd.Connection = conn
Figures
cmd.Transaction = tran
List of Tables
Try
List of Listings
str = "INSERT INTO Users (UserName, UserDescription)" & _
List of Sidebars
" VALUES ('New User', 'New Description')"
cmd.CommandText = str
cmd.ExecuteNonQuery()
str = "UPDATE Users SET UserName = 'Updated User' WHERE " & _
" UserName = 'New User'"
cmd.CommandText = str
cmd.ExecuteNonQuery()
str = "DELETE * FROM Users WHERE UserName = 'Updated User'"
cmd.CommandText = str
cmd.ExecuteNonQuery()
' Commit transaction
tran.Commit()
Console.WriteLine("Changes saved.")
Applied
Catch e ADO.NET:
As ExceptionBuilding Data-Driven Solutions
by Mahesh Chand and
' Rollback transaction David Talbot ISBN:1590590732
Apress 2003 (928
tran.Rollback() pages)
This text provides extensive coverage of ADO.NET technology
Console.WriteLine(e.Message.ToString())
including ADO.NET internals, namespaces,
Console.WriteLine("No changesclasses,
were andmade to database.")
interfaces, and takes a comprehensive look at XML
Finally
namespaces and classes, and how to integrate both with
conn.Close()
ADO.NET.
conn.Dispose()
End Try
Table of Contents
End Sub
Applied ADO.NETBuilding Data-Driven Solutions
Introduction
Chapter 1 - ADO.NET Basics
Chapter 2 - Data Components
A: Auto-incrementing columnsin Visual Studio .NET
are columns whose value increases automatically when a new record is added
to the
Chapter 3 table. To create
- ADO.NET an auto-incrementing
in Disconnected Environmentscolumn, you set the DataColumn.AutoIncrement property
totrue.
Chapter The DataColumn
4 - ADO.NET willEnvironments
in Connected then start with the value defined in the AutoIncrementSeed property,
and5with
Chapter each rowADO.NET
- Handling added, Events
the value of the AutoIncrement column increases by the value held in the
AutoIncrementStep
Chapter property
6 - Integrating XML with of the column:
ADO.NET
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
Dim8 col1
Chapter As DataColumn
- Constraints =
and Data Relations
DataTable.Columns.Add("CustomerID",
Chapter 9 - ADO.NET Exception Handling typeof(Int32))
workColumn.AutoIncrement = true
Chapter 10 - Working with the ODBC .NET Data Provider
workColumn.AutoIncrementSeed
Chapter 11 - Stored Procedures and Views = 1000
workColumn.AutoIncrementStep = 10Providers
Chapter 12 - Oracle, SQLXML, and Other .NET Data
Chapter 13 - Developing a Custom Data Provider
Chapter 14 - Developing Database Web Applications using ASP.NET
A: There are occasions when you don't want to mess with the original DataSet's data and instead want to
Chapter 15 - Using ADO.NET in Xml Web Services
copy data somewhere and work with it. The DataSet provides a Copy method that you can use to copy the
Chapter
data16of- aASP.NET
DataSet Server
to a Controls and Data Binding
second DataSet. When you copy data, you can copy in different ways: You can
Chapter 17 - Building Real-World Web Applications
create an exact copy of a DataSet including its schema, data, row state information, and row versions. You
Chapter
can18 - Object-Relational
also copy only affectedMapping in a
rows of .NET
DataSet to a second DataSet. Another case may be when you only
Chapter
want19to- copy
Mapped Objects: Performance
a DataSet schema, notConsiderations
the data. and Data Binding
Chapter 20 - COM Interoperability and ADO.NET
To create
Chapter an exact copy of the DataSet including a DataSet schema and data, you can use the Copy
21 - Messaging
method.
Chapter For Server
22 - SQL example:
and ADO.NET: Notes on Performance
Appendix A - Relational Databases: Some Basic Concepts
Dim Bds2
Appendix As DataSet
- Commonly = Statements
Used SQL ds1.Copy()
Appendix C - ADO.NET Frequently Asked Questions
Index
TheGetChanges method gets the affected rows of a DataSet. The GetChanges method takes a
List of Figures
DataRowState object, which has members including Added,Modified, and Deleted. Using this
List of Tables
method, you can create a new DataSet from an existing DataSet with all rows that have been modified,
List of Listings
or you can specify new added, deleted, or modified rows.
List of Sidebars
To create a copy of a DataSet that includes schema and only the data representing the Added,
Modified, or Deleted rows, use the GetChanges method of the DataSet. You can also use
GetChanges to return only rows with a specified row state by passing a DataRowState value when
calling GetChanges. The following code shows how to pass a DataRowState when calling
GetChanges:
Table of Contents
Applied ADO.NETBuilding
A: Getting the number ofData-Driven Solutions
records using a DataSet is pretty simple. A DataSet is a set of DataTable
Introduction
objects, and a DataTable'sRows property represents the number of records in a DataTable. The
following
Chapter code retrieves
1 - ADO.NET Basics the number of rows of the first table of a DataSet. Similarity, you can retrieve the
number
Chapter of records
2 - Data from other
Components tables
in Visual if a DataSet
Studio .NET contains more than one DataTable object:
Chapter 3 - ADO.NET in Disconnected Environments
Chapter
Dim4 ds
- ADO.NET in Connected
As DataSet = New Environments
DataSet()
Chapter 5 - Handling ADO.NET
adapter.Fill(ds, Events
"Employees")
Chapter
Dim6 counter
- Integrating
AsXML with ADO.NET
Integer = ds.Tables(0).Rows.Count
MessageBox.Show(counter.ToString())
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
Chapter 8 - Constraints and Data Relations
Chapter 9 - ADO.NET Exception Handling
Retrieving the number of records using a DataReader is little tricky. You use the SELECT Count * SQL
Chapter 10 - Working with the ODBC .NET Data Provider
statement and execute the SQL statement using the ExecuteScalar method of the Command object. The
Chapter 11 - Stored Procedures and Views
following code returns the number of records using the Count * statement:
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Chapter 13 - Developing a Custom Data Provider
Dim cmd As OleDbCommand = _
Chapter 14 - Developing Database Web Applications using ASP.NET
New OleDbCommand("SELECT Count(*) FROM Orders", conn)
Chapter 15 - Using ADO.NET in Xml Web Services
Dim counter As Integer = CInt(cmd.ExecuteScalar())
Chapter 16 - ASP.NET Server Controls and Data Binding
MessageBox.Show(counter.ToString())
Chapter 17 - Building Real-World Web Applications
Chapter 18 - Object-Relational Mapping in .NET
Chapter 19 - when
A: Usually Mapped Objects:
you Performance
work with Considerations
databases, you already and
knowData
theBinding
database schema such as database tables,
Chapter 20columns,
table - COM Interoperability and ADO.NET
and column properties. What if you don't know the database schema, and you need to get a
Chapter 21 - Messaging
database's tables, columns, and column properties programmatically?
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
In this
Appendix A sample we show
- Relational you how
Databases: to access
Some a database schema programmatically. As you can see from
Basic Concepts
Figure C-2, we created a Windows application with one TextBox control, three Button controls, and two
Appendix B - Commonly Used SQL Statements
ListBox controls. The Browse button lets you browse .mdb databases on your machine. The Get Tables
Appendix C - ADO.NET Frequently Asked Questions
button then reads the database tables and adds them to the first list box. The Get Table Schema button
Index
returns the table columns and the properties of the selected table in list box.
List of Figures
List of Tables
List of Listings
List of Sidebars
TableListing
of Contents
C-8 shows the GetSchemaBn_Click event handler that returns the columns and properties of a
Applied ADO.NETBuilding
database Data-Driven
table. You read Solutions
the database table using SELECT * and use a DataTable to get columns. The
DataColumn class defines the member for a table column properties such as allow null, auto number,
Introduction
unique,
Chapter 1 - column
ADO.NETdata type, column name, and so on.
Basics
Chapter 2 - Data Components in Visual Studio .NET
Listing
Chapter 3 - C-8: Getting
ADO.NET a DatabaseEnvironments
in Disconnected Table Schema
Chapter 4 - ADO.NET in Connected Environments
Private
Chapter Sub GetTableSchema_Click(ByVal
5 - Handling ADO.NET Events sender As System.Object, _
Chapter ByVal e As System.EventArgs)
6 - Integrating XML with ADO.NET Handles GetTableSchema.Click
Chapter 7 '- Data
Get Binding
the selected item
and Windows text
Forms of list
Data-Bound box
Controls
Chapter 8 Dim selTable
- Constraints and As
DataString
Relations= ListBox1.GetItemText(ListBox1.SelectedItem)
Chapter 9 '- ADO.NET
Connection string
Exception Handling
Dim strDSN As String = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
Chapter 10 - Working with the ODBC .NET Data Provider
"Data Source=" + dbName
Chapter 11 - Stored Procedures and Views
' Create and open connection
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Dim conn As OleDbConnection = New OleDbConnection(strDSN)
Chapter 13 - Developing a Custom Data Provider
Try
Chapter 14 - Developing Database Web Applications using ASP.NET
conn.Open()
Chapter 15 - Using ADO.NET in
Dim strSQL AsXml Web Services
String = "SELECT * FROM " + selTable
Chapter 16 - ASP.NET Server Controls
' Create data adapter and Data Binding
Chapter 17 - Building Real-World
Dim adapter AsWeb Applications
OleDbDataAdapter = New OleDbDataAdapter(strSQL, conn)
Chapter 18 - Object-Relational
' Create and Mapping in .NETset
fill data
Chapter 19 - Mapped
Dim dtSetObjects:
AsPerformance
DataSet = Considerations and Data Binding
New DataSet()
Chapter 20 - COM Interoperability and ADO.NET
adapter.Fill(dtSet)
Chapter Dim dt As DataTable = dtSet.Tables(0)
21 - Messaging
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
' Add items
Appendix A - Relational to the
Databases: Somelist box control
Basic Concepts
ListBox2.Items.Add("Column
Appendix B - Commonly Used SQL Statements Name, DataType, Unique," & _
" AutoIncrement,
Appendix C - ADO.NET Frequently Asked Questions AllowNull")
Index
ListBox2.Items.Add("=====================================")
Dim i As Integer
List of Figures
For i = 0 To dt.Columns.Count - 1
List of Tables
Dim dc As DataColumn
List of Listings
dc = dt.Columns(i)
List of Sidebars
ListBox2.Items.Add(dc.ColumnName.ToString() + _
" , " + dc.DataType.ToString() + _
" ," + dc.Unique.ToString() + " ," + dc.AutoIncrement.ToString() & _
" ," + dc.AllowDBNull.ToString())
Next
.NET Framework Library provides two classes (Registry and RegistryKey) to work with the Registry.
Note The Registry classes are defined in the Microsoft.Win32 namespace. Before using these
classes, you need to add a reference to this namespace.
TheRegistry class contains members to provides access to Registry keys. Table C-2 described the
Registry class members.
Applied ADO.NET: Building Data-Driven Solutions
by Registry
Table C-2: The Mahesh Chand andMembers
Class David Talbot ISBN:1590590732
Apress 2003 (928 pages)
MEMBER DESCRIPTION
This text provides extensive coverage of ADO.NET technology
including ADO.NET internals, namespaces, classes, and
CurrentUser Stores
interfaces, and takesinformation aboutlook
a comprehensive useratpreferences
XML
namespaces and classes, and how to integrate both with
LocalMachine
ADO.NET. Stores configuration information for the local machine
ClassesRoot Stores information about types (and classes) and their properties
Table of Contents
Users Stores information about the default user configuration
Applied ADO.NETBuilding Data-Driven Solutions
PerformanceData
Introduction Stores performance information for software components
Chapter 1 - ADO.NET Basics
CurrentConfig Stores non-user-specific hardware information
Chapter 2 - Data Components in Visual Studio .NET
DynData
Chapter 3 Stores dynamic
- ADO.NET in Disconnected data
Environments
Chapter 4 - ADO.NET in Connected Environments
For example, if you want to access the HKEY_LOCAL_MACHINE key, you need to call the
Chapter 5 - Handling ADO.NET Events
Registry.LocalMachine member, which returns a RegistryKey type:
Chapter 6 - Integrating XML with ADO.NET
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
RegistryKey
Chapter pRegKey
8 - Constraints and Data=Relations
Registry.LocalMachine;
Chapter 9 - ADO.NET Exception Handling
Chapter 10 - Working with the ODBC .NET Data Provider
Using the RegistryKey Class
Chapter 11 - Stored Procedures and Views
The12
Chapter RegistryKey classand
- Oracle, SQLXML, contains
Other members to add, remove, replace, and read Registry data. Table C-3
.NET Data Providers
defines
Chapter 13 - some of its acommon
Developing properties.
Custom Data Provider
Chapter 14 - Developing Database Web Applications using ASP.NET
Table
Chapter 15 -C-3: The
Using RegistryKey
ADO.NET Class
in Xml Web Properties
Services
Chapter 16 - ASP.NET Server Controls and Data Binding
PROPERTY DESCRIPTION
Chapter 17 - Building Real-World Web Applications
Name
Chapter 18 - Object-Relational Mapping in .NET Name of the key
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
SubKeyCount Number of children of the key
Chapter 20 - COM Interoperability and ADO.NET
ValueCount
Chapter 21 - Messaging Count of values in the key
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Table
Appendix A C-4 describes
- Relational the RegistryKey
Databases: Some Basic class methods.
Concepts
Appendix B - Commonly Used SQL Statements
Table
Appendix C -C-4: The RegistryKey
ADO.NET Class
Frequently Asked Methods
Questions
Index
List of Figures
List of Tables
List of Listings
List of Sidebars
METHOD DESCRIPTION
Applied ADO.NET: Building Data-Driven Solutions
by Mahesh Chand and David Talbot ISBN:1590590732
Close Closes the key
Apress 2003 (928 pages)
CreateSubKey Creates
This text provides a new
extensive subkey of
coverage if not in existence
ADO.NET or opens it
technology
including ADO.NET internals, namespaces, classes, and
interfaces, andDeletes
DeleteSubKey takes a a subkey
comprehensive look at XML
namespaces and classes, and how to integrate both with
DeleteSubKeyTree
ADO.NET. Deletes subkey and its children
DeleteValue Deletes the value of a key
Table of Contents
GetSubKeyName Returns an array of strings that contains all the subkey names
Applied ADO.NETBuilding Data-Driven Solutions
GetValue
Introduction Returns the value of a subkey
Chapter 1 - ADO.NET Basics
GetValueName Retrieves an array of strings that contains all the value names associated
Chapter 2 - Data Components inwith
Visual Studio .NET
a key
Chapter 3 - ADO.NET in Disconnected Environments
OpenSubKey
Chapter 4 Opens
- ADO.NET in Connected a subkey
Environments
Chapter 5 - Handling ADO.NET Events
SetValue Sets the value of a subkey
Chapter 6 - Integrating XML with ADO.NET
Chapter 7 - Data
Adding a KeyBinding and Windows
and Value Forms Data-Bound Controls
to Registry
Chapter 8 - Constraints and Data Relations
Let's
Chapter 9 see how to add
- ADO.NET data toHandling
Exception the Registry. You use CreateSubKey to add a new key to the Registry and
call the SetValue method to write a value and key. The following code does this:
Chapter 10 - Working with the ODBC .NET Data Provider
Chapter 11 - Stored Procedures and Views
' Create
Chapter a new
12 - Oracle, keyand
SQLXML, under
Other HKEY_LOCAL_MACHINE\Software
.NET Data Providers as MCBInc
Dim13key
Chapter As RegistryKey
- Developing = Provider
a Custom Data Registry.LocalMachine.OpenSubKey("Software", True)
' Add
Chapter one moreDatabase
14 - Developing sub key
Web Applications using ASP.NET
Dim newkey As RegistryKey = key.CreateSubKey("MCBInc")
Chapter 15 - Using ADO.NET in Xml Web Services
' Set value of sub key
Chapter 16 - ASP.NET Server Controls and Data Binding
newkey.SetValue("MCBInc", "NET Developer")
Chapter 17 - Building Real-World Web Applications
Chapter 18 - Object-Relational Mapping in .NET
Chapter 19 - Mapped
Retrieving DataObjects:
from thePerformance
Registry Considerations and Data Binding
Chapter 20 - COM Interoperability and ADO.NET
Now
Chapter 21let's see how to use these remove the keys and their values from the Registry.
- Messaging
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
TheGetValue method returns the value of a subkey in the form of Object. The following code reads the
Appendix A - Relational Databases: Some Basic Concepts
value of the CenteralProcessor\0 subkey and writes it to the console:
Appendix B - Commonly Used SQL Statements
Appendix C - ADO.NET Frequently Asked Questions
' Retrieve data from other part of the registry
Index
' find out your processor
List of Figures
Dim pRegKey As RegistryKey = Registry.LocalMachine
List of Tables
pRegKey =
List of pRegKey.OpenSubKey("HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\0")
Listings
List ofDim
Sidebars
val As Object = pRegKey.GetValue("VendorIdentifier")
Console.WriteLine("The central processor of this machine is:" + val)
Deleting Data
You can use the DeleteValue method to delete the value of a subkey. DeleteSubKey deletes the
defined subkey. DeleteSubKey deletes the subkey with its data:
To make the application a little more interactive and user friendly, we created a Windows application, added
aTextBox control, three Button controls, and a PictureBox control. The final form looks like Figure C-
4. As you can pretty much guess from this figure, the Browse Image button allows users to browse for
bitmap files. The Save Image button saves opened file in the database, and the Read Image button reads
the first row of the database table, saves binary data as a bitmap, and displays the image in a PictureBox
control.
Applied ADO.NET: Building Data-Driven Solutions
by Mahesh Chand and David Talbot ISBN:1590590732
Apress 2003 (928 pages)
This text provides extensive coverage of ADO.NET technology
including ADO.NET internals, namespaces, classes, and
interfaces, and takes a comprehensive look at XML
namespaces and classes, and how to integrate both with
ADO.NET.
Table of Contents
Applied ADO.NETBuilding Data-Driven Solutions
Introduction
Chapter 1 - ADO.NET Basics
Chapter 2 - Data Components in Visual Studio .NET
Chapter 3 - ADO.NET in Disconnected Environments
Figure C-4: Reading and writing images in a database final form
Chapter 4 - ADO.NET in Connected Environments
Chapter 5 -writing
Before Handling ADO.NET
code on the Events
button clicks, define following variables:
Chapter 6 - Integrating XML with ADO.NET
Chapter 7 - Data
' User Binding variables
defined and Windows Forms Data-Bound Controls
Chapter Private
8 - Constraints and Data
curImage AsRelations
Image = Nothing
Chapter Private
9 - ADO.NET Exception Handling
curFileName As String = Nothing
Chapter Private
10 - Working with the ODBC .NET Data
connectionString As Provider
String = _
Chapter 11"Provider=Microsoft.Jet.OLEDB.4.0;
- Stored Procedures and Views " & _
Chapter 12"Data Source=C:\\AppliedAdoNet.mdb"
- Oracle, SQLXML, and Other .NET Data Providers
Chapter Private savedImageName
13 - Developing As String _
a Custom Data Provider
Chapter 14=- Developing
"C:\\ImageFromDb.BMP"
Database Web Applications using ASP.NET
Chapter 15 - Using ADO.NET in Xml Web Services
Chapter 16 - ASP.NET Server Controls and Data Binding
Also, don't forget to add references to the System.IO and System.Data.OleDb namespaces:
Chapter 17 - Building Real-World Web Applications
Chapter 18 - Object-Relational Mapping in .NET
Imports System.Data.OleDb
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
Imports System.IO
Chapter 20 - COM Interoperability and ADO.NET
Chapter 21 - Messaging
Chapter 22 -C-12
Listing SQL shows
Server the
and Browse
ADO.NET: Notesclick
button on Performance
code, which simply browses bitmap files and saves the filename
in theA curFileName
Appendix variable.
- Relational Databases: Some Basic Concepts
Appendix B - Commonly Used SQL Statements
Listing
Appendix C - C-12: Browse
ADO.NET Button
Frequently Click
Asked Event Handler
Questions
Index
List ofPrivate
Figures Sub BrowseBtn_Click(ByVal sender As System.Object, _
List ofByVal
Tables e As System.EventArgs) Handles BrowseBtn.Click
Dim openDlg As OpenFileDialog = New OpenFileDialog()
List of Listings
openDlg.Filter = "All Bitmap files|*.bmp"
List of Sidebars
Dim filter As String = openDlg.Filter
openDlg.Title = "Open a Bitmap File"
If (openDlg.ShowDialog() = DialogResult.OK) Then
curFileName = openDlg.FileName
TextBox1.Text = curFileName
End If
End Sub
The Save Image button code shown in Listing C-13 first creates a FileStream object from the bitmap file,
opens a connection with the database, adds a new DataRow, set its values, and saves the row back to
database.
Applied ADO.NET: Building Data-Driven Solutions
Listing C-13:by Mahesh
Save Chand
Image and David
Button Click Talbot
Event Handler ISBN:1590590732
Apress 2003 (928 pages)
This text provides extensive coverage of ADO.NET technology
Private Sub SaveImageBtn_Click(ByVal sender As System.Object, _
including ADO.NET internals, namespaces, classes, and
ByVal e interfaces,
As System.EventArgs) Handles
and takes a comprehensive lookSaveImageBtn.Click
at XML
namespaces and classes, and how to integrate both with
ADO.NET.
If TextBox1.Text Is String.Empty Then
MessageBox.Show("Browse a bitmap")
Return
Table of Contents
End If
Applied ADO.NETBuilding Data-Driven Solutions
' Read a bitmap contents in a stream
Introduction
Dim fs As FileStream = New FileStream(curFileName, _
Chapter FileMode.OpenOrCreate,
1 - ADO.NET Basics FileAccess.Read)
Chapter 2 Dim
- Data ComponentsAs
rawData() in Visual
ByteStudio
= New .NET
Byte(fs.Length) {}
Chapter 3 fs.Read(rawData,
- ADO.NET in Disconnected0, Environments
System.Convert.ToInt32(fs.Length))
Chapter 4 fs.Close()
- ADO.NET in Connected Environments
Chapter 5 '- Handling
Construct ADO.NET
a SQLEvents
string and a connection object
Chapter 6 Dim
- Integrating
sql AsXML with ADO.NET
String = "SELECT * FROM Users"
Chapter 7 Dim conn
- Data As and
Binding OleDbConnection = New OleDbConnection()
Windows Forms Data-Bound Controls
conn.ConnectionString
Chapter 8 - Constraints and Data Relations = connectionString
Chapter 9 '- ADO.NET
Open connection
Exception Handling
If conn.State
Chapter 10 - Working with the <>
ODBC ConnectionState.Open
.NET Data Provider Then
conn.Open()
Chapter 11 - Stored Procedures and Views
End If
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
' Create a data adapter and data set
Chapter 13 - Developing a Custom Data Provider
Dim adapter As OleDbDataAdapter = _
Chapter 14 - Developing Database Web Applications using ASP.NET
New OleDbDataAdapter(sql, conn)
Chapter 15 - Using ADO.NET in Xml Web Services
Dim cmdBuilder As OleDbCommandBuilder = _
Chapter 16 - ASP.NET Server Controls and Data Binding
New OleDbCommandBuilder(adapter)
Chapter 17Dim
- Building
ds As Real-World
DataSet Web = Applications
New DataSet("Users")
Chapter 18adapter.MissingSchemaAction
- Object-Relational Mapping in .NET = MissingSchemaAction.AddWithKey
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
Chapter 20'- COM
FillInteroperability
data adapter and ADO.NET
Chapter 21adapter.Fill(ds,
- Messaging "Users")
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Appendix ADim userDes
- Relational As String
Databases: = _ Concepts
Some Basic
"Mahesh Used
Appendix B - Commonly Chand
SQLis a founder of C# Corner "
Statements
Appendix CuserDes
- ADO.NET+= "Author:
Frequently Asked1. A Programmer's Guide to ADO.NET;"
Questions
Index userDes += ", 2. Applied ADO.NET. "
List of Figures
' Create a new row
List of Tables
Dim row As DataRow = ds.Tables("Users").NewRow()
List of Listings
row("UserName") = "Mahesh Chand"
List of Sidebars
row("UserEmail") = "mcb@mindcracker.com"
row("UserDescription") = userDes
row("UserPhoto") = rawData
' Add row to the collection
ds.Tables("Users").Rows.Add(row)
' Save changes to the database
adapter.Update(ds, "Users")
' Clean up connection
If conn Is Nothing Then
If conn.State = ConnectionState.Open Then
conn.Close()
End If
' Dispose connection
Applied ADO.NET: Building Data-Driven Solutions
conn.Dispose()
End Ifby Mahesh Chand and David Talbot ISBN:1590590732
Apress 2003 (928 pages)
MessageBox.Show("Image Saved")
End Sub This text provides extensive coverage of ADO.NET technology
including ADO.NET internals, namespaces, classes, and
interfaces, and takes a comprehensive look at XML
namespaces and classes, and how to integrate both with
ADO.NET.
Once data is saved, the next step is to read data from the database table, save it as a bitmap again, and
view the bitmap on the form. You can directly view an image using the Graphics.DrawImage method or
Tablebyof using
Contents
a PictureBox control. In this case, we'll use a PictureBox.Listing C-14 shows the code for
Applied ADO.NETBuilding
reading Data-Driven
binary data. As Solutions
you can see, the code simply opens a connection, creates a DataAdapter, fills a
DataSet, and gets the first row of the Users table. Now if you want to read all images, you may want to
Introduction
modify
Chapter 1 -your application
ADO.NET Basics or make a loop through all rows.
Chapter 2 - Data Components in Visual Studio .NET
Listing
Chapter 3 - C-14: Reading
ADO.NET Binary Data
in Disconnected Environments
Chapter 4 - ADO.NET in Connected Environments
Private
Chapter Sub UseReaderBtn_Click(ByVal
5 - Handling ADO.NET Events sender As System.Object, _
ByVal
Chapter e As System.EventArgs)
6 - Integrating XML with ADO.NET Handles UseReaderBtn.Click
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
Chapter 8 '- Constraints
Construct a Data
and SQLRelations
string and a connection object
Chapter Dim sql As String = "SELECT UserPhoto FROM Users"
9 - ADO.NET Exception Handling
Chapter
Dim conn As OleDbConnection = New OleDbConnection()
10 - Working with the ODBC .NET Data Provider
conn.ConnectionString = connectionString
Chapter 11 - Stored Procedures and Views
' Open connection
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
If conn.State <> ConnectionState.Open Then
Chapter 13 - Developing a Custom Data Provider
conn.Open()
Chapter 14 - Developing Database Web Applications using ASP.NET
End If
Chapter 15 - Using ADO.NET in Xml Web Services
Chapter 16Dim
- ASP.NET
cmd AsServer Controls and Data
OleDbCommand Binding
= New OleDbCommand(sql, conn)
Chapter 17Dim
- Building Real-World
fs As FileStream Web Applications
Chapter 18Dim
- Object-Relational Mapping in .NET
bw As BinaryWriter
Chapter 19Dim
- Mapped Objects: Performance
bufferSize As Integer Considerations
= 300000and Data Binding
Chapter 20Dim
- COM Interoperability and-ADO.NET
outbyte(300000 1) As Byte
Chapter 21Dim retval As Long
- Messaging
Chapter 22Dim
- SQLstartIndex As Long
Server and ADO.NET: = on
Notes 0 Performance
Appendix ADim pub_id
- Relational As String
Databases: Some=Basic
"" Concepts
Appendix BDim readerUsed
- Commonly As SQL
OleDbDataReader
Statements = _
cmd.ExecuteReader(CommandBehavior.SequentialAccess)
Appendix C - ADO.NET Frequently Asked Questions
Index
' Read first record
reader.Read()
List of Figures
fs = New FileStream(savedImageName, _
List of Tables
FileMode.OpenOrCreate, FileAccess.Write)
List of Listings
bw = New BinaryWriter(fs)
List of Sidebars
startIndex = 0
retval = reader.GetBytes(0, 0, outbyte, 0, bufferSize)
bw.Write(outbyte)
bw.Flush()
' Close the output file.
bw.Close()
fs.Close()
reader.Close()
' Display image
curImage = Image.FromFile(savedImageName)
PictureBox1.Image = curImage
PictureBox1.Invalidate()
' Clean up connection
Applied ADO.NET:
If conn.State Building Data-Driven Solutions
= ConnectionState.Open Then
by Mahesh
conn.Close() Chand and David Talbot ISBN:1590590732
Apress 2003 (928
' Dispose connection pages)
This text provides extensive coverage of ADO.NET technology
conn.Dispose()
End Ifincluding ADO.NET internals, namespaces, classes, and
interfaces, and takes a comprehensive look at XML
End Sub namespaces and classes, and how to integrate both with
ADO.NET.
TableOnce
of Contents
a row is read, you get the data stored in the UserPhoto column (Image column) in a stream and save
Applied ADO.NETBuilding
it as Data-Driven
a bitmap file. Later Solutions
you can view that bitmap file in the PictureBox control by setting its Image
Introduction
property to the filename.
Chapter 1 - ADO.NET Basics
Now,
Chapter 2 you probably
- Data want toinsee
Components thisStudio
Visual program
.NETin action. You can select any image by clicking the Browse
Image -button,
Chapter 3
which lets you browse images. Once you've selected a file, you need to save it by clicking the
ADO.NET in Disconnected Environments
Save Image button. To read the image, simply click the Read Image button. This creates a temporary
Chapter 4 - ADO.NET in Connected Environments
bitmap file named ImageFromDb.BMP file in c:// folder. You may want to change your path to C:\\. The
Chapter 5 - Handling ADO.NET Events
final output looks like Figure C-5.
Chapter 6 - Integrating XML with ADO.NET
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
Chapter 8 - Constraints and Data Relations
Chapter 9 - ADO.NET Exception Handling
Chapter 10 - Working with the ODBC .NET Data Provider
Chapter 11 - Stored Procedures and Views
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Chapter 13 - Developing a Custom Data Provider
Chapter 14 - Developing Database Web Applications using ASP.NET
Chapter 15 - Using ADO.NET in Xml Web Services
Chapter 16 - ASP.NET Server Controls and Data Binding
Chapter 17 - Building Real-World Web Applications
Chapter 18 - Object-Relational Mapping in .NET
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
Chapter 20 - COM Interoperability and ADO.NET
Chapter 21 - Messaging
Chapter 22 - SQLC-5:
Figure Server and ADO.NET:
Displaying Notes
a bitmap on reading
after Performance
data from a database
Appendix A - Relational Databases: Some Basic Concepts
Appendix B - Commonly Used SQL Statements
A: The C
Appendix following sections
- ADO.NET discuss
Frequently the Questions
Asked basics of DiffGrams and how a DataSet utilizes the DiffGram format
Indexin this context.
List of Figures
DiffGrams and DataSet
List of Tables
List ofThere
Listings
are occasions when you want to compare the original data with the current data to get the changes
List ofmade to the original data. A common example of this is saving data on Web Forms applications. When
Sidebars
working with Web-based data-driven applications, you read data using a DataSet, make some changes to
the data, and send data back to the database to save the final data. Sending an entire DataSet may be a
costly affair, especially when there are thousands of records in a DataSet. In this scenario, the best
practice is to find out the updated rows of a DataSet and send only those rows back to the database
instead of the entire DataSet. This is where the DiffGrams are useful.
Note Do you remember the GetChanges method of a DataSet? This method returns the rows that
have been modified in the current version in the form of a DataSet. This is how a DataSet
knows the modified rows.
ADiffGram is an XML format used to identify the current and original versions of data elements. Because
theDataSet uses XML to store and transfer data, it also uses DiffGrams to keep track of the original
Applieddata.
data and the current ADO.NET:
When Building
a DataSetData-Driven Solutions
is written as a DiffGram, not only does the DiffGram stores
by Mahesh Chand and David Talbot ISBN:1590590732
original and current data, it also stores row versions, error information, and their orders.
Apress 2003 (928 pages)
DiffGram XML Format
This text provides extensive coverage of ADO.NET technology
including ADO.NET internals, namespaces, classes, and
The XML format for a DiffGram
interfaces, and takeshas three parts: data
a comprehensive instance,
look at XML DiffGram before, and DiffGram errors.
namespacestag
The<DataInstance> and classes, and
represents thehow
datatoinstance
integratepart
both
ofwith
a DiffGram, which represents the current
ADO.NET.
data. The DiffGram before is represented by the <diffgr:before> tag, which represents the original
version of the data. The <diffgr:errors> tag represents the DiffGram errors part, which stores the
Tableerrors and related information. The DiffGram itself is represented by the tag <diffgr:diffgram>.
of Contents
Listing C-15 represents
Applied ADO.NETBuilding the XML skeleton
Data-Driven Solutionsof a DiffGram.
Introduction
Listing C-15: ADiffGram Format
Chapter 1 - ADO.NET Basics
Chapter 2 - Data Components in Visual Studio .NET
<?xml
Chapter version="1.0"?>
3 - ADO.NET in Disconnected Environments
<diffgr:diffgram
Chapter 4 - ADO.NET in Connected Environments
xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"
Chapter 5 - Handling ADO.NET Events
xmlns:diffgr="urn:schemas-microsoft-com:xml-diffgram-v1"
Chapter 6 - Integrating XML with ADO.NET
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
Chapter 8 - Constraints and Data Relations
<DataInstance>
Chapter 9</DataInstance>
- ADO.NET Exception Handling
Chapter 10 - Working with the ODBC .NET Data Provider
Chapter <diffgr:before>
11 - Stored Procedures and Views
Chapter </diffgr:before>
12 - Oracle, SQLXML, and Other .NET Data Providers
Chapter 13 - Developing a Custom Data Provider
Chapter <diffgr:errors>
14 - Developing Database Web Applications using ASP.NET
Chapter </diffgr:errors>
15 - Using ADO.NET in Xml Web Services
</diffgr:diffgram>
Chapter 16 - ASP.NET Server Controls and Data Binding
Chapter 17 - Building Real-World Web Applications
Chapter 18 - Object-Relational Mapping in .NET
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
The<diffgr:before> sections only store the changed rows, and the <diffgr:errors> section only
Chapter 20 - COM Interoperability and ADO.NET
stores the rows that had errors. Each row in a DiffGram is identified with an ID, and these three sections
Chapter 21 - Messaging
communicate through this ID. For example, if the ID of a row is Id1, and it has been modified and has
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
errors, the <diffgr:errors> stores those errors. Besides the previously discussed three sections, a
Appendix A - Relational
DiffGram Databases:
uses other Some
elements Basic
(see Concepts
Table C-5).
Appendix B - Commonly Used SQL Statements
Appendix
TableC -C-5:
ADO.NET Frequently Elements
The DiffGram Asked Questions
Index
List of Figures
List of Tables
List of Listings
List of Sidebars
ELEMENT Applied
DESCRIPTION
ADO.NET: Building Data-Driven Solutions
by Mahesh Chand and David Talbot ISBN:1590590732
id This is the DiffGram ID, which is usually in the format of
Apress 2003 (928 pages)
[TableName][RowIdentifier]. For example: <Customers
This text provides extensive coverage of ADO.NET technology
diffgr:id="Customers1">.
including ADO.NET internals, namespaces, classes, and
parented interfaces, and takes a comprehensive look at XML
This is the parent row of the current row, which is usually in the format of
namespaces and classes, and how to integrate both with
[TableName][RowIdentifier].
ADO.NET. For example: <Orders
diffgr:parentId="Customers1">.
hasChanges
Table of Contents
This identifies a row in the <DataInstance> block as modified. The
hasChanges element can have one of the three values: inserted,modified,
Applied ADO.NETBuilding Data-Driven Solutions
or descent. The value inserted means an added row, modifiedmeans a
Introduction
modified row, and descent means the children of a parent row have been
Chapter 1 - ADO.NET Basics
modified.
Chapter 2 - Data Components in Visual Studio .NET
3 - ADO.NET inThis
hasErrors
Chapter identifies Environments
Disconnected a row in the <DataInstance> block with a RowError. The error
Chapter 4 - ADO.NET inelement is placed
Connected in the <diffgr:errors> block.
Environments
Chapter 5 - Handling ADO.NET
error Eventsthe text of the RowError for a particular element in the
This contains
Chapter 6 - Integrating <diffgr:errors>
XML with ADO.NET block.
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
Chapter 8 -are
There Constraints
two moreand Data Relations
elements a DataSet-generatedDiffGram can have, and these elements are
Chapter 9 - ADO.NET
RowOrder Exception
and Hidden. Handling is the row order of the original data and identifies the index of a row in
RowOrder
Chapter 10 - Working
a particular with the ODBC
DataTable. .NET
Hidden Data Provider
identifies a column as having a ColumnMapping property set to
Chapter 11 - Stored Procedures and Views
MappingType.Hidden.
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Listing C-16 reads data from the Employees tables and writes in an XML document in DiffGram format.
Chapter 13 - Developing a Custom Data Provider
Chapter 14 - Developing Database Web Applications using ASP.NET
Listing C-16: ReadingDiffGrams
Chapter 15 - Using ADO.NET in Xml Web Services
Chapter 16 - ASP.NET Server Controls and Data Binding
Dim connectionString As String = _
Chapter 17 - Building Real-World Web Applications
"Provider=Microsoft.Jet.OLEDB.4.0; Data Source=c:\\Northwind.mdb"
Chapter 18 - Object-Relational Mapping in .NET
Dim sql As String = _
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
"SELECT EmployeeID, FirstName, LastName, Title FROM Employees"
Chapter 20 - COM Interoperability and ADO.NET
Dim conn As OleDbConnection = Nothing
Chapter 21 - Messaging
Dim ds As DataSet = Nothing
Chapter 22'- SQL Serverand
Create and open
ADO.NET: Notes on Performance
connection
Appendix Aconn- Relational Databases: Some Basic Concepts
= New OleDbConnection(connectionString)
Appendix BIf - Commonly
conn.State Used SQL
<> Statements
ConnectionState.Open Then
Appendix C - ADO.NET
conn.Open()Frequently Asked Questions
Index End If
List of Figures
' Create a data adapter
Dim adapter As OleDbDataAdapter = New OleDbDataAdapter(sql, conn)
List of Tables
' Create and fill a DataSet
List of Listings
ds = New DataSet("TempDtSet")
List of Sidebars
adapter.Fill(ds, "DtSet")
' Write XML in DiffGram format
ds.WriteXml("DiffGramFile.xml", XmlWriteMode.DiffGram)
' Close connection
If conn.State = ConnectionState.Open Then
conn.Close()
End If
MessageBox.Show("Done")
Table of Contents
Applied ADO.NETBuilding Data-Driven Solutions
Introduction
Chapter 1 - ADO.NET Basics
Chapter 2 - Data Components in Visual Studio .NET
Chapter 3 - ADO.NET in Disconnected Environments
Chapter 4Figure
- ADO.NET in Connected
C-6: DiffGram Environments
format
Chapter 5 - Handling ADO.NET Events
Now
Chapter 6 if -you update data,
Integrating you'llADO.NET
XML with see new additions to the XML file with <diffgr:before> and
7 - Data Bindingtags;
<DataInstance>
Chapter if any errors
and Windows occur
Forms during the
Data-Bound update, the entries will go to the
Controls
<diffgr:errors>
Chapter section.
8 - Constraints and Data Relations
Chapter 9 - ADO.NET Exception Handling
You can use the ReadXml method to read XML documents in DiffGram format. The first parameter of
Chapter 10 - Working with the ODBC .NET Data Provider
ReadXml is the XML document name, and the second parameter should be XmlReadMode.DiffGram:
Chapter 11 - Stored Procedures and Views
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
' Create a DataSet Object
Chapter 13 - Developing a Custom Data Provider
Dim ds As DataSet = New DataSet()
Chapter 14 - Developing Database Web Applications using ASP.NET
' Fill with the data
Chapter 15 - Using ADO.NET in Xml Web Services
ds.ReadXml("DiffGramFile.xml", XmlReadMode.DiffGram)
Chapter 16 - ASP.NET Server Controls and Data Binding
Chapter 17 - Building Real-World Web Applications
Using
Chapter 18 -the GetChanges Method
Object-Relational Mapping in .NET
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
TheGetChanges method of DataSet can retrieve the rows that have been modified since the last time
Chapter 20 - COM Interoperability and ADO.NET
DataSet was filled, saved, or updated. The GetChanges method returns a DataSet's objects with
Chapter 21 - Messaging
modified rows.
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Appendix A - Relational Databases:
TheGetChanges method can Some
takeBasic
eitherConcepts
no argument or one argument of type DataRowState. The
Appendix B - Commonlyenumeration
DataRowState Used SQL Statements
defines the DataRow state, which can be used to filter a DataSet based on
the types
Appendix of rows.Frequently
C - ADO.NET Table C-6Asked
describes the DataRowState members.
Questions
Index
List ofTable C-6: The DataRowState Members
Figures
List of Tables
MEMBER DESCRIPTION
List of Listings
List of Added
Sidebars Add added rows to a DataRowCollection of a DataSet and AcceptChanges
has not been called.
Deleted All the deleted rows.
Detached Rows were created but not added to the row collection. Either waiting for the
addition to or removal from the collection.
Modified Modified rows and AcceptChanges has not been called.
Unchanged Unchanged rows since last AcceptChanges was called.
Listing C-17 copies only modified rows of ds to a new DataSet called tmpDtSet.
Listing C-17: Reading Only Modified Rows of a DataSet
Applied ADO.NET: Building Data-Driven Solutions
by Mahesh Chand and David Talbot ISBN:1590590732
' See if DataSet has
Apress 2003 (928changes
pages)
or not
If Not ds.HasChanges(DataRowState.Modified) Then Exit Sub
This text provides extensive coverage of ADO.NET technology
Dim tmpDtSet As DataSet
including ADO.NET internals, namespaces, classes, and
' GetChanges
interfaces, for modified
and takes rows only.
a comprehensive look at XML
namespaces
tmpDtSet and classes, and how to integrate both with
= ds.GetChanges(DataRowState.Modified)
ADO.NET.
If tmpDtSet.HasErrors Then
MessageBox.Show("DataSet has errors")
Exit Sub
Table of Contents
End If
Applied ADO.NETBuilding Data-Driven Solutions
adapter.Update(tmpDtSet)
Introduction
Chapter 1 - ADO.NET Basics
Chapter 2 - Data Components in Visual Studio .NET
Chapter
Now 3 you
- ADO.NET
can use in Disconnected
the new DataSetEnvironments
to bind it to data-bound controls or send back to the database to store
Chapter 4 -
results. ADO.NET in Connected Environments
Chapter 5 - Handling ADO.NET Events
A: Besides
Chapter the defaultXML
6 - Integrating with ADO.NET method of SqlCommand or other data provider command objects, an
ExecuteReader
overloaded
Chapter 7 - Dataform of ExecuteReader
Binding takes
and Windows Forms an argument
Data-Bound of type CommandBehavior enumeration. The
Controls
CommandBehavior
Chapter enumeration
8 - Constraints and provides a description of the results of the query and its effect on the
Data Relations
database.
Chapter We've used
9 - ADO.NET the SchemaOnly
Exception Handling and SequentialAccess members of CommandBehavior
members
Chapter in the samples
10 - Working discussed
with the ODBC .NET in FAQ
Data 2. However, the CommandBehavor enumeration has few more
Provider
members
Chapter (see Procedures
11 - Stored Table C-7).and Views
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Table C-7: The CommandBehavior Enumeration
Chapter 13 - Developing a Custom Data Provider
Chapter 14 - Developing DatabaseDESCRIPTION
MEMBER Web Applications using ASP.NET
Chapter 15 - Using ADO.NET in Xml Web Services
CloseConnection TheConnection object associated with the DataReader is closed
Chapter 16 - ASP.NET Server Controls and Data Binding
when the DataReader is closed.
Chapter 17 - Building Real-World Web Applications
Chapter 18 - Object-Relational Mapping
Default Defaultinoption.
.NET No effects. Hence, calling ExecuteReader with
Chapter 19 - Mapped Objects: Performance returns
Considerations and Data
CommandBehavior.Default the same result as calling
Binding
Chapter 20 - COM InteroperabilityExecuteReader
and ADO.NET with no parameters.
Chapter 21 - Messaging
KeyInfo Returns column and primary key information. You should use this option
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
when you need to read the information about a table's columns and
Appendix A - Relational Databases: Some Basic Concepts
primary key.
Appendix B - Commonly Used SQL Statements
C - ADO.NET FrequentlyReturns
SchemaOnly
Appendix column information only. Useful when you want to know a table
Asked Questions
Index schema. We used this option in FAQ 2 to read a database table schema.
List of SequentialAccess
Figures Used to read rows that contain columns with large binary values. The
List of Tables SequentialAccess option allows the DataReader to read data in a
List of Listings stream. We use this option in Listing C-14, where we read binary data.
List of Sidebars
SingleResult Returns a single result set.
SingleRow Returns a single row.
A: Unlike an ADO recordset, the DataReader doesn't provide any property or method that returns the total
number of records fetched through a SELECT statement. There are two common ways to find out the total
number of records fetched by a DataReader. First, you can use a SELECT COUNT * statement, which
was discussed in FAQ 12. Second, you can loop through all the records and store the value in an increment
counter. This method is not recommended when there are thousands of records.
Applied
A: Unlike an ADO ADO.NET:
recordset, Building Data-Driven
the DataReader Solutions
doesn't support EOF either. If there aren't any records left in a
DataReader, bythe
Mahesh
ReadChand
method and
ofDavid Talbot
the DataReader returns
ISBN:1590590732
false.
Apress 2003 (928 pages)
A: ADataReader Thisdoesn't provideextensive
text provides any property or method
coverage to sorttechnology
of ADO.NET the records. The easiest way to sort
records ADO.NET
DataReaderincluding is using the
internals, BY clause with
ORDERnamespaces, the SELECT
classes, and statement. The ORDER BY clause
interfaces,
followed by ASC or DESCand takes
sorts a comprehensive
in ascending look at XML
or descending order, respectively. For example, if you want to
namespaces and classes, and how to integrate both with
sort records based
ADO.NET.
on the Name column in descending order, you use the following SQL statement:
Table of Contents
Applied ADO.NETBuilding Data-Driven Solutions
Introduction
Chapter 1 - ADO.NET Basics
Chapter 2 - Data Components in Visual Studio .NET
Chapter 3 - ADO.NET in Disconnected Environments
Chapter 4 - ADO.NET in Connected Environments
Chapter 5 - Handling ADO.NET Events
Chapter 6 - Integrating XML with ADO.NET
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
Chapter 8 - Constraints and Data Relations
Chapter 9 - ADO.NET Exception Handling
Chapter 10 - Working with the ODBC .NET Data Provider
Chapter 11 - Stored Procedures and Views
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Chapter 13 - Developing a Custom Data Provider
Chapter 14 - Developing Database Web Applications using ASP.NET
Chapter 15 - Using ADO.NET in Xml Web Services
Chapter 16 - ASP.NET Server Controls and Data Binding
Chapter 17 - Building Real-World Web Applications
Chapter 18 - Object-Relational Mapping in .NET
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
Chapter 20 - COM Interoperability and ADO.NET
Chapter 21 - Messaging
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Appendix A - Relational Databases: Some Basic Concepts
Appendix B - Commonly Used SQL Statements
Appendix C - ADO.NET Frequently Asked Questions
Index
List of Figures
List of Tables
List of Listings
List of Sidebars
Index Applied ADO.NET: Building Data-Driven Solutions
by Mahesh Chand and David Talbot ISBN:1590590732
Apress 2003 (928 pages)
Numbers This text provides extensive coverage of ADO.NET technology
including ADO.NET internals, namespaces, classes, and
1NF (First Normal Form), 780782
interfaces, and takes a comprehensive look at XML
2NF (Second Normal Form), and
namespaces classes, and how to integrate both with
782784
ADO.NET.
3NF (Third Normal Form), 784785
4NF (Fourth Normal Form), 785
Table of Contents
5NF (Fifth Normal Form), 786
Applied ADO.NETBuilding Data-Driven Solutions
Introduction
Chapter 1 - ADO.NET Basics
Chapter 2 - Data Components in Visual Studio .NET
Chapter 3 - ADO.NET in Disconnected Environments
Chapter 4 - ADO.NET in Connected Environments
Chapter 5 - Handling ADO.NET Events
Chapter 6 - Integrating XML with ADO.NET
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
Chapter 8 - Constraints and Data Relations
Chapter 9 - ADO.NET Exception Handling
Chapter 10 - Working with the ODBC .NET Data Provider
Chapter 11 - Stored Procedures and Views
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Chapter 13 - Developing a Custom Data Provider
Chapter 14 - Developing Database Web Applications using ASP.NET
Chapter 15 - Using ADO.NET in Xml Web Services
Chapter 16 - ASP.NET Server Controls and Data Binding
Chapter 17 - Building Real-World Web Applications
Chapter 18 - Object-Relational Mapping in .NET
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
Chapter 20 - COM Interoperability and ADO.NET
Chapter 21 - Messaging
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Appendix A - Relational Databases: Some Basic Concepts
Appendix B - Commonly Used SQL Statements
Appendix C - ADO.NET Frequently Asked Questions
Index
List of Figures
List of Tables
List of Listings
List of Sidebars
Index Applied ADO.NET: Building Data-Driven Solutions
by Mahesh Chand and David Talbot ISBN:1590590732
Apress 2003 (928 pages)
A This text provides extensive coverage of ADO.NET technology
including ADO.NET internals, namespaces, classes, and
aborted transactions, 747
interfaces, and takes a comprehensive look at XML
namespaces and classes,
AcceptChanges and RejectChanges and how
Methods of atoDataSet
integrate both listing),
(code with 191-192
ADO.NET.
AcceptChanges method, 127,191-192,231
Access, Microsoft
Tableaccessing
of Contents
databases, 378-380
Applied ADO.NETBuilding
exporting table to text Data-Driven
file, 383-385Solutions
Introduction
Active Data Objects .NET (ADO.NET). SeeADO.NET
Chapter 1 - ADO.NET Basics
ActiveX Data Objects Multi-Dimensional Library (ADOMD), 718
Chapter 2 - Data Components in Visual Studio .NET
Add Button
Chapter Click Event
3 - ADO.NET Handler (code
in Disconnected listing), 505
Environments
Chapter
Add Web4 Reference
- ADO.NET in Connected
feature, 525 Environments
Chapter 5 - Handling ADO.NET Events
AddCat1Stored Procedure (code listing), 404
Chapter 6 - Integrating XML with ADO.NET
AddHandler statement, 209
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
adding 8data
Chapter (ASP.NET),
- Constraints 505
and Data Relations
Chapter
AddNew 9 method
- ADO.NET Exception130
(DataView), Handling
Chapter 10 - Working with the ODBC .NET Data
AddRowBtn_Click Method (code listing), Provider
109-110
Chapter 11 - Stored Procedures and Views
administration queues (user), 726
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
ADO (ActiveX
Chapter Data Objects)
13 - Developing a Custom Data Provider
comparing
Chapter with ADO.NET,
14 - Developing 11-13
Database Web Applications using ASP.NET
connections and disconnected data, 11-12
Chapter 15 - Using ADO.NET in Xml Web Services
RecordSets vs. DataSets, 12
Chapter 16 - ASP.NET Server Controls and Data Binding
XML support, 12-13
Chapter 17 - Building Real-World Web Applications
overview of, 6
Chapter 18 - Object-Relational Mapping in .NET
recordset and ADO.NET, 712-716
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
ADO Examples and Best Practices for Programmers ,760
Chapter 20 - COM Interoperability and ADO.NET
ADODB
Chapter 21Namespace
- Messagingto Access a Database (code listing), 715-716
Chapter
ADO.NET22 - SQL Server and ADO.NET: Notes on Performance
Appendix A - Relational
ADO.NET Databases:
Application Some Basic
(code listing), 27 Concepts
ADO.NET
Appendix (Apress),Used
B - Commonly 760 SQL Statements
ADOX,
Appendix C -using with,Frequently
ADO.NET 716-718 Asked Questions
Indexarchitecture,75-76
COM
List of interoperability and. SeeCOM interoperability
Figures
creating
List of Tables a project, 33
exception
List of Listings handling in. Seeexception handling in ADO.NET
Frequently Asked Questions. SeeFrequently Asked Questions, ADO.NET
List of Sidebars
object-relational (OR) mapping in. Seeobject-relational (OR) mapping in .NET
overview of, 6-7
SQL Server performance and. SeeSQL Server and ADO.NET
using in XML Web services. SeeXML Web services
Web application, creating, 478-480
XML, using with, 262-272
displaying XML data in DataSet format, 270
reading XML using DataSet, 262-264
saving data from DataSet to XML, 271-272
writing XML using DataSet, 264-267
XmlDataDocument and DataSet objects, 272
XmlDataDocument and XML, 267-269
ADO.NET basics, 1-31
Applied ADO.NET: Building Data-Driven Solutions
advantages of, 9-11
by Mahesh Chand and David Talbot ISBN:1590590732
managed code, 10
Apress 2003 (928 pages)
performance and scalability, 11
This text provides
single object-oriented extensive coverage of ADO.NET technology
API, 9-10
including ADO.NET internals, namespaces, classes, and
visual datainterfaces,
components, 11
and takes a comprehensive look at XML
XML support, 10
namespaces and classes, and how to integrate both with
code listings ADO.NET.
ADO.NET Application, 27
Viewing Data From SQL Server Database, 30-31
Table of Contents
comparing with ADO, 11-13
Applied ADO.NETBuilding Data-Driven Solutions
connections and disconnected data, 11-12
Introduction
RecordSets vs. DataSets, 12
Chapter XML
1 - ADO.NET Basics
support, 12-13
Chapter 2 - Data of,
components Components
15-22 in Visual Studio .NET
Chapter Command
3 - ADO.NET in Disconnected
object, 17-18 Environments
Chapter CommandBuilder, 19
4 - ADO.NET in Connected Environments
Chapter Connection
5 - Handling object,
ADO.NET16-17
Events
Chapter data
6 - providers,
Integrating15-16
XML with ADO.NET
Chapter DataAdapter object,
7 - Data Binding and19-20
Windows Forms Data-Bound Controls
DataSet structure, 20-21
Chapter 8 - Constraints and Data Relations
Chapter DataSets
9 - ADO.NETin DataViews,
Exception 21-22
Handling
creating simple ADO.NET application, 26-28
Chapter 10 - Working with the ODBC .NET Data Provider
DataSet to read data, 28-31
Chapter 11 - Stored Procedures and Views
Microsoft Data Access Technologies, overview
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
ADO,6
Chapter 13 - Developing a Custom Data Provider
ADO.NET,6-7
Chapter 14 - Developing Database Web Applications using ASP.NET
DAO,4-5
Chapter MFC,
15 - Using
5 ADO.NET in Xml Web Services
Chapter ODBC,
16 - ASP.NET
2-4 Server Controls and Data Binding
Chapter OLE
17 - DB,
Building
5-6 Real-World Web Applications
Chapter RDO,
18 - Object-Relational
5 Mapping in .NET
Chapter 19 - Mapped
namespaces andObjects:
classesPerformance Considerations and Data Binding
overview, 13-14
overview,
Chapter 6-8 Interoperability and ADO.NET
20 - COM
reasons
Chapter for design of, 8-9
21 - Messaging
writing
Chapter 22 -ADO.NET
SQL Server applications,
and ADO.NET:22-26
Notes on Performance
Appendixchoosing .NET Databases:
A - Relational providers, 22-23
Some Basic Concepts
AppendixCommand
B - Commonlyor DataAdapter objects, creating, 25
Used SQL Statements
connections, closing, 26
Appendix C - ADO.NET Frequently Asked Questions
Index
connections, establishing, 24-25
displaying data, 25-26
List of Figures
Filling data to DataSet or DataReader object, 25
List of Tables
namespace references, adding, 23-24
List of Listings
ADO.NET
List events, handling, 209-232
of Sidebars
code listings
ColumnChanging and ColumnChanged Event Handlers, Writing, 222-223
Connection Events, Writing Code That Executes, 214-215
DataAdapter FillError Event Handler Code, 217
DataAdapter's Fill and Update Methods, Calling, 219-220
DataView Event Handler Caller, 230-231
DataView OnListChanged Event Handler, 230
InfoMessage and StateChange events, Writing Event Handlers for, 213
MergeFailed Event Handler, Calling, 220-221
NodeChanged Event Handler, 228
NodeInserted Event Handler, 229
NodeRemoved Event Handler, 229
RowChanging and RowChanged Event Handlers, Writing, 224
Applied ADO.NET: Building Data-Driven Solutions
RowDeleting and RowDeleted Event Handlers, Writing, 225-226
RowUpdatedby Mahesh Chand and
Event Handler, 218 David Talbot ISBN:1590590732
Apress 2003 (928 pages)
RowUpdating Event Handler, 218-219
This text
SqlDataAdapter provides
Event extensive
Handler coverage
Bodies, 217 of ADO.NET technology
including ADO.NET internals, namespaces, classes, and
XmlDataDocument Event Handling Example, 227-228
interfaces, and takes a comprehensive look at XML
Connection events, 211-215
namespaces and classes, and how to integrate both with
DataAdapter events,
ADO.NET. 215-220
DataSet events, 220-221
DataTable events, 221-226
TableDataView
of Contents
and DataViewManager events, 229-231
Applied ADO.NETBuilding
fundamentals, 209-211Data-Driven Solutions
Introduction
XmlDataDocument events, 226-229
Chapter 1 - ADO.NET Basics
ADO.NET in connected environments, 135-208
Chapter 2 - Data Components in Visual Studio .NET
code listings
Chapter AcceptChanges
3 - ADO.NET in and Disconnected Environments
RejectChanges methods of a DataSet, Using, 191-192
Chapter Calling
4 - ADO.NET in Connected Environments
a DataAdapter's Fill Method, 171
Chapter Connecting
5 - Handling to ADO.NET
SQL Server Events
and Reading SqlConnection Properties, 144-145
Chapter Connecting
6 - Integrating
to SQL ServerADO.NET
XML with Using OleDb Data Provider, 144
Chapter Creating
7 - DataTwoBinding and Windows
Connections withForms Data-Bound
Different Controls
Strings, 147-148
Chapter DataAdapter's
8 - Constraints Update Method,
and Data Calling, 178
Relations
Chapter DataColumnMapping,
9 - ADO.NET Exception Using, 180-181
Handling
Chapter DataReader
10 - WorkingReads From
with the ODBC SQL Server
.NET Database, 162-164
Data Provider
Chapter DataSet Rows,
11 - Stored Adding,and
Procedures Editing,
ViewsDeleting, 190-191
Chapter DataTableMapping
12 - Oracle, SQLXML, toand
MapOther
Northwind Orders
.NET Data Table, 179
Providers
DataTableMapping with Table Option,
Chapter 13 - Developing a Custom Data Provider Using, 179-180
DeleteCommand Property of DataAdapter, Setting,
Chapter 14 - Developing Database Web Applications using ASP.NET
176
Displaying Customers Table's Data in DataGrid Using SqlDataAdapter, 174-175
Chapter 15 - Using ADO.NET in Xml Web Services
Displaying Orders Table Data in DataGrid Using OleDbAdapter, 173-174
Chapter 16 - ASP.NET Server Controls and Data Binding
ExecuteScalar Method to Retrieve Single Value, 160
Chapter 17 - Building Real-World Web Applications
Executing Batches Using DataReader, 164-165
Chapter 18 - Object-Relational Mapping in .NET
Executing Multiple SQL Queries Using SqlTransaction, 207-208
Chapter Fill
19 method
- MappedofObjects: Performance
a DataAdapter, Considerations
Calling, 177 and Data Binding
Chapter Filling
20 - COM Interoperability and ADO.NET
Data From Multiple Tables, 188-189
Chapter FillSchema
21 - Messaging
method of SqlDataAdapter, Using, 172
Chapter INSERT
22 - SQLSQL
Server and ADO.NET:
Statement, AddingNotes on Performance
Records to Table Using, 159
AppendixMerging
A - Relational
Two DataSet Objects, 189 Concepts
Databases: Some Basic
AppendixOleDb Database,
B - Commonly Connecting
Used to, 143
SQL Statements
AppendixOleDbCommand, Using to
C - ADO.NET Frequently Access
Asked an Access Database, 154
Questions
Index Optimistic Concurrency, 202-203
Parameter, Creating a, 185-186
List of Figures
Pessimistic Concurrency, 204
List of Tables
Private Members, 196-197
List of Listings
ReleaseObjectPool, Calling, 149
List of Sidebars
Removing a Row and Calling Update Method of DataAdapter, 177
Savepoints in Sql Data Provider, Using, 205-206
Saving Only Modified Rows of DataSet, 193
SELECT Statement, Executing Using OleDbDataAdapter, 167-168
SqlCommand Properties, Setting and Getting, 151
SqlCommand to Read Data from Database, 153
SqlCommandBuilder Class, Creating and Using, 183-184
SqlConnection objects, creating, 139-140
SqlDataAdapter Instances, Creating, 167
SqlDataAdapter Properties, Using, 169
SqlParameter, Creating, 177
Stored Procedure, Calling Using SqlCommand, 155
Stored Procedure, Executing and Reading Results of, 156-157
Applied ADO.NET: Building Data-Driven Solutions
Stored Procedure Results Output, Adding Subtotal Listing to, 157
by Mahesh
Stored Procedure Chand
(Sales byand David
Year) Talbot
in Northwind ISBN:1590590732
Database, 156
Apress 2003 (928
TableDirect to Read Table, 158 pages)
ConnectingThis to antextOracle
provides extensive417-418
Database, coverage of ADO.NET technology
including ADO.NET internals, namespaces, classes, and
Constructing SQL INSERT, UPDATE, DELETE Queries, 421
interfaces, and takes a comprehensive look at XML
ExecuteSqlQuery
namespaces Method, 420
and classes, and how to integrate both with
FillDataGrid Method, 419-420
ADO.NET.
Oracle-Specific DataReader Methods, 423
OracleDataAdapter, Reading/Writing Data Using, 423-424
Table of OracleDataReader,
Contents Reading Data Using, 422-423
Applied ADO.NETBuilding
SQL Server and ADO.NET Data-Driven Solutions
Introduction
Generic Data Access Class, 771-773
Chapter Generic
1 - ADO.NET Basics Class, Using, 774-775
Data Access
Chapter Query
2 - DatafromComponents in Visual StudioNot
SelectVideosCheckedIn, .NETOptimized, 762-763
Chapter SelectVideosCheckedIn
3 - ADO.NET in Disconnected Query, Optimized Version, 763-764
Environments
Chapter sp_executesql
4 - ADO.NET in toConnected
Execute aEnvironments
Database Query, 765
Chapter User-Defined
5 - Handling Variables,
ADO.NET Events 773-774
SQLXML
Chapter and SQL XML
6 - Integrating .NETADO.NET
XML with data providers
Chapter SqlXmlAdapter,
7 - Data BindingUsing, 429
and Windows Forms Data-Bound Controls
SqlXmlCommand to Execute
Chapter 8 - Constraints and Data Relations Commands, 433-435
stored procedures and views
Chapter 9 - ADO.NET Exception Handling
AddCat1 Stored Procedure, 404
Chapter 10 - Working with the ODBC .NET Data Provider
Executing mySP Stored Procedure Using SQL Data Provider, 400-401
Chapter 11 - Stored Procedures and Views
Executing Stored Procedure with Output Parameter, 404-405
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Executing Views Programmatically, 410
Chapter 13 - Developing a Custom Data Provider
Parameters, Using in Stored Procedure, 402-404
Chapter 14 Studio
Visual - Developing
.NET data Database Web Applications using ASP.NET
components
Chapter Added
15 - Using
Sql Server Provider Web
ADO.NET in Xml Services 48-49
Components,
Chapter Calling
16 - ASP.NET Server Controls
DataForm1 from Button Click, and Data 65
Binding
Chapter Calling
17 - Building Real-World Web Applications
DataForm2 from Button Click, 66
Chapter Cancel
18 - Object-Relational
All Button ClickMapping in .NET 71
Event Handler,
Chapter DataAdapter Connection
19 - Mapped Objects: through TableMapping,
Performance 49 Data Binding
Considerations and
Chapter FillDataSet Method Generated
20 - COM Interoperability by Data Form Wizard, 69
and ADO.NET
Chapter Form's Load Event Handler, 50-51
21 - Messaging
Chapter Load and Server
22 - SQL Updateand Button Click Event
ADO.NET: Handlers,
Notes on 67-68
Performance
AppendixLoadDataSet
A - RelationalMethod Generated
Databases: by Data
Some Basic Form Wizard, 68-69
Concepts
AppendixUpdateDataSource
B - Commonly Usedand SQLUpdateDataSet
Statements Methods Generated by Data Form Wizard, 70-71
Web applications, building Button
Appendix C - ADO.NET Frequently Asked Questions
Click Event Handlers, 614-615
DisplayData.aspx HTML View, 624-627
Index
Done Button Click Event Handler, 620,623
List of Figures
FillDataGrid and Page_Load Methods, 627,629
List of Tables
FillPartialData Method, 628
List of Listings
Login Button Click Event Handler Code, 613
List of Sidebars
Post Job Button Click Event Handler, 619
Post Resume Button Click Event Handler, 622-623
Post Resume Page, Adding Options to, 621-622
Register.aspx Code, 616
Resumes.aspx HTML View, 630-632
Send Message Click Event Handler, 618
XML integration with ADO.NET
Adding a Node with Attributes, 260
Adding Nodes to a Document, 256
Appending in an XML Document Fragment, 254
GetAttribute of a Node, Using, 243-244
Getting Node Information, 240-241
Getting Root Node of Document, 256
Applied ADO.NET: Building Data-Driven Solutions
Getting XML Node Information, 240
by Mahesh
Inserting XML FragmentChandintoand David Talbot
Document, 259 ISBN:1590590732
Apress 2003 (928
MoveToContent Method, Using, 243pages)
This text
Moving to Root andprovides
First Childextensive
Nodes coverage of ADO.NET technology
Using XPathNavigator, 274-275
including ADO.NET internals, namespaces, classes, and
Output of XmlWriterSample.vb Class, 249-250
interfaces, and takes a comprehensive look at XML
Reading an XML file, 239
namespaces and classes, and how to integrate both with
RemoveAllADO.NET.
for books.xml, Calling, 258
Removing All Items of a Node, 257
ReplaceChild, Calling, 258
Table of Saving
Contents
DataSet Data to XML Document, 271-272
Applied ADO.NETBuilding
Skip Method, Using, Data-Driven
244 Solutions
Introduction
WriteXml method Output, 266
Chapter WriteXml
1 - ADO.NET Basics
method, Using, 265-266
Chapter WriteXmlSchema
2 - Data Components in Visual
Method, Studio
Using, 267 .NET
Chapter XML Schema Generated
3 - ADO.NET for Database
in Disconnected Table, 284-285
Environments
Chapter XmlConvert
4 - ADO.NET Class, Using, 251
in Connected Environments
Chapter XmlDataDocumentSample.vb,
5 - Handling ADO.NET Events 270
Chapter XmlDocumentFragment
6 - Integrating XML withSample,
ADO.NET254
Chapter XmlWriter Example,
7 - Data Binding and248-249
Windows Forms Data-Bound Controls
Chapter XPathIterator andand
8 - Constraints Select, Using, 276-277
Data Relations
XPathNavigator, Reading
Chapter 9 - ADO.NET Exception Handling
Document Using, 275-276
XSL Transformation, 262
Chapter 10 - Working with the ODBC .NET Data Provider
XML Web services
Chapter 11 - Stored Procedures and Views
Button-Click Event Handler for Calling Order Retrieval Web Service, 528-529
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Client Event Handler for Executing Web Service, 533
Chapter 13 - Developing a Custom Data Provider
ExecuteQuery Method, 534
Chapter GetOrdersFromDatabase
14 - Developing Database Web Applications
Method, 521 using ASP.NET
Chapter Populating
15 - Using ADO.NET in Xml Web Services
an Order in Database, Web Service Method for, 530-531
Chapter WebService
16 - ASP.NETandServer Controls and
WebMethod Data Binding
Attributes, Adding Descriptions to, 522-524
Chapter 17 - Building Real-World Web Applications
Color and Font Properties, Using DataGrid's (code listing), 320
Chapter 18 - Object-Relational Mapping in .NET
columns
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
column and table mapping, 178-181
Chapter 20 - COM Interoperability and ADO.NET
ColumnChanged event, 222-223
Chapter 21 - Messaging
ColumnChanging and ColumnChanged Event Handlers, Writing (code listing), 222-223
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
ColumnMapping property, 92
Appendix A - Relational Databases: Some Basic Concepts
ColumnMapping Property of DataColumn, Using (code listing), 92
AppendixColumns
B - Commonly Used
property SQL494-495
page, Statements
AppendixCreating
C - ADO.NET Frequently Asked Questions
Using Different DataColumn Constructors (code listing), 88-89
Index customizing and rearranging, 587-589
List of Figures
defined, 779
List of Tables
determinant,785
header names, getting, 332
List of Listings
mappings, 45
List of Sidebars
selecting for indexing, 757-758
understanding, 586-587
COM (Component Object Model)
marshaling,12-13
Web services and, 517
COM interoperability, 709-724
.NET Framework interop tools, 710-712
Type Library Exporter (Tlbexp.exe), 712
Type Library Importer (Tlbimp.exe), 711
Visual Studio .NET, 710
ADO recordset and ADO.NET, 712-716
ADOX, using with ADO.NET, 716-718
Applied ADO.NET: Building Data-Driven Solutions
basics,709-710
code listings by Mahesh Chand and David Talbot ISBN:1590590732
Apress 2003 (928 pages)
ADODB Namespace to Access a Database, 715-716
ADOX from This text provides
Managed Code,extensive coverage of ADO.NET technology
Using, 717-718
including ADO.NET internals, namespaces, classes, and
Getting All Dimensions of a Cube, 722-723
interfaces, and takes a comprehensive look at XML
Getting Cubes from FoodMart
namespaces 2000and
and classes, Database, 721-722both with
how to integrate
Getting Dimension
ADO.NET.Members, 723-724
COM and .NET Interoperability,709
OLAP server data, accessing, 718-724
Table of Contents
ComboBox and ListBox controls, data binding in, 304-306
Applied ADO.NETBuilding Data-Driven Solutions
Comma Separated Values (CSV) format, 438
Introduction
Chapter
Command1 - Behaviors,
ADO.NET Basics
165-166
Chapter
Command2 - components,
Data Components
75 in Visual Studio .NET
Chapter 3 - ADO.NET in Disconnected Environments
Command objects
Chapter 4 - ADO.NET in Connected Environments
basics,17-18
Chapter 5 - Handling ADO.NET Events
creating,25
Chapter 6 - Integrating XML with ADO.NET
in custom data provider interfaces, 440-441
Chapter 7 - Datafor
vs. DataSet Binding anddata
updating Windows Forms
sources, Data-Bound Controls
776
Chapter 8 - Constraints
properties, 150 and Data Relations
Chapter
SQL9 statements,
- ADO.NET executing,
Exception Handling
150-160
Chapter calling
10 - Working
stored with the ODBC155-157
procedures, .NET Data Provider
Chapter Command
11 - Storedmethods,
Procedures and Views
160
Chapter Command
12 - Oracle,properties, 150-151
SQLXML, and Other .NET Data Providers
Chapter 13 - Developing a Custom Data154-155
CommandType enumeration, Provider
Chapter creating Command
14 - Developing objects,
Database Web 151-153
Applications using ASP.NET
Chapter executing
15 - UsingCommands, 158-160
ADO.NET in Xml Web Services
OleDbCommand, creating
Chapter 16 - ASP.NET Server Controls and using,
and Data 153-154
Binding
TableDirect, 157-158
Chapter 17 - Building Real-World Web Applications
CommandBehavior
Chapter 18 - Object-Relational Mapping in .NET
enumeration,
Chapter 843-844
19 - Mapped Objects: Performance Considerations and Data Binding
understanding,
Chapter 165-166
20 - COM Interoperability and ADO.NET
Chapter 21 - Messaging
CommandBuilder object
creating,
Chapter 182 Server and ADO.NET: Notes on Performance
22 - SQL
defined,
Appendix A - 19
Relational Databases: Some Basic Concepts
SqlCommandBuilder
Appendix members,
B - Commonly Used 182
SQL Statements
SqlCommandBuilder,
Appendix using, Asked
C - ADO.NET Frequently 182-184
Questions
Index
CommandType enumeration, 154-155
List of Figures
Commit, Rollback, and Savepoints, 204-206
List of Tables
committed transactions, 747
List of Listings
complex
List and simple data binding, 288,538
of Sidebars
complex Web Forms controls, data binding in, 562-607
BaseDataList class, 562-563
DataGrid Web server control. SeeDataGrid Web server control
DataKeyCollection class, 563
DataList Web server control. SeeDataList Web server control
component isolation, 666-670
components of ADO.NET, 15-22
Command object, 17-18
CommandBuilder, 19
Connection object, 16-17
data providers, 15-16
DataAdapter object, 19-20
Applied ADO.NET: Building Data-Driven Solutions
DataSet structure, 20-21
by Mahesh 21-22
DataSets in DataViews, Chand and David Talbot ISBN:1590590732
Apress 2003 (928 pages)
concurrency
This text provides extensive coverage of ADO.NET technology
concurrency control,
including199
ADO.NET internals, namespaces, classes, and
transactions and, 198-200
interfaces, and takes a comprehensive look at XML
using,201-204namespaces and classes, and how to integrate both with
ADO.NET.
conditional statements in SQL, 799
Configure Data Adapter property, 46-47
Table of Contents
connected environments, ADO.NET in.
Applied ADO.NETBuilding Data-Driven Solutions
SeeADO.NET in connected
Introduction
environments
Chapter 1 - ADO.NET Basics
connecting to data sources. Seedata sources, connecting to
Chapter 2 - Data Components in Visual Studio .NET
Connecting
Chapter to SQL Server
3 - ADO.NET and Reading
in Disconnected SqlConnection Properties (code listing), 144-145
Environments
Chapter 4 - ADO.NET
Connecting in Connected
to SQL Server Environments
Using OleDb Data Provider (code listing), 144
Chapter 5 - Handling ADO.NET Events
Connection class members, 141
Chapter 6 - Integrating XML with ADO.NET
Connection component of DataProvider, 136
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
Connection
Chapter events, 211-215
8 - Constraints and Data Relations
Chapter 9 - ADO.NET
Connection Exception
Events, Writing Handling
Code That Executes (code listing), 214-215
Chapter 10 - Working
Connection objects with the ODBC .NET Data Provider
Chapter 11 - Stored
in custom Procedures
data provider and Views
interfaces, 439-440
Chapter 12 - Oracle,
definition SQLXML, and 16-17
and fundamentals, Other .NET Data Providers
Chapter 13 - Developing
properties, 140 a Custom Data Provider
Chapter 14 - Developing Database Web Applications using ASP.NET
connection pooling, 145-149
Chapter 15 - Using ADO.NET in Xml Web Services
connection strings
Chapter 16 - ASP.NET Server Controls and Data Binding
for different data providers, 845
Chapter 17 - Building Real-World Web Applications
Oracle .NET data provider, 417
Chapter 18 - Object-Relational Mapping in .NET
pooling and, 777
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
SqlXmlAdapter object, 428
Chapter 20 - COM Interoperability
understanding, 40 and ADO.NET
Chapter 21 - Messaging
connections
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
closing,26,142-145
Appendix A - Relational Databases: Some Basic Concepts
Connections, Creating Two with Different Strings (code listing), 147-148
Appendix B - Commonly Used SQL Statements
ConnectionState enumeration members, 213
Appendix C - ADO.NET Frequently
ConnectionString Asked Questions
property, 142
IndexConnectionType enumeration members, 141
List of Figures139-140
creating,
List of Tables
creating in Oracle .NET data provider, 416-418
List of Listings
data, 38-40
disconnected
List of Sidebars data and, 11-12
establishing,24-25
opening and closing, 142-145
properties and methods, 140-141
constraints
adding and removing, 350-351
code listings
Adding PRIMARY KEY Constraint to DataTable, 352
Constraints, Adding and Removing, 350-351
FOREIGN KEY Constraint, Creating, 347-348
Reading All Constraints of a Collection, 352
UNIQUE Constraint, Creating, 348-349
UNIQUE Constraints, Adding, 351
Applied ADO.NET: Building Data-Driven Solutions
Constraint classes, implementing, 346
by85
constraint rule, Mahesh Chand and David Talbot ISBN:1590590732
Apress 2003 (928 pages)
ConstraintCollection class, 349-350
This text class,
ForeignKeyConstraint provides extensive coverage
implementing, of ADO.NET technology
346-348
including ADO.NET internals, namespaces, classes, and
PRIMARY KEY constraints, adding, 352
interfaces, and takes a comprehensive look at XML
property,101 namespaces and classes, and how to integrate both with
reading all constraints,
ADO.NET. 352
SQL statements to add and remove, 352-353
types of, 345-346
TableUniqueConstraint
of Contents class, 348-349
Applied ADO.NETBuilding Data-Driven Solutions
Contact.aspx page (Online Job Board Application), 617-618
Introduction
Contains,
Chapter 1 Find, and Remove
- ADO.NET Basics Method of DataRowCollection, Using (code listing), 116
content2node,
Chapter moving
- Data to (XML),
Components 242-243
in Visual Studio .NET
Chapter
Control3and
- ADO.NET in Disconnected
Page classes Environments
in data binding, 301,539
Chapter 4 - ADO.NET in Connected Environments
Count (*) to determine number of rows, 823
Chapter 5 - Handling ADO.NET Events
Counting
Chapter 6 and Removing
- Integrating Binding
XML Objects (code listing), 290
with ADO.NET
CREATE
Chapter 7 PROCEDURE SQLWindows
- Data Binding and statement, 393Data-Bound Controls
Forms
Chapter
CREATE 8 TABLE
- Constraints and Data Relations
SQL statement, 353
Chapter 9 - ADO.NET Exception Handling
CREATE TABLE statements, 803
Chapter 10 - Working with the ODBC .NET Data Provider
CREATE VIEW SQL statements, 808-809
Chapter 11 - Stored Procedures and Views
CreateCommand
Chapter 12 - Oracle,and ChangeDatabase
SQLXML, methods,
and Other .NET 149-150
Data Providers
Chapter 13 - Developing a Method
CreateCustomersTable Custom (code
Data Provider
listing), 107-109
Chapter 14 - Developing Database Web Applications using ASP.NET
CreateDataSet Method (code listing), 322-323
Chapter 15 - Using ADO.NET in Xml Web Services
Creating a Queue (code listing), 737
Chapter 16 - ASP.NET Server Controls and Data Binding
Creating
Chapter 17DataView
- BuildingObjects From
Real-World a DataTable
Web Applications(code listing), 129
Chapter
Cubes 18 - Object-Relational Mapping in .NET
Getting
Chapter 19 -All Dimensions
Mapped Objects:ofPerformance
(code listing), 722-723
Considerations and Data Binding
Getting
Chapter 20 -from
COM FoodMart 2000 and
Interoperability Database (code listing), 721-722
ADO.NET
Chapter 21 - object,
CultureInfo Messaging
123
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
CurrencyManager
Appendix A - Relational Databases: Some Basic Concepts
DataGridTableStyle From (code listing), 316
Appendix B - Commonly Used295-296
and PropertyManager, SQL Statements
Appendix C - ADO.NET Frequently Asked
for synchronization of controls, 293Questions
Index
cursors
List of Figures
locks and, 766
List of Tables
and recordsets, 786-787
List of Listings
CustEmpView, 409-410
List of Sidebars
custom controls (server-side), 483
custom data providers, developing. Seedata providers, developing custom
custom filters and error messages, 364-365
Custom Properties, Adding and Removing (code listing), 93
Custom Properties of a DataSet, Setting and Reading (code listing), 123-124
Custom Recordset, Creating (code listing), 337
Customer/Orders Relationship Example (code listing), 102-105
CustRecordSet.vb (code listing), 335-336
Index Applied ADO.NET: Building Data-Driven Solutions
by Mahesh Chand and David Talbot ISBN:1590590732
Apress 2003 (928 pages)
D This text provides extensive coverage of ADO.NET technology
including ADO.NET internals, namespaces, classes, and
DAO (Data Access Objects), 4-5
interfaces, and takes a comprehensive look at XML
namespaces and 641,
Data Access Component (DAC), classes, and how
648-652, to integrate both with
770-775
ADO.NET.
Data Adapter Configuration Wizard, 41-51
DataAdapter, adding, 42-44
TableDataAdapter
of Contents properties, setting and reviewing, 44-46
DataGrid
Applied control, adding,
ADO.NETBuilding 42
Data-Driven Solutions
DataGrid control, filling with data, 50-51
Introduction
project
Chapter 1 -template,
ADO.NET 42Basics
reviewing options, 46-48 in Visual Studio .NET
Chapter 2 - Data Components
source code, 48-49
Chapter 3 - ADO.NET in Disconnected Environments
data binding
Chapter 4 - ADO.NET in Connected Environments
ASP.NET
Chapter server controls
5 - Handling ADO.NETand. SeeASP.NET server controls and data binding
Events
in ComboBox
Chapter and ListBox
6 - Integrating controls,
XML with ADO.NET304-306
in complex
Chapter Web
7 - Data Forms
Binding andcontrols,
Windows562-607
Forms Data-Bound Controls
Chapter 8
BaseDataList class, 562-563
- Constraints and Data Relations
DataGrid Web server control. SeeDataGrid Web server control
Chapter 9 - ADO.NET Exception Handling
DataKeyCollection class, 563
Chapter 10 - Working with the ODBC .NET Data Provider
DataList Web server control. SeeDataList Web server control
Chapter 11 - Stored Procedures and Views
Control and Page classes in, 539
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
mapped objects and, 675-684
Chapter bound
13 - Developing a Custom Data
objects, accessing Provider
properties of, 678-680
Chapter bound
14 - Developing
objects, using logic with, 680-685 using ASP.NET
Database Web Applications
Chapter connection
15 - Using ADO.NET in Xml Web Services
strings, 676
Chapter 16 - ASP.NET
read-only,537 Server Controls and Data Binding
Chapter
Repeater control and, 553 Web Applications
17 - Building Real-World
simple
Chapter 18 -and complex, 538 Mapping in .NET
Object-Relational
in simple
Chapter Web Forms
19 - Mapped controls,
Objects: 540-562
Performance Considerations and Data Binding
Chapter ASP.NET templates, 547-548
20 - COM Interoperability and ADO.NET
Chapter Button control, 540-541
21 - Messaging
Chapter Calendar control,and
22 - SQL Server 542-545
ADO.NET: Notes on Performance
AppendixDropDownList
A - Relational control, 558-560
Databases: Some Basic Concepts
ListBox control, 556-558
Appendix B - Commonly Used SQL Statements
ListControl class, 555-556
Appendix C - ADO.NET Frequently Asked Questions
Repeater control, 552-555
Index
templates, Web server control. Seetemplates, Web server control templates
List of Figures
TextBox, Button and Image controls, 560-562
List of Tables
in Web Forms, 537-539
List of Listings
data binding and data-bound controls, 287-344
List of Sidebars
code listings
AllowNavigation in Action, 319
Binding Multiple Controls Using Binding, 289
Binding TextBox Using Binding, 288-289
Counting and Removing Binding objects, 290
CreateDataSet Method, 322-323
Custom Recordset, Creating, 337
CustRecordSet.vb, 335-336
DataGridBoolColumn Class, Creating, 318
DataGrid's Caption Properties, 321
DataGrid's Color and Font Properties, Using, 320
DataGridTableStyle, Creating and Adding, 315
DataGridTableStyle From CurrencyManager, 316
Applied ADO.NET: Building Data-Driven Solutions
Exchanging the Button Click Handler, 329
FillDataGridbyand
Mahesh Chand and
Form_Load David Talbot
Methods, 328 ISBN:1590590732
Apress 2003 (928
FillDataGrid Method, 323-324,341 pages)
Table of Contents
Applied ADO.NETBuilding Data-Driven Solutions
Introduction
Chapter 1 - ADO.NET Basics
Chapter 2 - Data Components in Visual Studio .NET
Chapter 3 - ADO.NET in Disconnected Environments
Chapter 4 - ADO.NET in Connected Environments
Chapter 5 - Handling ADO.NET Events
Chapter 6 - Integrating XML with ADO.NET
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
Chapter 8 - Constraints and Data Relations
Chapter 9 - ADO.NET Exception Handling
Chapter 10 - Working with the ODBC .NET Data Provider
Chapter 11 - Stored Procedures and Views
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Chapter 13 - Developing a Custom Data Provider
Chapter 14 - Developing Database Web Applications using ASP.NET
Chapter 15 - Using ADO.NET in Xml Web Services
Chapter 16 - ASP.NET Server Controls and Data Binding
Chapter 17 - Building Real-World Web Applications
Chapter 18 - Object-Relational Mapping in .NET
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
Chapter 20 - COM Interoperability and ADO.NET
Chapter 21 - Messaging
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Appendix A - Relational Databases: Some Basic Concepts
Appendix B - Commonly Used SQL Statements
Appendix C - ADO.NET Frequently Asked Questions
Index
List of Figures
List of Tables
List of Listings
List of Sidebars
Index Applied ADO.NET: Building Data-Driven Solutions
by Mahesh Chand and David Talbot ISBN:1590590732
Apress 2003 (928 pages)
J This text provides extensive coverage of ADO.NET technology
joins and aliases,including
806-807ADO.NET internals, namespaces, classes, and
interfaces, and takes a comprehensive look at XML
namespaces
journal queues (system), 726and classes, and how to integrate both with
ADO.NET.
Table of Contents
Applied ADO.NETBuilding Data-Driven Solutions
Introduction
Chapter 1 - ADO.NET Basics
Chapter 2 - Data Components in Visual Studio .NET
Chapter 3 - ADO.NET in Disconnected Environments
Chapter 4 - ADO.NET in Connected Environments
Chapter 5 - Handling ADO.NET Events
Chapter 6 - Integrating XML with ADO.NET
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
Chapter 8 - Constraints and Data Relations
Chapter 9 - ADO.NET Exception Handling
Chapter 10 - Working with the ODBC .NET Data Provider
Chapter 11 - Stored Procedures and Views
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Chapter 13 - Developing a Custom Data Provider
Chapter 14 - Developing Database Web Applications using ASP.NET
Chapter 15 - Using ADO.NET in Xml Web Services
Chapter 16 - ASP.NET Server Controls and Data Binding
Chapter 17 - Building Real-World Web Applications
Chapter 18 - Object-Relational Mapping in .NET
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
Chapter 20 - COM Interoperability and ADO.NET
Chapter 21 - Messaging
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Appendix A - Relational Databases: Some Basic Concepts
Appendix B - Commonly Used SQL Statements
Appendix C - ADO.NET Frequently Asked Questions
Index
List of Figures
List of Tables
List of Listings
List of Sidebars
Index Applied ADO.NET: Building Data-Driven Solutions
by Mahesh Chand and David Talbot ISBN:1590590732
Apress 2003 (928 pages)
K This text provides extensive coverage of ADO.NET technology
including ADO.NET internals, namespaces, classes, and
keyset cursors, 786-787
interfaces, and takes a comprehensive look at XML
namespaces and classes, and how to integrate both with
ADO.NET.
Table of Contents
Applied ADO.NETBuilding Data-Driven Solutions
Introduction
Chapter 1 - ADO.NET Basics
Chapter 2 - Data Components in Visual Studio .NET
Chapter 3 - ADO.NET in Disconnected Environments
Chapter 4 - ADO.NET in Connected Environments
Chapter 5 - Handling ADO.NET Events
Chapter 6 - Integrating XML with ADO.NET
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
Chapter 8 - Constraints and Data Relations
Chapter 9 - ADO.NET Exception Handling
Chapter 10 - Working with the ODBC .NET Data Provider
Chapter 11 - Stored Procedures and Views
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Chapter 13 - Developing a Custom Data Provider
Chapter 14 - Developing Database Web Applications using ASP.NET
Chapter 15 - Using ADO.NET in Xml Web Services
Chapter 16 - ASP.NET Server Controls and Data Binding
Chapter 17 - Building Real-World Web Applications
Chapter 18 - Object-Relational Mapping in .NET
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
Chapter 20 - COM Interoperability and ADO.NET
Chapter 21 - Messaging
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Appendix A - Relational Databases: Some Basic Concepts
Appendix B - Commonly Used SQL Statements
Appendix C - ADO.NET Frequently Asked Questions
Index
List of Figures
List of Tables
List of Listings
List of Sidebars
Index Applied ADO.NET: Building Data-Driven Solutions
by Mahesh Chand and David Talbot ISBN:1590590732
Apress 2003 (928 pages)
L This text provides extensive coverage of ADO.NET technology
including ADO.NET internals, namespaces, classes, and
language support, ASP.NET, 466
interfaces, and takes a comprehensive look at XML
namespaces and199
last in wins concurrency control, classes, and how to integrate both with
ADO.NET.
lazy loading, 695-705
leaf pages, 756
Table of Contents
ListBox Control
Applied ADO.NETBuilding Data-Driven Solutions
binding methods and, 300
Introduction
and ComboBox Controls, Binding (code listing), 305-306
Chapter 1 - ADO.NET Basics
and ComboBox, data binding in, 304-306
Chapter
Data2 Binding
- Data in
Components in Visual
(code listing), Studio .NET
557-558
Chapter 3 -Control
ListBox ADO.NET in Disconnected
Event Environments
Handler, Adding (code listing), 302-303
Chapter 4 556-558
using, - ADO.NET in Connected Environments
Chapter 5 - Handling ADO.NET Events
ListChanged event, 229-230
Chapter 6 - Integrating XML with ADO.NET
ListControl- class,
Chapter 7
301-302
Data Binding and Windows Forms Data-Bound Controls
ListControl
Chapter 8 - class (Web and
Constraints Forms),
Data 555-556
Relations
Chapter 9 - DataBinding-related
ListControl ADO.NET Exception Handling
events, 302-303
Chapter 10 - Working with the ODBC .NET Data Provider
listings. Seecode listings
Chapter 11 - Stored Procedures and Views
Load method (XmlDocument class), 252-253
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
LoadData
Chapter 13 -and GetDataSet
Developing Methods
a Custom Data(code listing), 298-299
Provider
Chapter 14 - Developing
LoadDataSet Database Web
Method Generated Applications
by Data using ASP.NET
Form Wizard (code listing), 68-69
Chapter 15 - Using ADO.NET
LoadXml method, 269 in Xml Web Services
Chapter 16 - ASP.NET Server Controls and Data Binding
LOBs (Large Object Binary data types), 425
Chapter 17 - Building Real-World Web Applications
locking,18
Chapter 788-791
- Object-Relational Mapping in .NET
isolation
Chapter levels, 788-789
19 - Mapped Objects: Performance Considerations and Data Binding
locking modes, 790-791
Chapter 20 - COM Interoperability and ADO.NET
locks, avoiding,
Chapter 766
21 - Messaging
Chapter 22 - SQL
Login Button Server
Click and
Event ADO.NET:
Handler Notes
Code on listing),
(code Performance
613
Appendix A - Relational Databases: Some Basic Concepts
Login.aspx page (Online Job Board Application), 612-615
Appendix B - Commonly Used SQL Statements
Appendix C - ADO.NET Frequently Asked Questions
Index
List of Figures
List of Tables
List of Listings
List of Sidebars
Index Applied ADO.NET: Building Data-Driven Solutions
by Mahesh Chand and David Talbot ISBN:1590590732
Apress 2003 (928 pages)
M This text provides extensive coverage of ADO.NET technology
including ADO.NET internals, namespaces, classes, and
managed classes, 10
interfaces, and takes a comprehensive look at XML
namespaces
managed code, 10,709 and classes, and how to integrate both with
ADO.NET.
manual coding vs. IDE, 39
manual vs. designer development mode, 775
Table of Contents
mapped objects
Applied ADO.NETBuilding Data-Driven Solutions
caching mechanism, near-zero- impact, 706708
Introduction
code listings
Chapter 1 - ADO.NET Basics
Adding Videos() Array to VideoCategory Object, 695696
Chapter Code-Behind
2 - Data Components in Visual Studio
File of TestDataGrid .NET 676677
Program,
Chapter Code-Behind
3 - ADO.NETObjectin Disconnected Environments
of FancyBinding Page, 682684
Chapter Code-Behind
4 - ADO.NETObjectin Connected Environments
of LazyLoading Page, 697700
Chapter GetBlockedCategory
5 - Handling ADO.NET Events
Stored Procedure, 692693
Chapter HTML
6 - Integrating XML with
of FancyBinding ADO.NET
Page, 681682
Chapter HTML of TestGridObjects
7 - Data Binding and WindowsPage,Forms
679680
Data-Bound Controls
HTML Page of Lazy Loading
Chapter 8 - Constraints and Data Relations Page, 696697
Chapter HTML Side of TestDataGrid
9 - ADO.NET Page, 677678
Exception Handling
Incremental Lazy Loading Stored
Chapter 10 - Working with the ODBC .NET Data Procedure,
Provider701
Theoretical Shopping Cart
Chapter 11 - Stored Procedures and Views Example, 680681
Chapter VideoCategory and Related
12 - Oracle, SQLXML, Objects,
and Other 686691
.NET Data Providers
VideoCategoryIndexer, 701703
Chapter 13 - Developing a Custom Data Provider
VideoCategoryIndexer Test Case, 703704
Chapter 14 - Developing Database Web Applications using ASP.NET
WeakCache Object, 707708
Chapter 15 - Using ADO.NET in Xml Web Services
creating,644648
Chapter 16 - ASP.NET Server Controls and Data Binding
data binding and, 675684
Chapter 17 - Building Real-World Web Applications
bound objects, accessing properties of, 678680
Chapter bound
18 - Object-Relational Mapping
objects, using logic with,in680685
.NET
Chapter connection
19 - Mapped Objects:
strings, Performance Considerations and Data Binding
676
Chapter 20 - COM
definition and Interoperability
fundamentals, and 641ADO.NET
Chapter
large21master-detail
- Messaging relationships, 694705
Chapter incremental
22 - SQL Server
lazyand ADO.NET:
loading schemes,Notes700705
on Performance
AppendixlazyA - loading, 695700
Relational Databases: Some Basic Concepts
Appendixloading detail when
B - Commonly Usedmaster is loaded, 705
SQL Statements
master-detail relationships, problematic,
Appendix C - ADO.NET Frequently Asked Questions 684694
Index highly nested structures, 685691
large tree structures, 691693
List of Figures
tree optimization, 693694
List of Tables
mappings
List of Listings
column,45
List of Sidebars
object-relational in .NET. Seeobject- relational (OR) mapping in .NET
table,4546
marshaling, interoperability, 710
master-detail relationships
defined, 99
problematic,684694
highly nested structures, 685691
large tree structures, 691693
tree optimization, 693694
working with large, 694705
incremental lazy loading schemes, 700705
lazy loading, 695700
Applied ADO.NET: Building Data-Driven Solutions
loading detail when master is loaded, 705
by Mahesh Chand and David Talbot ISBN:1590590732
materialized views, 809
Apress 2003 (928 pages)
MaxLength property,
This 9394
text provides extensive coverage of ADO.NET technology
Merging including ADO.NET internals, namespaces, classes, and
interfaces, and takes a comprehensive look at XML
DataRow andnamespaces
DataTable Objects (code
and classes, listing),
and how to127
integrate both with
DataRow, DataTable
ADO.NET. or DataSet, 126127
Merge method, 126127
MergeFailed event, 220221
TableMergeFailed
of ContentsEvent Handler, Calling (code listing), 220221
Applied
TwoADO.NETBuilding
DataSet Objects Data-Driven Solutions
(code listing), 189
Introduction
Two DataSets (code listing), 126127
Chapter 1 - ADO.NET Basics
MessagePriority Enumeration members, 746
Chapter 2 - Data Components in Visual Studio .NET
messaging,725752
Chapter 3 - ADO.NET in Disconnected Environments
code listings
Chapter 4 - ADO.NET in Connected Environments
Creating a Queue, 737
Chapter 5 - Handling ADO.NET Events
Deleting a Queue, 738
Chapter 6 - Integrating XML with ADO.NET
Encrypted Messages, Sending, 751
Chapter Filtering
7 - Data BindingBased
Queues and Windows Forms Data-Bound
on Category, Controls
Machine Name, and Label, 733734
Chapter Getting
8 - Constraints
a Queue's and Data Relations
Properties, 738
Chapter Private
9 - ADO.NET Exception
and Public Handling
Queues, Retrieving, 732733
Chapter Receiving
10 - Working with thefrom
Messages ODBC a .NET Data
Queue, Provider
743744
Chapter Sending
11 - Stored
andProcedures
Receiving and Views
Transactional Messages, 749750
Chapter Sending Messages
12 - Oracle, SQLXML, toand
a Queue, 743 Data Providers
Other .NET
encrypting messages, 750751
Chapter 13 - Developing a Custom Data Provider
message
Chapter queuing Database Web Applications using ASP.NET
14 - Developing
creating
Chapter 15 - Using and deletinginmessage
ADO.NET Xml Web queues
Servicesprogrammatically, 735736
fundamentals, 725
Chapter 16 - ASP.NET Server Controls and Data Binding
Chapter installing, 726727
17 - Building Real-World Web Applications
managing queues with VS .NET, 731732
Chapter 18 - Object-Relational Mapping in .NET
MessageQueue class properties, 729730
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
MessageQueue instance, creating, 738739
Chapter 20 - COM Interoperability and ADO.NET
MessageQueueCriteria, filtering queues with, 734735
Chapter 21 - Messaging
MessageQueueTransaction class, 747
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
queue path, setting, 739740
Appendixretrieving
A - Relational Databases:
available queues,Some Basic Concepts
732734
Appendixsample
B - Commonly Usedcreating,
application, SQL Statements
736738
Appendixsending
C - ADO.NET Frequently
and receiving Asked Questions
messages, 740741
Index simple messaging application, creating, 741745
List of Figures
System.Messaging namespace, 727728
types of message queues, 725726
List of Tables
transactional
List of Listings messaging, 747750
working
List of Sidebarswith messages, 745750
creating and removing, 745
setting queue and message priorities, 746
meta-data, defined, 780
MFC (Microsoft Foundation Classes) overview, 5
Microsoft Access, 4,43
Microsoft Data Access Technologies, overview, 27
ADO,6
ADO.NET,67
DAO,45
MFC,5
ODBC,24
OLE DB, 56 Applied ADO.NET: Building Data-Driven Solutions
RDO, 5 by Mahesh Chand and David Talbot ISBN:1590590732
Apress 2003 (928 pages)
Microsoft Message Queuing (MSMQ), 725
This text provides extensive coverage of ADO.NET technology
Microsoft .NET Class Library,
including 465 internals, namespaces, classes, and
ADO.NET
interfaces, and takes a comprehensive look at XML
Microsoft Transaction Server and
namespaces (MTS), 7 and how to integrate both with
classes,
ADO.NET.
Microsoft Universal Description, Discovery and Integration (UDDI) Business Registry, 526
Microsoft Visual Studio .NET (VS .NET). SeeVisual Studio .NET
Table of Contents
Microsoft.Data.Odbc namespace, 377,
Applied ADO.NETBuilding Data-Driven Solutions
Microsoft.Data.SqlXml namespace, 427
Introduction
Mobile Internet
Chapter 1
Toolkit, ASP.NET, 388 466467
- ADO.NET Basics
Move Next,
Chapter MoveComponents
2 - Data Previous, Move First,Studio
in Visual Move.NET
Last Button Code (code listing), 299
Chapter 3 - ADO.NET
MoveToContent in Disconnected
method (nodes), 242Environments
Chapter 4- ADO.NET in Connected Environments
MoveToContent Method, Using (code listing), 243
Chapter 5 - Handling ADO.NET Events
MoveToMethod (nodes), 242
Chapter 6 - Integrating XML with ADO.NET
Moving7Record
Chapter - DataButton Click
Binding and Event Handlers
Windows (code listing),
Forms Data-Bound 337338
Controls
Chapter
Moving8to -Root
Constraints and
and First Data
Child Relations
Nodes Using XPathNavigator (code listing), 274275
Chapter 9 - ADO.NET Exception
msadomd.dll library, 718719 Handling
Chapter 10 - Working with the ODBC .NET Data Provider
MSXML (Microsoft XML), 6
Chapter 11 - Stored Procedures and Views
multi-item
Chapter 12 -data-bound controls,
Oracle, SQLXML, and 488
Other .NET Data Providers
multiple13Catch
Chapter statements,
- Developing 363364
a Custom Data Provider
Chapter
multiple14columns,
- Developing Database
grid lines, andWeb Applications
alternating rows,using ASP.NET
568569
Chapter 15 - Using ADO.NET in Xml Web Services
multiple tables, filling DataSet from, 188189
Chapter 16 - ASP.NET Server Controls and Data Binding
multiple17views
Chapter - Building Real-World Web Applications
creating,195197
Chapter 18 - Object-Relational Mapping in .NET
filling DataSets from, 411
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
My Home
Chapter 20 -Page
COM and View Guestand
Interoperability Book Buttons (code listing), 514
ADO.NET
Chapter 21 -67
MyDS.xsd, Messaging
Chapter
MySQL22 - SQL Server and ADO.NET: Notes on Performance
Database
Appendix A - Relational
and .NET Databases:
data provider, 435 Some Basic Concepts
Appendix B - Commonly
accessing, 380382Used SQL Statements
Appendix C - ADO.NET
Accessing Frequently
(code listing), 382Asked Questions
Index
List of Figures
List of Tables
List of Listings
List of Sidebars
Index Applied ADO.NET: Building Data-Driven Solutions
by Mahesh Chand and David Talbot ISBN:1590590732
Apress 2003 (928 pages)
N This text provides extensive coverage of ADO.NET technology
including ADO.NET internals, namespaces, classes, and
namespaces
interfaces, and takes a comprehensive look at XML
and classes overview,
namespaces13-14
and classes, and how to integrate both with
data provider,ADO.NET.
38
importing,137
references, adding, 23-24
TableSystem.SqlClient,
of Contents 137-139
Applied ADO.NETBuilding Data-Driven Solutions
Navigation and DataGrid sorting, setting, 318-319
Introduction
nested 1data
Chapter relations,Basics
- ADO.NET 356
nested 2structures,
Chapter 685-691 in Visual Studio .NET
- Data Components
Chapter
nested 3transactions,
- ADO.NET 198
in Disconnected Environments
Chapter 4 - ADO.NET in Connected Environments
Nested Try...Catch and Multiple Catch Blocks (code listing), 363-364
Chapter 5 - Handling ADO.NET Events
nesting6Try...Catch
Chapter statements,
- Integrating XML with 363
ADO.NET
.NET 7
Chapter - Data Binding and Windows Forms Data-Bound Controls
1.1 8updates,
Chapter implementing,
- Constraints and Data391
Relations
Base Class Library,
Chapter 9 - ADO.NET Exception14 Handling
Common
Chapter Language
10 - Working withRuntime
the ODBC (CLR) services,
.NET Data 1
Provider
data provider, MySQL and, 435
Chapter 11 - Stored Procedures and Views
data providers, choosing, 22-23
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Framework and XML, 233-238
Chapter 13 - Developing a Custom Data Provider
Document Object Model (DOM) interfaces, 237
Chapter 14 - Developing Database Web Applications using ASP.NET
System.Xml namespace, 234-235
Chapter 15 - Using ADO.NET in Xml Web Services
System.Xml namespace reference, adding, 238
Chapter 16 - ASP.NET Server Controls and Data Binding
System.Xml.Schema namespace, 235
Chapter System.Xml.Serialization
17 - Building Real-World Web Applications
namespace, 236
Chapter System.Xml.XPath
18 - Object-Relational Mapping in 236
namespace, .NET
Chapter System.Xml.Xsl
19 - Mapped Objects: Performance
namespace, 236 Considerations and Data Binding
Chapter XML
20 - COM
.NETInteroperability and ADO.NET
architecture, 237-238
Chapter 21 - Messaging
Framework Class Library, 366
Framework
Chapter 22 - SQLinterop
Server tools, 710-712 Notes on Performance
and ADO.NET:
AppendixType Library Exporter
A - Relational (Tlbexp.exe),
Databases: Some Basic712
Concepts
Type Library Importer (Tlbimp.exe),
Appendix B - Commonly Used SQL Statements 711
AppendixVisual Studio .NET,
C - ADO.NET 710 Asked Questions
Frequently
Index Framework Library
data providers in, 38
List of Figures
server-side controls and, 483-485
List of Tables
XML Web services and, 518
List of Listings
Runtime Class Library, 76
List of Sidebars
Software Development Kit (SDK), 376,710
XML API, 237
New Query Wizard (Access), 43
nodes
Adding a Node With Attributes (code listing), 260
adding attributes to, 259-260
adding to documents, 256
GetAttributes of (XML), 243-244
getting root, 256
node information, getting (XML), 239-242
NodeChanged Event Handler (code listing), 228
NodeInserted Event Handler (code listing), 229
Applied ADO.NET: Building Data-Driven Solutions
NodeRemoved Event Handler (code listing), 229
Nodes, AddingbytoMahesh Chand (code
a Document and David Talbot
listing), 256 ISBN:1590590732
Apress 2003
removing and replacing, 257 (928 pages)
XML designer,This
277text provides extensive coverage of ADO.NET technology
including ADO.NET internals, namespaces, classes, and
Visual Studio .NET data components,
interfaces, and takes a33-71
comprehensive look at XML
code listings namespaces and classes, and how to integrate both with
ADO.NET.From Button Click, 65
Calling DataForm1
Calling DataForm2 From Button Click, 66
Cancel All Button Click Event Handler (code listing), 71
Table of Contents
DataAdapter Connection Through TableMapping, 49
Applied ADO.NETBuilding Data-Driven Solutions
FillDataSet Method Generated by Data Form Wizard, 69
Introduction
Form's Load Event Handler, 50-51
Chapter 1 - ADO.NET Basics
LoadDataSet Method Generated by Data Form Wizard, 68-69
Chapter 2 - Data Components in Visual Studio .NET
Sql Server Provider Components, Added, 48-49
Chapter UpdateDataSource
3 - ADO.NET in Disconnected Environments
and UpdateDataSet Methods Generated by Data Form Wizard, 70-71
Chapter 4 - ADO.NET
connection strings, 40 in Connected Environments
Chapter 5 - Handling
creating ADO.NET ADO.NET
project,Events
33
Chapter 6 - Integrating
data connections, 38-40 XML with ADO.NET
Chapter
Data7 Form
- Data Binding57-71
Wizard, and Windows Forms Data-Bound Controls
Chapter adding items, 58 and Data Relations
8 - Constraints
Chapter calling form from
9 - ADO.NET application,
Exception 65-66
Handling
Chapter creating relationship
10 - Working with thebetween
ODBC .NETtables,
Data60-61
Provider
Chapter Data Connection,
11 - Stored choosing,
Procedures 59
and Views
Chapter DataForm1
12 - Oracle, .vb, 67-71and Other .NET Data Providers
SQLXML,
DataSet, choosing,
Chapter 13 - Developing a Custom 59 Data Provider
display style, choosing, 62-65
Chapter 14 - Developing Database Web Applications using ASP.NET
displaying tables and columns, 62
Chapter 15 - Using ADO.NET in Xml Web Services
MyDS.xsd,67
Chapter 16 - ASP.NET Server Controls and Data Binding
project template, 58
Chapter 17 - Building Real-World Web Applications
tables or views, choosing, 59-60
Chapter 18 - Object-Relational Mapping in .NET
viewing output, 66
Chapter 19 - Mapped
DataSet Objects:components,
and DataView Performance 51-57
Considerations and Data Binding
Chapter typed
20 - COM Interoperability and
DataSets in VS .NET, 51-54 ADO.NET
Chapter understanding
21 - MessagingDataView, 54-57
Chapter 22 - SQL Server
fundamentals, 37-38and ADO.NET: Notes on Performance
Appendix A - Relational
Server Explorer, 34-36 Databases: Some Basic Concepts
Appendixadding new connection,
B - Commonly Used SQL35 Statements
Appendixmanaging
C - ADO.NETand Frequently
viewing data, 36 Questions
Asked
IndexSQL DataAdapters, 40-51
Data Adapter Configuration Wizard. SeeData Adapter Configuration Wizard
List of Figures
Server Explorer, creating DataAdapters with, 41
List of Tables
List of Listings
List of Sidebars
Index Applied ADO.NET: Building Data-Driven Solutions
by Mahesh Chand and David Talbot ISBN:1590590732
Apress 2003 (928 pages)
W This text provides extensive coverage of ADO.NET technology
including ADO.NET internals, namespaces, classes, and
WeakCache Object (code listing), 707708
interfaces, and takes a comprehensive look at XML
Web applicationsnamespaces and classes, and how to integrate both with
defined, 468 ADO.NET.
using ASP.NET. SeeASP.NET for database Web applications
Webof
Table applications,
Contents building, 609636
code
Applied listings
ADO.NETBuilding Data-Driven Solutions
Button Click Event Handlers, 614615
Introduction
Chapter DisplayData.aspx HTML View, 624627
1 - ADO.NET Basics
Chapter Done Button
2 - Data Click Event
Components in Handler, 620,.NET
Visual Studio 623
FillDataGrid
Chapter 3
and Page_Load Methods, 627,629
- ADO.NET in Disconnected Environments
FillPartialData Method, 628
Chapter 4 - ADO.NET in Connected Environments
Login Button Click Event Handler Code, 613
Chapter 5 - Handling ADO.NET Events
Post Job Button Click Event Handler, 619
Chapter 6 - Integrating XML with ADO.NET
Post Resume Button Click Event Handler, 622623
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
Post Resume Page, Adding Options to, 621622
Chapter Register.aspx
8 - Constraints and Data
Code, 616 Relations
Chapter Resumes.aspx
9 - ADO.NET Exception
HTML View, Handling
630632
Chapter Send
10 - Working with the ODBC .NET Data618
Message Click Event Handler, Provider
Chapter 11 - Stored Procedures
database schema, 610611 and Views
Chapter 12 -Job
Online Oracle, SQLXML,
Board and Other
Application, .NET Data
developing, Providers
611635
Chapter Contact.aspx page,
13 - Developing 617618
a Custom Data Provider
Chapter DisplayData.aspx and Resumes.aspx
14 - Developing Database pages,
Web Applications 623632
using ASP.NET
Chapter dnjHeader.aspx page,
15 - Using ADO.NET 632633
in Xml Web Services
Chapter improving/modifying
16 - ASP.NET Server application,
Controls and635636
Data Binding
Chapter Login.aspx page,
17 - Building 612615
Real-World Web Applications
Chapter PostJob.aspx page, 618620
18 - Object-Relational Mapping in .NET
PostResume.aspx page, 620623
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
Register.aspx page, 615616
Chapter 20 - COM Interoperability and ADO.NET
running the application, 633635
Chapter 21 - Messaging
specifications, 609610
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Web controls
Appendix A - Relational Databases: Some Basic Concepts
adding to Web Forms (ASP.NET), 472473
Appendix B - Commonly Used SQL Statements
MyGuestBook.aspx,508
Appendix C - ADO.NET Frequently Asked Questions
properties, setting (ASP.NET), 474475
Index
ViewGuestBook.aspx, 511
List of Figures
Web
List Forms
of Tables
adding, editing, and deleting in, 502504
List of Listings
adding server-side controls to, 485487
List of Sidebars
controls,480,485
defined, 468
guest book, adding to, 511514
Web References Wizard, 528
Web server controls, 481482
Web-service-based data provider, 437
Web services
creating consumer, 524534
adding data to database, 529533
adding functionality, 534
defined, 468
WebService and WebMethod Attributes, Adding Descriptions to (code listing), 522524
XML.SeeXMLApplied ADO.NET: Building Data-Driven Solutions
Web services
by Mahesh Chand and David Talbot ISBN:1590590732
Web sites Apress 2003 (928 pages)
Apress,297
This text provides extensive coverage of ADO.NET technology
C# Corner discussion
including newsgroup, 811 namespaces, classes, and
ADO.NET internals,
C# Corner's XML.NET
interfaces,section,
and takes233, 297
a comprehensive look at XML
namespaces
connection strings for dataand classes, 845
providers, and how to integrate both with
ADO.NET. forms info, 786
database design/normal
DBTools download, 381
Duwamish7 demo application download, 639
Table of Contents
locking and concurrency levels information, 791
Applied ADO.NETBuilding Data-Driven Solutions
Microsoft,376
Introduction
Microsoft downloads, 414
Chapter 1 - ADO.NET Basics
Microsoft TreeView control, 693
Chapter 2 - Data Components in Visual Studio .NET
MySQL database/tools download, 380
Chapter 3 databases,
object - ADO.NET in Disconnected Environments
639
Chapter
ODBC drivers, 381 Connected Environments
4 - ADO.NET in
Chapter 5 -data
Oracle Handling ADO.NET
provider Events
article, 414
Chapter 6 - Integrating XML
OraDirect.NET download, 414 with ADO.NET
Chapter 7 - Data Binding and Windows
relational databases online resources, Forms Data-Bound Controls
792
SQL8 online
Chapter references,
- Constraints and 810
Data Relations
SQL9 Server
Chapter performance
- ADO.NET Exception info, 760
Handling
SQLXML
Chapter updateswith
10 - Working andthe
downloads,
ODBC .NET 426Data Provider
transaction
Chapter processing
11 - Stored info,and
Procedures 789Views
Chapter 12characters,
wildcard - Oracle, SQLXML,
194 and Other .NET Data Providers
Chapter
Windows13 Registry,
- Developing a Custom Data
reading/writing Provider
to, 828831
Chapter 14 - Developing Database Web Applications using ASP.NET
wiring protocol, 518
Chapter 15 - Using ADO.NET in Xml Web Services
WriteXml
Chapter 16 method, 264265
- ASP.NET Server Controls and Data Binding
WriteXml
Chapter 17 Method Output
- Building (codeWeb
Real-World listing), 266
Applications
Chapter 18 Method,
WriteXml - Object-Relational
Using (codeMapping in 265266
listing), .NET
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
WriteXmlSchema method, 127,266267
Chapter 20 - COM Interoperability and ADO.NET
writing 21
Chapter XML items, 247248
- Messaging
WSDL 22
Chapter (Web Service
- SQL Description
Server Language),
and ADO.NET: Notes on517, 527
Performance
Appendix A - Relational Databases: Some Basic Concepts
Appendix B - Commonly Used SQL Statements
Appendix C - ADO.NET Frequently Asked Questions
Index
List of Figures
List of Tables
List of Listings
List of Sidebars
Index Applied ADO.NET: Building Data-Driven Solutions
by Mahesh Chand and David Talbot ISBN:1590590732
Apress 2003 (928 pages)
X This text provides extensive coverage of ADO.NET technology
XML (Extensible including ADO.NET internals, namespaces, classes, and
Markup Language), support, 8,10,1213
interfaces, and takes a comprehensive look at XML
XML integration with ADO.NET, 233286 and how to integrate both with
namespaces and classes,
code listings ADO.NET.
Adding Node with Attributes, 260
Adding Nodes to Document, 256
Table of Contents
Appending in XML Document Fragment, 254
Applied ADO.NETBuilding Data-Driven Solutions
GetAttribute of a Node, Using, 243244
Introduction
Getting Node Information, 240241
Chapter 1 - ADO.NET Basics
Getting Root Node of Document, 256
Chapter 2 - Data Components in Visual Studio .NET
Getting XML Node Information, 240
Chapter Inserting
3 - ADO.NET in Disconnected
XML Fragment Environments
into Document, 259
Chapter MoveToContent
4 - ADO.NET in Method,
Connected Environments
Using, 243
Chapter Moving
5 - Handling
to RootADO.NET
and FirstEvents
Child Nodes Using XPathNavigator, 274275
Chapter Output
6 - Integrating XML with ADO.NET
of XmlWriterSample.vb Class, 249250
Chapter Reading
7 - Dataan Binding and 239
XML file, Windows Forms Data-Bound Controls
Chapter RemoveAll for books.xml,
8 - Constraints Calling, 258
and Data Relations
Chapter Removing
9 - ADO.NET All Items of a Handling
Exception Node, 257
Chapter ReplaceChild,
10 - Working with Calling, 258 .NET Data Provider
the ODBC
Chapter Saving DataSet
11 - Stored Data toand
Procedures XML Document, 271272
Views
Chapter Skip
12 - Method, Using, 244
Oracle, SQLXML, and Other .NET Data Providers
Chapter WriteXml method
13 - Developing Output, Data
a Custom 266 Provider
WriteXml method, Using, 265266
Chapter 14 - Developing Database Web Applications using ASP.NET
WriteXmlSchema Method, Using, 267
Chapter 15 - Using ADO.NET in Xml Web Services
XML Schema Generated for Database Table, 284285
Chapter 16 - ASP.NET Server Controls and Data Binding
XmlConvert Class, Using, 251
Chapter 17 - Building Real-World Web Applications
XmlDataDocumentSample.vb,270
Chapter 18 - Object-Relational Mapping in .NET
XmlDocumentFragment Sample, 254
Chapter XmlWriter
19 - Mapped Objects:248249
Example, Performance Considerations and Data Binding
Chapter XmlWriterSample.vb
20 - COM Interoperability andOutput
Class, ADO.NET
of, 249250
Chapter XPathIterator
21 - Messaging and Select, 276277
Chapter XPathNavigator,
22 - SQL Server and ADO.NET:
Reading Notes on
Document Performance
Using, 275276
AppendixXSL A - Transformation,
Relational Databases:262 Some Basic Concepts
DOMB(Document
Appendix - CommonlyObject Model)
Used SQL implementation, 251260
Statements
Appendixadding attributes
C - ADO.NET to nodes,
Frequently 259260
Asked Questions
Index fragments, inserting into XML document, 259
saving documents, 253
List of Figures
XmlDocument class, 252253
List of Tables
XmlDocumentFragment class, 253254
List of Listings
XmlElement class, 254259
List of Sidebars
XmlNode class, 252
navigating in XML, 272277
searching using XPathNavigator, 276277
XPathNavigator class, 273
XPathNavigator move methods, 274276
.Net Framework and XML, 233238
document classes, 234
DOM interfaces, 237
reader and writer classes, 234
System.Xml namespace, 234235
System.Xml namespace reference, adding, 238
System.Xml.Schema namespace, 235
System.Xml.Serialization namespace, 236
Applied ADO.NET: Building Data-Driven Solutions
System.Xml.XPath namespace, 236
by Mahesh
System.Xml.Xsl Chand and
namespace, 236David Talbot ISBN:1590590732
Apress 2003 (928
XML .NET architecture, 237238 pages)
Figure 4-3: Creating a Windows Forms application and adding controls to the form
Figure 4-4: Filling data from an Access database to a DataGrid control using OleDbDataAdapter
Figure 4-5: Filling data from a SQL Server database to a DataGrid control using SqlDataAdapter
Figure 4-6: Column
Appliedmapping
ADO.NET: Building Data-Driven Solutions
by Mahesh Chand and David Talbot ISBN:1590590732
Figure 4-7: Default multiple views application
Apress 2003 (928 pages)
This text
Figure 4-8: Multiple provides
views with extensive coverage
different filter of ADO.NET
and sorting technology
criteria
including ADO.NET internals, namespaces, classes, and
interfaces, and takes a comprehensive look at XML
Chapter 5: Handling ADO.NET Events
namespaces and classes, and how to integrate both with
ADO.NET.
Figure 5-1: Event handler and event argument classes defined in the System.Data namespace
Table of Contents
Figure 5-2: OleDb data provider event handler and event arguments
Applied ADO.NETBuilding Data-Driven Solutions
Introduction
Figure 5-3: Output of the Open button click
Chapter 1 - ADO.NET Basics
Figure
Chapter 2 - 5-4:
DataOutput of the in
Components Close button
Visual click
Studio .NET
Chapter 3 - ADO.NET in Disconnected Environments
Chapter
Chapter 4 6: Integrating
- ADO.NET XML with ADO.NET
in Connected Environments
Chapter 5 - Handling ADO.NET Events
Chapter 6 - 6-1:
Figure Integrating XMLarchitecture
XML .NET with ADO.NET
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
Figure
Chapter 8 - 6-2:XmlReader
Constraints and Relations
and Data its derived classes
Chapter 9 - ADO.NET Exception Handling
Figure 6-3: The XmlWriter class and its derived classes
Chapter 10 - Working with the ODBC .NET Data Provider
Chapter 11 - 6-4:
Figure Stored
TheProcedures
XmlElementand Views
class inheritance
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Figure
Chapter 13 - 6-5: The XSL
Developing transformation
a Custom Data Provider
Chapter 14 - Developing Database Web Applications using ASP.NET
Figure 6-6: The XmlDataDocument class inheritance
Chapter 15 - Using ADO.NET in Xml Web Services
Chapter 16 - 6-7:
Figure ASP.NET Server
Reading andControls
writing and
dataData Binding
using XmlDataDocument
Chapter 17 - Building Real-World Web Applications
Figure
Chapter 18 - 6-8: The XML designer
Object-Relational Mapping in .NET
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
Figure 6-9: The XML schema Toolbox
Chapter 20 - COM Interoperability and ADO.NET
Chapter 21 - 6-10:
Figure Messaging
Adding a schema element and its type
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Figure
Appendix A - 6-11: Adding
Relational a new bookstore
Databases: Some Basic element
Concepts
Appendix B - Commonly Used SQL Statements
Figure 6-12: A complexType item
Appendix C - ADO.NET Frequently Asked Questions
IndexFigure 6-13: Adding other types to complexType item
List of Figures
List ofFigure
Tables6-14: The book complexType and its elements
List of Listings
Figure 6-15: The author and book complexTypes in an XML schema
List of Sidebars
Figure 6-16: Viewing the XML code for a schema
Figure 14-25: Viewing data in a DataGrid using the design-time data binding method
Table Figure B-9: Output of query that uses the SQL SUM function
of Contents
Applied ADO.NETBuilding Data-Driven Solutions
Figure B-10: Output of COUNT
Introduction
Chapter 1 - B-11:
Figure ADO.NET Basics
Output of GROUP BY
Chapter 2 - Data Components in Visual Studio .NET
Figure
Chapter 3 - B-12: Output
ADO.NET of the AliasEnvironments
in Disconnected statement
Chapter 4 - ADO.NET in Connected Environments
Figure- B-13:
Chapter 5
Output of the JOIN statement
Handling ADO.NET Events
Chapter 6 - Integrating XML with ADO.NET
Appendix
- DataC:
Chapter 7 ADO.NET
Binding Frequently
and Windows Asked
Forms Data-Bound ControlsQuestions
Chapter 8 - Constraints and Data Relations
Figure
Chapter 9 - C-1: Paging
ADO.NET in an ADO.NET
Exception Handling application
Chapter 10 - Working with the ODBC .NET Data Provider
Figure C-2: Getting a database schema programmatically
Chapter 11 - Stored Procedures and Views
Chapter 12 - C-3:
Figure Oracle, SQLXML,
Users table and Other .NET Data Providers
schema
Chapter 13 - Developing a Custom Data Provider
Figure
Chapter 14 - C-4: Reading
Developing and writing
Database Web images in a database
Applications final form
using ASP.NET
Chapter 15 - Using ADO.NET in Xml Web Services
Figure C-5: Displaying a bitmap after reading data from a database
Chapter 16 - ASP.NET Server Controls and Data Binding
Chapter 17 - C-6:
Figure Building Real-World
DiffGram Web Applications
format
Chapter 18 - Object-Relational Mapping in .NET
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
Chapter 20 - COM Interoperability and ADO.NET
Chapter 21 - Messaging
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Appendix A - Relational Databases: Some Basic Concepts
Appendix B - Commonly Used SQL Statements
Appendix C - ADO.NET Frequently Asked Questions
Index
List of Figures
List of Tables
List of Listings
List of Sidebars
List of Tables
Applied ADO.NET: Building Data-Driven Solutions
by Mahesh Chand and David Talbot ISBN:1590590732
Apress 2003 (928 pages)
Chapter 3: This
ADO.NET inextensive
text provides Disconnected Environments
coverage of ADO.NET technology
including ADO.NET internals, namespaces, classes, and
interfaces,
Table 3-1: The and takes
System.Data a comprehensive
Namespace look at XML
Classes
namespaces and classes, and how to integrate both with
ADO.NET.
Table 3-2: The System.Data.Common Namespace Classes
Table Table
of Contents
14-4: ASP.NET Data-Bound Controls
Applied ADO.NETBuilding Data-Driven Solutions
Table 14-5:DataGrid Control Properties
Introduction
Chapter 1 - ADO.NET Basics
Table 14-6: Web Controls on MyGuestBook.aspx Page
Chapter 2 - Data Components in Visual Studio .NET
Chapter 3 -14-7:
Table ADO.NET
WebinControls
Disconnected Environments
of ViewGuestBook.aspx
Chapter 4 - ADO.NET in Connected Environments
Table
Chapter 5 -14-8: Controls
Handling of Thanks.aspx
ADO.NET Events Page
Chapter 6 - Integrating XML with ADO.NET
Chapter
Chapter 716:Binding
- Data ASP.NET Server
and Windows Controls
Forms Data-Bound and Data Binding
Controls
Chapter 8 - Constraints and Data Relations
Chapter 9 -16-1:
Table ADO.NET Exception Handling
The Calendar Class Properties
Chapter 10 - Working with the ODBC .NET Data Provider
Table
Chapter 11 -16-2: ASP.NET
Stored Templates
Procedures and Views
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Table 16-3: Templates Supported by the Repeater Control
Chapter 13 - Developing a Custom Data Provider
Chapter 14 -16-4:
Table Developing Database
The Values Web
of the Applications
B Part usingFormat
of the Data ASP.NET
String of ListControl
Chapter 15 - Using ADO.NET in Xml Web Services
Table
Chapter 16 -16-5: The Server
ASP.NET BaseDataList Class
Controls and DataProperties
Binding
Chapter 17 - Building Real-World Web Applications
Table 16-6: The DataList Class Properties
Chapter 18 - Object-Relational Mapping in .NET
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
Table 16-7: The TableItemStyle Class Properties
Chapter 20 - COM Interoperability and ADO.NET
Chapter 21 -16-8:
Table Messaging
The DataGrid Control Events
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Appendix A - Relational Databases: Some Basic Concepts
Chapter 18: Object-Relational Mapping in .NET
Appendix B - Commonly Used SQL Statements
Appendix C - ADO.NET Frequently Asked Questions
Table 18-1: The VideoTape Table
Index
List ofTable 18-2: The VideoCheckIn Table
Figures
List of Tables
Table 18-3: The VideoCheckOut Table
List of Listings
List ofTable
Sidebars
18-4: The Users Table
Listing 3-9: Setting the Values of the Id, Address, and Name Columns of a DataRow
Listing 4-2: Connecting to an OleDb Database and Reading the OleDbConnection Properties
Listing 4-3: Connecting to a SQL Server Using the OleDb Data Provider
Listing 4-4: Connecting to a SQL Server and Reading the SqlConnection Properties
Listing 4-13: Adding the Subtotal Listing to the Output of the Stored Procedure Results
Table of Contents
Applied ADO.NETBuilding
Listing Data-Driven Solutions
4-14: Using TableDirect to Read a Table
Introduction
Listing
Chapter 1 - 4-15: Adding
ADO.NET Records to a Table Using the INSERT SQL Statement
Basics
Chapter 2 - Data Components in Visual Studio .NET
Listing 4-16: Using the ExecuteScalar Method to Retrieve a Single Value
Chapter 3 - ADO.NET in Disconnected Environments
Chapter 4 - 4-17:
Listing ADO.NET in Connected
DataReader Environments
Reads Data from a SQL Server Database
Chapter 5 - Handling ADO.NET Events
Listing
Chapter 6 - 4-18: Executing
Integrating XML Batches Using DataReader
with ADO.NET
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
Listing 4-19: Creating SqlDataAdapter Instances
Chapter 8 - Constraints and Data Relations
Chapter 9 - 4-20:
Listing ADO.NET Exception
Executing Handling* Statement Using OleDbDataAdapter
a SELECT
Chapter 10 - Working with the ODBC .NET Data Provider
Listing
Chapter 11 - 4-21:
StoredUsing
Procedures and Views
SqlDataAdapter Properties
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Listing
Chapter 13 - 4-22: Calling
Developing aaCustom Data ProviderFill Method
DataAdapter's
Chapter 14 - Developing Database Web Applications using ASP.NET
Listing 4-23: Using the FillSchema Method of SqlDataAdapter
Chapter 15 - Using ADO.NET in Xml Web Services
Chapter 16 - 4-24:
Listing ASP.NET Server Controls
Displaying andTable
the Orders Data Binding
Data in a DataGrid Using OleDbDataAdapter
Chapter 17 - Building Real-World Web Applications
Listing
Chapter 18 - 4-25: Displaying the
Object-Relational Customers
Mapping in .NETTable's Data in a DataGrid Using SqlDataAdapter
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
Listing 4-26: Setting the DeleteCommand Property of DataAdapter
Chapter 20 - COM Interoperability and ADO.NET
Chapter 21 - 4-27:
Listing Messaging
Creating a SqlParameter
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Listing
Appendix A - 4-28: Calling
Relational the FillSome
Databases: Method ofConcepts
Basic a DataAdapter
Appendix B - Commonly Used SQL Statements
Listing 4-29: Removing a Row and Calling the Update Method of a DataAdapter
Appendix C - ADO.NET Frequently Asked Questions
Index
Listing 4-30: Calling a DataAdapter'sUpdate Method
List of Figures
List ofListing
Tables4-31: Using DataTableMapping to Map the Orders Table of Northwind
List of Listings
List ofListing 4-32: Using DataTableMapping with the Table Option
Sidebars
Listing 7-34:CustRecordSet.vb
Listing 10-1: Reading Data from Northwind Using the ODBC Data Provider
Listing C-10: Reading and Writing to and from the Windows Registry
Table of Contents
Listing
Applied C-11: ReadingData-Driven
ADO.NETBuilding ODBC DSNs Solutions
Introduction
Listing C-12: Browse Button Click Event Handler
Chapter 1 - ADO.NET Basics
Chapter 2 - C-13:
Listing Data Components
Save ImageinButton
VisualClick
Studio .NETHandler
Event
Chapter 3 - ADO.NET in Disconnected Environments
Listing
Chapter 4 - C-14: Reading
ADO.NET Binary Data
in Connected Environments
Chapter 5
Listing- C-15:
Handling ADO.NET Events
A DiffGram Format
Chapter 6 - Integrating XML with ADO.NET
Chapter 7 - C-16:
Listing Data Binding
Readingand Windows Forms Data-Bound Controls
DiffGrams
Chapter 8 - Constraints and Data Relations
Listing
Chapter 9 - C-17: Reading
ADO.NET OnlyHandling
Exception Modified Rows of a DataSet
Chapter 10 - Working with the ODBC .NET Data Provider
Chapter 11 - Stored Procedures and Views
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Chapter 13 - Developing a Custom Data Provider
Chapter 14 - Developing Database Web Applications using ASP.NET
Chapter 15 - Using ADO.NET in Xml Web Services
Chapter 16 - ASP.NET Server Controls and Data Binding
Chapter 17 - Building Real-World Web Applications
Chapter 18 - Object-Relational Mapping in .NET
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
Chapter 20 - COM Interoperability and ADO.NET
Chapter 21 - Messaging
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Appendix A - Relational Databases: Some Basic Concepts
Appendix B - Commonly Used SQL Statements
Appendix C - ADO.NET Frequently Asked Questions
Index
List of Figures
List of Tables
List of Listings
List of Sidebars
Applied ADO.NET: Building Data-Driven Solutions
List of Sidebars
by Mahesh Chand and David Talbot ISBN:1590590732
Apress 2003 (928 pages)
Table of Contents
Applied ADO.NETBuilding Data-Driven Solutions
Introduction
Chapter 1 - ADO.NET Basics
Chapter 2 - Data Components in Visual Studio .NET
Chapter 3 - ADO.NET in Disconnected Environments
Chapter 4 - ADO.NET in Connected Environments
Chapter 5 - Handling ADO.NET Events
Chapter 6 - Integrating XML with ADO.NET
Chapter 7 - Data Binding and Windows Forms Data-Bound Controls
Chapter 8 - Constraints and Data Relations
Chapter 9 - ADO.NET Exception Handling
Chapter 10 - Working with the ODBC .NET Data Provider
Chapter 11 - Stored Procedures and Views
Chapter 12 - Oracle, SQLXML, and Other .NET Data Providers
Chapter 13 - Developing a Custom Data Provider
Chapter 14 - Developing Database Web Applications using ASP.NET
Chapter 15 - Using ADO.NET in Xml Web Services
Chapter 16 - ASP.NET Server Controls and Data Binding
Chapter 17 - Building Real-World Web Applications
Chapter 18 - Object-Relational Mapping in .NET
Chapter 19 - Mapped Objects: Performance Considerations and Data Binding
Chapter 20 - COM Interoperability and ADO.NET
Chapter 21 - Messaging
Chapter 22 - SQL Server and ADO.NET: Notes on Performance
Appendix A - Relational Databases: Some Basic Concepts
Appendix B - Commonly Used SQL Statements
Appendix C - ADO.NET Frequently Asked Questions
Index
List of Figures
List of Tables
List of Listings
List of Sidebars