
164
|
Chapter 7: Data Access and Data Binding
This is the Title of the Book, eMatter Edition
Copyright © 2008 O’Reilly & Associates, Inc. All rights reserved.
Also note that in C#, when referring by index to items such as the tables in the
DataSet object or the items in a DataRow object, you must use square brackets
(rather than the parentheses you would use in Visual Basic .NET). This is consis-
tently one of the biggest gotchas in moving from VB.NET to C# and vice-versa.
One final difference in the looping code between Examples 7-1 and 7-2 is that
since the VB.NET Format function is not available for formatting the price data,
we use the static Format method exposed by the
String class instead; it formats
the data as currency and includes the appropriate regional currency symbol for
the current system.
Another important point to observe about the code in Example 7-2
is that because we’re not keeping a database connection open while
looping through the data, we can take as much time as we’d like in
displaying the data without affecting the ability of others to obtain
connections to the database. We can also use the ASP.NET cache
engine to cache the entire dataset for later use, if desired, so that we
don’t have to retrieve the data again. For data that is updated infre-
quently, this can result in a significant performance improvement,
since it is far faster to retrieve a dataset from memory than