Win a copy of Beginning ASP.NET 1.1. Databases

In some of the entries to our last competition a number of people asked us about various aspects of ASP.NET. There were even those <gasp> who suggested they used Visual Studio alongside Dreamweaver.

In immediate response, and in conjunction with Apress, we're giving you the chance to read a sample chapter from the forthcoming Beginning ASP.NET 1.1 Databases book by experienced .NET authors Dan Maharry and Damien Foggon.

Of course we've twisted the publisher's arms on your behalf, and have five books to give away to registered DMXzone members. All we want from you is to know either which bits of ASP.NET you've found most useful, or which you've found hardest to get to grips with. Lucky entries will be extracted by a draw from the inbox on the 22nd July!

If you want to pre-order a copy from Amazon >>

For convenience we've got a snippet of the chapter below (the full sample chapter PDF download is available above).

Extract from Beginning ASP.NET 1.1. Databases, Damien Foggon and Daniel Maharry, apress, ISBN 1-59059-369-3, 2004, by kind permission of Apress.

CHAPTER 6

DataReader and DataSet

IN CHAPTERS 4 AND 5, you saw in detail how you build and pass commands to a database, and you discovered the three types of result from a SQL statement: a confirmation, a scalar value, and a DataReader object. You also saw how to deal with scalars and confirmations.

In this chapter, you'll continue your look at the third step in driving a page with data: handling the data correctly once it has been returned from the database. You have a large number of options for this, but they all boil down to whether you're going to work with the data directly from the database or save it on the server as disconnected data. You'll look at both options in this chapter, and you'll use the following techniques, which are all quite commonplace:

  • Using the DataReader to work with the results of a query directly from the database
  • Saving query results into a DataSet object on the server away from the database
  • Creating a DataSet locally with your own data completely away from an external data source

Along the way, you'll look in some detail at both the DataReader and DataSet objects, their makeup, and their differences. At least one of these two objects will feature in every data-driven Web page you create, so it's good to be up to speed on how they work.

This chapter is only the first part of three in your journey through data handling. For now, we'll assume for the moment that the data you request doesn't need to be displayed on-screen. In Chapter 7, we'll assume that the data will be displayed on-screen but is read-only and won't need to be updated. Finally, in Chapter 8, you'll continue with building pages that allow you to create, modify, and delete data and reflect those changes back to the data source.

"Why not just look at DataReaders and DataSets as you go along?" we hear you cry. "Why put this interlude first?" These are good questions, but they have a simple answer, which we'll quite happily borrow from the world of Perl. For every data-related task you'll be looking at over the coming chapters, you can follow this motto: "There's More Than One Way To Do It."

But they all stem from how DataReaders and DataSets work. If you don't look at these objects now and see the situations in which they're useful, you'll be less likely to choose the right option when building data-driven pages of your own.

Ian Blackham

Ian BlackhamFollowing a degree in Chemistry and a doctorate in Scanning Tunneling Microscopy, Ian spent several years wrestling with acronyms in industrial R&D (SEM with a side order of EDS, AFM and TEM augmented with a topping of XPS and SIMS and yet more SEM and TEM).

Feeling that he needed a career with more terminology but less high voltages, Ian became a technical/commissioning editor with Wrox Press working on books as diverse as Beg VB Application Development and Professional Java Security. After Wrox's dissolution and a few short term assignments Ian became content manager at DMXzone.

Ian is a refugee from the industrial Black Country having slipped across the border to live in Birmingham. In his spare time he helps out with the website of a local history society, tries to makes sure he does what his wife Kate says, and worries that the little 'un Noah is already more grown up than he is.

See All Postings From Ian Blackham >>