Database Programming with C 1st Edition Carsten Thomsen (Auth.) pdf download
Database Programming with C 1st Edition Carsten Thomsen (Auth.) pdf download
https://ebookfinal.com/download/database-programming-with-c-1st-
edition-carsten-thomsen-auth/
https://ebookfinal.com/download/mastering-c-database-programming-1st-
edition-jason-price/
https://ebookfinal.com/download/murach-s-ado-net-4-database-
programming-with-c-2010-4th-edition-anne-boehm/
https://ebookfinal.com/download/practical-database-programming-with-
visual-basic-net-1st-edition-ying-bai/
https://ebookfinal.com/download/practical-database-programming-with-
visual-basic-net-2nd-edition-ying-bai/
Programming with ANSI C 2nd Edition Bhushan Trivedi
https://ebookfinal.com/download/programming-with-ansi-c-2nd-edition-
bhushan-trivedi/
https://ebookfinal.com/download/beginning-object-oriented-programming-
with-c-1st-edition-jack-purdum/
https://ebookfinal.com/download/c-gui-programming-with-qt-4-1st-
edition-jasmin-blanchette/
https://ebookfinal.com/download/professional-ios-database-application-
programming-2nd-edition-patrick-alessi/
https://ebookfinal.com/download/advances-in-photochemistry-
volume-29-1st-edition-douglas-c-neckers/
Database Programming with C 1st Edition Carsten
Thomsen (Auth.) Digital Instant Download
Author(s): Carsten Thomsen (auth.)
ISBN(s): 9781590590102, 1590590104
Edition: 1
File Details: PDF, 18.24 MB
Year: 2002
Language: english
Database Programming
with C#
CARSTEN THOMSEN
All rights reserved. No part of this work may be reproduced or transmitted in any form or by
any means, electronic or mechanical, including photocopying, recording, or by any information
storage or retrieval system, without the prior written permission of the copyright owner and
the publisher.
ISBN 978-1-59059-010-2 ISBN 978-1-4302-1098-6 (eBook)
DOI 10.1007/978-1-4302-1098-6
Trademarked names may appear in this book. Rather than use a trademark symbol with every
occurrence of a trademarked name, we use the names only in an editorial fashion and to the
benefit of the trademark owner, with no intention of infringement of the trademark.
Technical Reviewer: Douglas Milnes
Editorial Directors: Dan Appleman, Peter Blackburn, Gary Cornell, Jason Gilmore,
Karen Watterson, John Zukowski
Managing Editor: Grace Wong
Copy Editors: Nicole LeClerc, Ami Knox
Production Editor: Tory McLearn
Compositor: Impressions Book and Journal Services, Inc.
Indexer: Valerie Haynes Perry
Cover Designer: Tom Debolski
Marketing Manager: Stephanie Rodriguez
For information on translations, please contact Apress directly at 2560 9th Street, Suite 219,
Berkeley, CA 94710.
Email info@apress. com or visit http: I /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 the information contained in this work.
Contents at a Glance
Foreword .............................................................. .ix
About the Author ..................................................... .xi
About the Technical Reviewer .................................... .. xiii
Acknowledgments ..................................................... .xv
Introduction ........................................................ .xvii
iii
Contents at a Glance
iv
Contents
Foreword ............................................................ .ix
v
Contents
vi
Contents
vii
Contents
viii
Foreword
No MATTER WHAT APPLICATION you're building, there's no escape from dealing with
data and, subsequently, with databases. While new technologies can make our
lives easier, they're built with one thing in mind: to keep data at our fingertips.
The same goes for .NET, the new generation of Microsoft technology that
promises to make data interchange easier and more flexible, even across dis-
parate systems .. NET comes with a whole set of data-handling tools that will
give developers more choices when they build applications.
Carsten's book is a wonderful introduction to all these choices, some of
which even I did not give a second thought to before reading the book. Because
problems in real-life applications demand different solutions, it is important for
every developer to understand these different solutions. Not only will this make
developers more productive, but it will also make them more marketable.
Moreover, I believe, by covering topics such as hierarchical databases,
Message Queuing, and SQLXML, Carsten shows his expertise in the area of data
handling within the .NET Framework, which goes beyond the ADO.NET coverage
you see in most other books. Being a Microsoft MVP, Carsten often interacts with
people to solve their day-to-day problems, and the same conduct continues in
his book. So, when I was asked to review this book and write the foreword, I was
more than happy to oblige.
I hope this book opens your mind to the new possibilities within .NET.
I'm sure you'll appreciate Carsten's efforts to make learning data access with
.NET easy.
Manohar Kamath
Microsoft MVP and .netBooks Editor, (http: I /www. dot net books. com)
March2002
ix
About the Author
Carsten Thomsen is a Microsoft MVP, recognition he
received in August 1999. He lives in his native Denmark and
currently holds the MCSE and MCSD certifications. Carsten
has been programming in Visual Basic for almost 10 years,
and he specializes in data access. With the advent ofVB .NET
and, more important, VS .NET, Carsten now focuses on data
access using C# and VB .NET.
Carsten and his girlfriend Mia live in Esbjerg, Denmark. They have a 2-year-
old daughter, Caroline, and are currently expecting a second child. Nicole, 7, is
Carsten's oldest daughter and she lives with her mother in Dublin, Ireland.
Carsten enjoys traveling to Dublin several times a year to spend time with Nicole.
xi
About the Technical
Reviewer
Douglas Milnes is a freelance computer consultant who has
been running his own consultancy and application develop-
ment business since 1984. He lives in the heart of the United
Kingdom's "Silicon Valley" near Reading, Berkshire, England.
He has consulted for major companies such as IBM and
Oracle and is a lead consultant with both DeeSoft
(http: I /www. dee soft. net) and Boost Data
(http: I lwww. boost. net/Douglas).
Douglas started with computing at the beginning of the microcomputer
boom and opened a pioneering retail business in the days before the IBM PC
was launched. After disposing of that business, he worked for a range of com-
panies implementing PC and UNIX systems. His specialty was accounting
applications, which led him into stock control applications and his first "real"
database exposure.
Douglas owns up to a wide experience in the computing world, admitting to
being one of those programmers who carries a screwdriver with him. He has
worked with DGE, DEC, IBM, and ICL minis and mainframes, but he's spent most
of the last few years around PCs, linking to larger machines where necessary. Like
any programmer who's been around for a time, he works on desktop computers
these days that vastly outpower the multiuser minicomputers he learned about
databases on.
Douglas has extensive experience with several programming languages,
including Assembler, RPG, Visual Basic and, of course, C#. Tending to keep up
with the times and being at the leading edge of technology, he has been involved
with .NET since the beta pre-releases were available.
With his two children, Daniel, 12, and Rebecca, 15, and his beautiful wife,
Douglas counts his blessings and enjoys a varied life. Douglas can be contacted
by e-mail at Douglas@DeeSoft. net.
xiii
Acknowledgments
This book, which is based on my first book Database Programming with VB .NET,
was somewhat easier for me to write than the first one. Having been through all
the processes once before, I knew what to expect and how to plan accordingly.
Obviously, a lot of the material in this book is taken from the first book, but
a number of changes have been made, especially to correct the typos and more
grave errors, and I've managed to add a lot more content to the book.
I couldn't have written this without Technical Reviewer Douglas Milnes, who
proved to be extremely valuable for content of this book. Douglas found some of
the mistakes that I made, but he also brought a number of excellent ideas to my
attention, on how to arrange the book and on "sticking in" extra or just missing
sections. My editor this time around was Peter Blackburn. I can't really say that
we started off on the right foot (which was also the case with Douglas) but we
sure ash*** made up for it along the way. Peter has an "annoying" habit of con-
tacting me day and night on MSN Messenger, so we were always in close contact
about the book, the whole process, and just about everything else. What I am
getting at here, is that it truly has been an excellent partnership, not just with
Peter and Douglas, but also with the rest of the crew: Grace, Nicole, Alexa, Ami,
and Tory.
Carsten,[email protected]
Esbjerg, Denmark
March2002
XV
Introduction
THIS BOOK IS ALL ABOUT ACCESSING DATABASES of variOUS kinds, SUCh as Active Directory,
SQL Server 2000, Exchange Server 2000, and Message Queuing. My intention with
this book is to give you insight into how ADO.NET works and how you can use
the classes from ADO.NET to access a database; use stored procedures, views,
and triggers; get information from Active Directory and Exchange Server; and use
Message Queuing in your applications. Having said that, my goal was to make the
book as easy to read as possible, and although there are passages that aren't quite
as easy to read as I'd like them to be, I think I've managed to accomplish what
I set out to do.
xvii
Introduction
Part Two is the juicy part, where you take a look at how to connect to rela-
tional and hierarchical databases. You will also learn how to wrap your
database access in classes and how to master exception handling. Part Two
starts with a look at how to design a relational database, and you gradually
learn the building blocks for the User Man example application.
Appendix A covers how to use the SQLXML plug-in for manipulating SQL
Server 2000 data using XML from managed code or using HTTP.
Technology Requirements
From the example code you can connect to SQL Server using any of these three
.NET Data Providers: SQL Server .NET Data Provider, OLE DB .NET Data
Provider, or ODBC .NET Data Provider. The example code also includes how to
connect to and manipulate data in MySQL 3.23.45 or later, Oracle 8i or later,
Microsoft Access 2000 or later, and SQL Server. For connecting to SQL Server
2000, you can find coverage of the SQLXML plug-in for manipulating SQL
Server data using XML from managed code or using HTTP. Exchange Server 2000
connection and data manipulation is also covered.
Because I'm using some ofthe Enterprise functionality ofVisual Studio .NET,
you'll need either of the two Enterprise editions to follow all the exercises. How-
ever, the Professional edition will do for most of the example code, and it will
certainly do if you just want to see how everything is done while you learn
ADO.NET. This means that the only thing extra you get from the Enterprise
editions in terms of database access is an extra set of database tools to be used
from within the IDE.
xviii
Introduction
Example Code
All the example code for this book can be found on the Apress Web site
(http: I lwww. a press. com) in the Downloads section, or on the UserMan Web site
(http: I lwww. userman. dk).
Data Source
The data source for the example code in this book is running on SQL Server 2000.
However, the example code also includes how to connect to and manipulate data
in MySQL 3.23.45 or later, Oracle 8i or later, Microsoft Access 2000 or later, and
SQL Server.
Feedback
I can be reached at carstent@dotnetservices. biz and I'll gladly answer any
e-mail concerning this book. Now, I don't need any unnecessary grief, but I'll try
to respond to any queries you might have regarding this book.
I have set up a Web site for the UserMan example application, where you can
post and retrieve ideas on how to take it further. The Web site address is
http: I lwww. userman. dk. Please check it out.
xix
Part One
Getting Started
CHAPTER 1
ALightning-Quick
Introduction to C#
THE .NET FRAMEWORK IS AN ENVIRONMENT for building, deploying, and running
services and other applications. This environment is all about code reuse and
specialization, multilanguage development, deployment, administration,
and security. The .NET Framework will lead to a new generation of software that
melds computing and communication in a way that allows the developer to
create truly distributed applications that integrate and collaborate with other
complementary services. In other words, you now have the opportunity to create
Web services, such as search engines and mortgage calculators, that will help
transform the Internet as we know it today. No longer will it be about individual
Web sites or connected devices; it's now a question of computers and devices,
such as handheld computers, wristwatches, and mobile phones, collaborating
with each other and thus creating rich services. As an example, imagine calling
a search engine to run a search and then displaying and manipulating the results
of the search in your own application.
There are rumors that the .NET Framework is solely for building Web sites,
but this is not true. You can just as easily create your good old-fashioned
Windows applications with the .NET Framework. The .NET Framework is actually
more or less what would have been called COM+ 2.0 if Microsoft had not
changed its naming conventions. Granted, the .NET Framework is now a far cry
from COM+, but initially the development did start from the basis of COM+.
I guess not naming it COM+ 2.0 was the right move after all.
This book is based on the assumption that you already know about the .NET
Framework. However, this chapter provides a quick run-through of .NET con-
cepts and terms. Although the terms are not specific to C#, but rather are relevant
to all .NET programming languages, you'll need to know them if you're serious
about using C# for all your enterprise programming.
3
Part One: Getting Started
• Assemblies
• Namespaces
• Managed components
4
Chapter 1: A Lightning-Quick Introduction to C#
• Web Forms allow you to build Web pages using a forms-based UI. These
forms are quite similar to the forms used in previous versions ofVisual
Basic. This also means that you have proper event and exception handling,
unlike in ASP, where event and especially exception handling is a difficult
task to manage.
• XML Web services are a clever way of exposing and accessing functionality
on remote servers. XML Web services are based on the Simple Object
Access Protocol (SOAP), which is a firewall- friendly protocol based on
XML. SOAP uses the HTTP protocol to work across the Internet. XML Web
services can also be invoked using the HTTP GET method simply by
browsing to the Web service and the HTTP POST method.
5
Discovering Diverse Content Through
Random Scribd Documents
The centre of these forces is not as might be supposed at the
centre of the plane, but at a point between the centre and the front
edge called the "centre of pressure." The centre of pressure
approaches the front edge as the angle of the plane with the
horizontal becomes less.
In order to render a better idea of how it is possible for an
aeroplane to gain support in the air consider a skater moving swiftly
over very thin ice which would not bear his weight, but since he is
moving so rapidly that any one portion of the ice does not have time
to bend to the breaking point, he is supported. In somewhat the
same manner, the planes pass so rapidly on to new and undisturbed
bodies of air, and stay over one body for so brief an instant that
there is no time to completely overcome the inertia of the air and
force it downwards.
FIG. 12. The action of the air upon a curved and a flat plane. We
have seen that by the effects of the resistance of the air, an
aeroplane may be sustained in the atmosphere. We must now see in
what manner we can use these effects to the greatest advantage.
First of all, we have been continually speaking of a "plane" as
the supporting surface, which from the definition of the word would
lead one to believe that they were flat. If the wings of a bird are
examined, it will soon be noticed that they are concave underneath.
Since the first attempts at aviation, therefore, machines have been
built with planes or wings concave on the underside. The reason for
this is very apparent from Fig. 12. The first illustration shows the
action of a flat surface moving through the air. The air streams, as
represented by the lines do not follow the surface of the plane, but
leave a considerable region of dead air. This is the reason that a flat
plane is very inefficient and not capable of giving so great a lift as
the curved plane in the next figure where the lines follow the outline
of the plane. The less disturbance a plane causes in the surrounding
air, the closer it is said to approach to "stream line form." A correctly
curved plane is considerably more effectual than a flat one, giving at
the same time greater "lift" and less "drift."
Built-up Planes, that is, planes having a double curve
approaching true stream line form, come nearer being the ideal
plane than any other from some standpoints, but do not possess any
advantages when used on models of less than four feet spread.
FIG. 13. Section of a built-up plane showing how a rib is made.
When made small, they offer greater "drift" or head resistance than
a single curved surface plane and cannot because of the delicate
structure necessary to make them light, withstand hard knocks.
They have the further disadvantage of being from a constructional
standpoint very hard to make smooth and rigid.
With a little care, strips several feet long may be easily split
from bamboo rods. The best method of accomplishing this is to use
a fine saw, but a sharp knife will often be successful.
FIG. 14. How ribs may be joined to the long members.
The fin should be placed well toward the rear of the machine
and, whenever possible, stretched both above and below the centre
line of the machine, so that the pressure due to cross winds will be
equal both above and below and there will be no tendency for the
machine to twist about its longitudinal axis.
When it is not possible to place the fin both above and below
the centre line it should be placed above rather than below.
Fins may be made out of thin wood, sheet aluminum or fabric
stretched over a wire or rattan framework.
CHAPTER IV. THE FUSELLAGE OR
FRAMEWORK.
FIG. 24.
By far the simplest and most efficient form of power which could be
installed in a model aeroplane to drive the propeller is a twisted
skein of rubber. Nothing is lighter, or more easily handled and
repaired.
The word elastic, in physics, is the name given to the tendency
which a body exerts, when distorted, to return to its original shape.
Rubber possesses more elasticity than any other material known, it
being possible to stretch a piece of rubber cord to eight or nine
times its original length without fracture. Rubber also possesses the
added requisite of lightness and will store up more energy than any
form of steel spring.
The Simplest Form of Motor is a single skein of elastic
stretched between two hooks, one fixed and the other to which the
propeller is attached, free to rotate. In some cases it is a decided
advantage to divide the motor into one or more parts. One phase of
this question has already been considered. The others will be
discussed in the following chapter.
The type of Elastic which gives at once the longest life and
the greatest power is the square rubber, preferably about 3/32 x
3/32 inches, and not the flat strip. When examined under the
microscope the edges of the square rubber show to be cleaner and
sharper and not so ragged as those of the flat strips. To be of any
value for use in a model aeroplane, the rubber should be absolutely
pure and fresh.
There are certain precautions which if observed will add greatly
to the power and efficiency of a rubber band motor.
Always remove the elastic from the machine when the flights
are over for the time being. Rubber spoils very quickly when kept
under tension. It also deteriorates if warm, so keep in a cool place.
Strong sunlight causes rubber to harden and lose its elasticity, due
to the presence of the sulphur used in vulcanizing. If talcum powder
or finely powdered soapstone is rubbed on the bands from time to
time it will prevent them from sticking together. The strands will then
run and slip more easily upon each other, making it possible to store
up a greater number of propeller revolutions.
In spite of the use of talcum powder, however, when a skein of
rubber is twisted very tightly, the strands stick together, causing it to
soon break up.
This nuisance may be somewhat alleviated if the strands are
lubricated with pure redistilled glycerine free from grease, etc. Such
a precaution will not always greatly lengthen the life of the rubber,
but will increase the number of turns which it is possible to give the
skein (and this is a very important advantage in model contests).
Due to its sticky nature, however, the glycerine will cause the rubber
to gather dust and particles of dirt which, if allowed to grind into the
rubber, would soon weaken it. The skein should therefore be washed
from time to time in warm soda and water and fresh glycerine
applied. By all means, avoid all oils or substances of a greasy nature,
such as lubricants. They quickly soften and rot the rubber.
The Amount of Elastic required for a model will vary
considerably for propellers of the same pitch and diameter. There is
always a tendency to use too much rather than too little and this
fault should be carefully guarded against. In nine cases out of ten it
is the cause of the unsatisfactory behavior of a model.
The motor should always be "stranded," that is, made up of a
skein of bands. It is then possible to secure a larger number of turns
than if a single strip were used.
Always start a new machine with a small number of strands and
gradually add to the number until the proper amount of power is
obtained. The distance between the propeller and the fixed hook
should always be as great as possible so as to secure the maximum
number of turns.
Doubling the Number of Elastic Strands increases the
power of the motor but cuts down the number of turns which it is
possible to give the propeller. That is to say, a certain skein
composed of six strands of rubber will take perhaps two hundred
and twenty-five turns while a twelve strand skein of he same sized
rubber strands strands is only capable of less than half or about one
hundred turns before it is wound tight.
Doubling the number of strands and at the same time keeping
them the same length increases the torque more than three times
but diminishes the number of turns from one-half to one-third.
Doubling the length of the strands does not materially reduce
the torque for the first hundred turns. After two hundred turns have
been reached, the torque is only about one-half as great as it would
be in case the length were not doubled.
Doubling the length of the strands doubles the number of turns
it is possible to give the skein. It is easy to see from this why it is
always advisable to make the motor as long as possible and to
compose it of the fewest number of strands if long flights are
desirable.
By using several separate skeins geared together so as to apply
their energy to one screw, it is possible to obtain a greatly increased
number of turns. The weight of the gearing is very small and hardly
a factor, considering the advantages derived therefrom. Since the
skeins revolve in opposite directions the frame of the machine is
relieved of the harmful twisting effect so often present in a single
skein.
The gears should be of steel accurately cut and of no larger
diameter than is necessary to separate the rubber skeins the
requisite distances so that they will not rub.
Holes may be bored in the gears to lighten them. The gears are
easily and conveniently cut out of steel pinion wire.
CHAPTER VI. SCREW PROPELLERS.
FIG. 27. A propeller of the truly helical type delivers a cylinder of air
in which all parts move at the same speed as at A. A propeller
having blades of the same angle throughout their length throws the
air as in B in which the centre of the cylinder moves more slowly
than the outside.
FIG. 28. Templets for testing and carving a propeller.
Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.
ebookfinal.com