One of the most important requirements for any web site is to accurately and safely transmit and store information. This information could be in any form, from the credit card details stored by a credit company, to the results of a straw poll on a marketing site. Whatever you use ASP.NET web pages for, you'll find that sooner or later you're going to need to access, read from, write to, and generally master operations involving a database.
Luckily for us, working with databases from a web application is much simpler than it used to be. The .NET Framework has revolutionized the way in which we can develop sophisticated web sites. ASP.NET has made enormous improvements to the ways in which we can develop complex and interactive web sites, and ADO.NET - which provides powerful and flexible data processing functionality - has radically changed the ways that we can retrieve, process, and store data from within a web application.
In this book, we're going to explain how to can create data-enabled ASP.NET applications. Written with hands-on learning in mind, it is packed with code examples that demonstrate important fundamental principles. Requiring some basic knowledge of ASP.NET and Visual Basic .NET, but assuming no prior experience of working with databases, the authors will guide you through the processes involved in connecting ASP.NET pages to a database, and investigate the various ways of reading, processing, and updating data. They'll then explore all the major issues involved in data-heavy ASP.NET programming, including some more advanced topics such as using stored procedures and components. The book concludes with a case study that puts everything in the preceding chapters into context.
What Does This Book Cover?
Chapter 1 begins by looking at the general notion of creating data-driven web sites. More specifically,we talk about the relationship between web sites and data, introducing ADO.NET in the process. Later in the chapter, we look at setting up our development environment for the rest of the book, an d discuss some of the stumbling blocks that you may encounter.
It seems like a strange question, but what exactly is a database? In Chapter 2 we examine different types of databases, how they are designed, and how we can use them to store and retrieve information. W e then move on to present an overview of the SQL language, and draw a quick comparison between Microsoft's database solutions.
Having taken our first look at databases, we need to learn how to connect to them from our ASP.NET code. Chapter 3 begins by building on the overview of ADO.NET that was presented in Chapter 1, clarifying the important terms that you need to know. We then move on to create and test a connection to the sample Northwind database that we'll be using throughout the book. This chapter contains numerous examples that demonstrate how to connect to diverse data sources such as Access, SQL Server, Excel, and XML, enabling us to be confident in whatever environment we have to develop in.
Packed with examples, Chapter 4 looks at reading and displaying data using data reader objects. We start with a discussion of the theory of handling data in ASP.NET and ADO.NET that introduces command objects. After that, we go on to look at how we can use data readers to obtain data, and then bind that data to different controls like radio buttons, check boxes, and most importantly, the DataGrid.
Chapter 5 talks about an important ADO.NET object called DataSet, which is used to store and retrieve data of any complexity on the server. Once the initial theory is dealt with, we use plenty of examples to demonstrate different ways to use a dataset.
Of course, we don't always just read other people's data, so Chapter 6 explains how to create our own records in existing databases. Topics covered in this chapter include ASP.NET's validation controls, and using command and DataSet objects to perform record insertions.
Following on from the previous chapter, Chapter 7 demonstrates how to modify and delete records. We look at how to edit data using the DataGrid and DataView controls, and at how to update and delete records from a dataset object
Next in line is Chapter 8, which looks at stored procedures. In it, we explain what they are, what they can be used for, and some of their advantages and disadvantages. After demonstrating how to create stored procedures with Visual Basic .NET, this chapter shows how to invoke them from your ASP.NET code, and how to supply them with parameters to perform certain tasks.
Chapter 9 is a mine of information regarding some of the more advanced topics that can crop up when you're creating commercial-quality data-driven ASP. NET applications. The four subjects that we introduce and explain here are error handling, code structure, scalability and concurrency, and security.
Approaching the end of the book, Chapter 10 introduces components, explaining why they can be valuable before discussing how to create them. The code samples in this chapter center around the creation of a class library that includes numerous methods for accessing a database.
Since one of the goals of any programmer should be to write the best code possible, Chapter 11 is devoted to performance issues. We look at connection pooling and performance counters, and produce some metrics on the relative performance of dataset and data reader objects in different situations. We also highlight the importance of porting old ADO code to new ADO.NET as soon as you can.
We finish with a case study in Chapter 12. This builds on all the subjects that l~_ve been presented in the book, and presents a complete, real-world application that uses multiple A~PX pages, ASP.NET web server controls, VB.NET components, and stored procedures.
Who Is This Book For?
This book is for people who:
Have some experience of Visual Basic .NET and ASP.NET
Have some familiarity with the .NET Framework and related technologies
Want to learn how to use ASP.NET to create data-enabled web applications
However, you need to know nothing about databases in order to understand this book - although, of course, a little prior knowledge never goes amiss.
What You Need to Use This BookTo run the examples in this book, you need to have a PC running the following:
Microsoft Windows NT, Windows 2000, or Windows XP
The .NET Framework
A version of Visual Studio .NET that includes, as a minimum, the Standard Edition of Visual Basic .NET
In addition, some of the examples use Microsoft Access and Microsoft SQL Server, but there is no requirement for you to own either. All of the important examples use the MSDE as their database engine, and this ships with all versions of Microsoft Visual Studio .NET.
Conventions
We've used a number of different styles of text and layout in this book to help differentiate between different kinds of information. Here are examples of the styles we use, and an explanation of what they mean. Code has several styles. If it's a word that we're talking about in the text - for example, when discussing a For...Next loop - it's in this font. If it's a block of code that can be typed as a program and run, then it's also in a gray box:
Sometimes, you'll see code in a mixture of styles, like this:
Widget
S10. O0
< / invoice>
In these cases, the code with a white background represents either something that we're already familiar with, or something that's not important in the current discussion. The line highlighted in gray is either a new addition to the code since we last looked at it, or the focus of the current discussion.
Advice, hints, and background information come in this style.
Important pieces of information come in boxes like this.
Bullets appear indented, with each new bullet marked as follows:
Important Words are in a bold font
Words that appear on the screen, or in menus like Open or Close, are in a similar font to the one you would see on a Windows desktop
Keys that you press on the keyboard, like Ctrl and Enter, are in italics
Customer Support
We always value hearing from our readers, and we want to know what you think about this book: what you liked, what you didn't like, and what you think we can do better next time. You can send us your comments either by returning the reply card in the back of the book, or by e-mail to feedback@wrox.com. Please be sure to mention the book's title in your message.
How to Download the Sample Code for the Book
When you visit the Wrox web site at www.wrox.com, simply locate this book through our Search facility or by using one of the title lists. Click on Download in the Code column, or on Download Code on the book's detail page.
The files that are available for download from our site have been archived using WinZip. When you've saved the attachments to a folder on your hard drive, you need to extract the files using a decompression program such as WinZip or PKUnzip. When you extract the files, the code will be extracted into chapter folders. When you start the extraction process, ensure that your softwar e is set up to use folder names.
Errata
We've made every effort to make sure that there are no errors in this book. However, no one is perfect, and mistakes do occur. If you find an error, like a spelling mistake or a faulty piece of code, we would be very grateful for feedback. By sending in errata, you may save another reader hours of frustration, and you will be helping us to provide even higher quality information. Simply e-mail the information to support@wrox.eom; your information will be checked and (if correct) posted to the errata page for that title and used in any subsequent editions of the book.
To find existing errata messages on the web site, click on the Book Errata link, which is below the cover graphic on the book's detail page.
E-mail Support
If you wish to query a problem in the book with an expert who knows the book in detail, e-mail support@wrox.com with the title of the book and the last four numbers of the ISBN in the subject field of the e-mail. A typical e-mail should include the following things:
The title of the book, the last four digits of the ISBN (6195), and the page number of the
problem in the Subject field
Your name, contact information, and the problem in the body of the message
We won't send you junk mail. We need the details to save your time and ours. When you send an e-mai message, it will go through the following chain of support:
Customer Support - Your message is delivered to our customer support staff, who are the first people to read it. They have files on most frequently asked questions, and will answer general queries about the book or the web site immediately.
Editorial - Deeper queries are forwarded to the technical editor responsible for that book. They have experience with the programming language or particular product, and are able to answer detailed technical questions on the subject.
The Authors - Finally, in the unlikely event that the editor cannot answer your problem, they will forward the question to the author. We do try to protect our authors from distractions, but we're quite happy to forward specific requests to them. All Wrox authors help with the support on their books; they will e-mail the customer and the editor with their response, and again all readers should benefit.
The Wrox support process can only offer support to issues that are directly pertinent to the content of our published title. Support for questions that fall outside the scope of normal book support is provided via the community lists of our http://p2p.wrox.eom forum.
p2p.wrox.com
For author and peer discussion, join the P2P mailing lists. Our unique system provides programmer to programmerTM contact on mailing lists, forums, and newsgroups, all in addition to our one-to-one e-mail support system. If you post a query to P2P, you can be confident that the many Wrox authors and other industry experts who are present on our mailing lists are examining it. At p2p.wrox.com, you will find a number of different lists that will help you not only while you read this book, but also as you develop your own applications. Particularly appropriate to this book are the aspx_beginners and the vb_dotnet lists.
To subscribe to a mailing list, follow these steps:
1. Go to http://p2p.wrox.com.
2. Choose the appropriate category from the left menu bar.
3. Click on the mailing list you wish to join.
4. Follow the instructions to subscribe, and fill in your e-mail address and password.
5. Reply to the confirmation e-mail you receive.
O. Use the subscription manager to join more lists and set your e-mail preferences.
Why This System Offers the Best Support
You can choose to join the mailing lists, or you can receive them as a weekly digest. If you don't have the time or facility to receive the mailing list, then you can search our online archives. Junk and spam mails are deleted, and your own e-mail address is protected by the Lyris system. Queries about joining or leaving lists, and any other general queries about lists, should be sent to listsupport@p2p.wrox.com.