All rights reserved. No part of the contents of this book may be reproduced or transmitted in any form or by any means without the written permission of the publisher.
Library of Congress Control Number: 2011927329
ISBN: 978-0-7356-2739-0
Printed and bound in the United States of America.
Microsoft Press books are available through booksellers and distributors worldwide. If you need support related to this book, email Microsoft Press Book Support at mspinput@microsoft.com. Please tell us what you think of this book at http://www.microsoft.com/learning/booksurvey.
Microsoft and the trademarks listed at http://www.microsoft.com/about/legal/en/us/IntellectualProperty /Trademarks/EN-US.aspx are trademarks of the Microsoft group of companies. All other marks are property of their respective owners.
The example companies, organizations, products, domain names, email addresses, logos, people, places, and events depicted herein are fictitious. No association with any real company, organization, product, domain name, email address, logo, person, place, or event is intended or should be inferred.
This book expresses the author’s views and opinions. The information contained in this book is provided without any express, statutory, or implied warranties. Neither the authors, Microsoft Corporation, nor its resellers, or distributors will be held liable for any damages caused or alleged to be caused either directly or indirectly by this book.
Acquisitions Editor: Martin Del Re
Developmental Editor: Karen Szall
Project Editor: Valerie Woolley
Editorial Production: nSight, Inc.
Technical Reviewer: Christophe Nasarre; Technical Review services provided by Content Master, a member of CM Group, Ltd.
Copyeditor: Kerin Forsyth
Indexer: Luci Haskins
Cover: Twist Creative • Seattle
Exam 70-516: TS: Accessing Data with Microsoft .NET Framework 4
MODELING DATA (20%)
Map entities and relationships by using the Entity Data Model.
Map entities and relationships by using LINQ to SQL.
Create and customize entity objects.
Connect a POCO model to the entity Framework.
Create the database from the Entity Framework model.
Create model-defined functions.
MANAGING CONNECTIONS AND CONTEXT (18%)
Configure connection strings and providers.
4
6
6
6
6
1
1
1
1
1
1 Create and manage a data connection.
a connection.
2
2
1
1 Manage the DataContext and ObjectContext.
4
6
1
1 Implement eager loading.
4
3 Configure ADO.NET Data Services.
(22%)
Create an Entity SQL (ESQL) query.
Handle special data types.
MANIPULATING DATA (22%)
Create, update, or delete data by using SQL statements.
Create, update, or delete data by using DataContext.
Create, update, or delete data by using ObjectContext.
2
6
2 Manage transactions.
2
6
Create disconnected objects.
1
DEVELOPING AND DEPLOYING RELIABLE APPLICATIONS (18%)
Monitor and collect performance data.
Handle exceptions.
Protect data.
Synchronize data.
Deploy ADO.NET components.
Chapter 8 Lesson 1
Chapter 8 Lesson 2
Chapter 8 Lesson 3
Chapter 2
Chapter 8 Lesson 3 Lesson 4
Chapter 9 Lesson 1
Exam Objectives The exam objectives listed here are current as of this book’s publication date. Exam objectives are subject to change at any time without prior notice and at Microsoft’s sole discretion. Please visit the Microsoft Learning Web site for the most current listing of exam objectives: http://www.microsoft.com/learning/en/us/Exam .aspx?ID=70-516
Contents at a Glance
What do you think of this book? We want to hear from you!
Microsoft is interested in hearing your feedback so we can continually improve our books and learning resources for you. To participate in a brief online survey, please visit:
www.microsoft.com/learning/booksurvey/
Introduction
This training kit is designed for developers who write or support applications that access data written in C# or Visual Basic using Visual Studio 2010 and the Microsoft .NET Framework 4.0 and who also plan to take the Microsoft Certified Technology Specialist (MCTS) exam 70-516. Before you begin using this kit, you must have a solid foundation-level understanding of Microsoft C# or Microsoft Visual Basic and be familiar with Visual Studio 2010.
The material covered in this training kit and on exam 70-516 relates to the data access technologies in ADO.NET 4.0 with Visual Studio 2010. The topics in this training kit cover what you need to know for the exam as described on the Skills Measured tab for the exam, which is available at http://www.microsoft.com/learning/en/us/exam.aspx?ID=70-516&locale=en -us#tab2.
By using this training kit, you will learn how to do the following:
■ Work with the ADO.NET disconnected classes
■ Work with the ADO.NET connection classes
■ Write and execute LINQ queries
■ Implement LINQ to SQL classes
■ Implement LINQ to XML in your applications
■ Implement the ADO.NET Entity Framework in your applications
■ Create and Implement WCF Data Service applications
■ Monitor and Collect ADO.NET performance data
■ Synchronize offline data
■ Deploy Data Access applications
Refer to the objective mapping page in the front of this book to see where in the book each exam objective is covered.
System Requirements
The following are the minimum system requirements your computer needs to meet to complete the practice exercises in this book and to run the companion CD. To minimize the time and expense of configuring a physical computer for this training kit, it’s recommended, but not required, that you use a virtualized environment, which will allow you to work in a sandboxed environment. This will let you make changes without worrying about
your day-to-day environment. Virtualization software is available from Microsoft (Virtual PC, Virtual Server, and Hyper-V) and other suppliers such as VMware (VMware Workstation) and Oracle (VirtualBox).
Hardware Requirements
Your computer should meet the following minimum hardware requirements:
■ 2.0 GB of RAM (more is recommended)
■ 80 GB of available hard disk space
■ DVD-ROM drive
■ Internet connectivity
Software Requirements
The following software is required to complete the practice exercises:
■ Windows 7. You can download an Evaluation Edition of Windows 7 at the Microsoft Download Center at http://technet.microsoft.com/en-us/evalcenter/cc442495
■ SQL Server 2008 Developer Edition is recommended because some labs and sample code use this edition for permanently mounted databases. An Evaluation Edition is available from http://msdn.microsoft.com/en-us/evalcenter/bb851668.aspx.
■ SQL Server 2008 Express Edition is recommended because some labs and sample code use this edition for User Instance mounted databases. A full release is available from http://www.microsoft.com/express/Database.
NOTE SQL SERVER INSTALLATION
If you are using a 64 -bit OS, you should install 64 -bit SQL Server before installing Visual Studio 2010. Visual Studio 2010 includes, and attempts to install, the 32-bit SQL Server 2008 Express Edition.
If you install the 64-bit versions of SQL Server first, the Visual Studio 2010 installer will see that SQL Server Express Edition is already installed and will skip over installing the 32-bit SQL Server 2008 Express Edition.
■ Visual Studio 2010. You can download an evaluation edition from http://msdn.microsoft .com/en-us/evalcenter/default. Although the labs and code samples were generated using Visual Studio 2010 Premium Edition, you can use the Express Edition of Visual Studio for many of the labs, which is available from http://www.microsoft.com/express.
Code Samples
The code samples are provided in Visual C# and Visual Basic. You will find a folder for each chapter that contains CS (C#) and VB (Visual Basic) code. In these folders, you will find the sample code solution and a folder for each lesson that contains the practice code. The Practice Code folder contains Begin and Completed folders, so you can choose to start at the beginning and work through the practice or you can run the completed solution.
Using the CD
A companion CD is included with this training kit. The companion CD contains the following:
■ Practice tests You can reinforce your understanding of the topics covered in this training kit by using electronic practice tests that you customize to meet your needs. You can run a practice test that is generated from the pool of Lesson Review questions in this book. Alternatively, you can practice for the 70-516 certification exam by using tests created from a pool of over 200 realistic exam questions, which give you many practice exams to ensure that you are prepared.
■ Code Samples All of the Visual Basic and C# code you see in the book you will also find on the CD.
■ An eBook An electronic version (eBook) of this book is included for when you do not want to carry the printed book with you.
Companion Content for Digital Book Readers: If you bought a digital edition of this book, you can enjoy select content from the print edition’s companion CD Visit http://go.microsof t.com/f wlink/?Linkid=216910 to get your downloadable content. This content is always up-to-date and available to all readers.
How to Install the Practice Tests
To install the practice test software from the companion CD to your hard disk, perform the following steps:
1. Insert the companion CD into your CD drive and accept the license agreement. A CD menu appears.
NOTE IF THE CD MENU DOES NOT APPEAR
If the CD menu or the license agreement does not appear, AutoRun might be disabled on your computer. Refer to the Readme.txt file on the CD for alternate installation instructions.
2. Click Practice Tests and follow the instructions on the screen.
How to Use the Practice Tests
To start the practice test software, follow these steps:
1. Click Start, All Programs, and then select Microsoft Press Training Kit Exam Prep.
A window appears that shows all the Microsoft Press training kit exam prep suites installed on your computer.
2. Double-click the lesson review or practice test you want to use.
NOTE LESSON REVIEWS VS. PRACTICE TESTS
Select the (70-516): Accessing Data with Microsoft .NET Framework 4 lesson review to use the questions from the “Lesson Review” sections of this book. Select the (70-516): Accessing Data with Microsoft .NET Framework 4 practice test to use a pool of questions similar to those that appear on the 70-516 certification exam.
Lesson Review Options
When you start a lesson review, the Custom Mode dialog box appears so that you can configure your test. You can click OK to accept the defaults, or you can customize the number of questions you want, how the practice test software works, which exam objectives you want the questions to relate to, and whether you want your lesson review to be timed. If you are retaking a test, you can select whether you want to see all the questions again or only the questions you missed or did not answer.
After you click OK, your lesson review starts. The following list explains the main options you have for taking the test:
■ To take the test, answer the questions and use the Next and Previous buttons to move from question to question.
■ After you answer an individual question, if you want to see which answers are correct—along with an explanation of each correct answer—click Explanation.
■ If you prefer to wait until the end of the test to see how you did, answer all the questions and then click Score Test. You will see a summary of the exam objectives you chose and the percentage of questions you got right overall and per objective. You can print a copy of your test, review your answers, or retake the test.
Practice Test Options
When you start a practice test, you choose whether to take the test in Certification Mode, Study Mode, or Custom Mode:
■ Certification Mode Closely resembles the experience of taking a certification exam. The test has a set number of questions. It is timed, and you cannot pause and restart the timer.
■ Study Mode Creates an untimed test during which you can review the correct answers and the explanations after you answer each question.
■ Custom Mode Gives you full control over the test options so that you can customize them as you like.
In all modes, the user interface when you are taking the test is basically the same but with different options enabled or disabled depending on the mode. The main options are discussed in the previous section, “Lesson Review Options.”
When you review your answer to an individual practice test question, a “References” section is provided that lists where in the training kit you can find the information that relates to that question and provides links to other sources of information. After you click Test Results to score your entire practice test, you can click the Learning Plan tab to see a list of references for every objective.
How to Uninstall the Practice Tests
To uninstall the practice test software for a training kit, use the Program And Features option in Windows Control Panel.
Acknowledgments
The author’s name appears on the cover of a book, but I am only one member of a much larger team. Thanks very much to Valerie Woolley, Christophe Nasarre, and Karen Szall for working with me, being patient with me, and making this a great book. Christophe Nasarre was my technical reviewer, and he was far more committed to the project than any reviewer I’ve worked with in the past. I certainly could not have completed this book without his help.
Each of these editors contributed significantly to this book and I hope to work with them all in the future.
And a special thanks to Kristy Saunders for writing all of the practice test questions for the practice test located on the CD.
Support & Feedback
The following sections provide information on errata, book support, feedback, and contact information.
Errata
We have made every effort to ensure the accuracy of this book and its companion content. If you do find an error, please report it on our Microsoft Press site at oreilly.com:
1. Go to http://microsoftpress.oreilly.com
2. In the Search box, enter the book’s ISBN or title.
3. Select your book from the search results.
4. On your book’s catalog page, under the cover image, you will see a list of links.
5. Click View/Submit Errata.
You will find additional information and services for your book on its catalog page. If you need additional support, please send an email message to Microsoft Press Book Support at mspinput@microsoft.com.
Please note that product support for Microsoft software is not offered through the addresses above.
We Want to Hear from You
At Microsoft Press, your satisfaction is our top priority, and your feedback our most valuable asset. Please tell us what you think of this book at: http://www.microsoft.com/learning/booksurvey
The survey is short, and we read every one of your comments and ideas. Thanks in advance for your input!
Stay in Touch
Let us keep the conversation going! We are on Twitter: http://twitter.com/MicrosoftPress.
Preparing for the Exam
Microsoft certification exams are a great way to build your resume and let the world know about your level of expertise. Certification exams validate your on-the-job experience and product knowledge. While there is no substitution for on-the-job experience, preparation through study and hands-on practice can help you prepare for the exam. We recommend that you round out your exam preparation plan by using a combination of available study materials and courses. For example, you might use the Training kit and another study guide for your “at home” preparation, and take a Microsoft Official Curriculum course for the classroom experience. Choose the combination that you think works best for you.
Note that this Training Kit is based on publicly available information about the exam and the author’s experience. To safeguard the integrity of the exam, authors do not have access to the live exam.
ADO.NET Disconnected Classes
Data access is an important factor in most applications, and ADO.NET provides the means of accessing data in your applications. This chapter describes the ADO.NET disconnected data classes; the next chapter describes the ADO.NET connected data classes.
This chapter is about foundation building. These classes have been in the Microsoft .NET Framework since its first release but are not obsolete. You should know the classes covered in this chapter to feel comfortable using many of the newer features covered in the chapters that follow.
Exam objectives in this chapter:
■ Create disconnected objects.
■ Cache data.
■ Handle special data types.
Lessons in this chapter:
■ Lesson 1: Working with the DataTable and DataSet Classes 3
■ Lesson 2: Serialization, Specialized Types, and Data Binding 34
important Have you read page xix?
It contains valuable information regarding the skills you need to pass the exam.
Before You Begin
To complete this book, you must have some understanding of Microsoft C# or Microsoft Visual Basic. This chapter requires the hardware and software listed at the beginning of this book.
REAL WORLD
Glenn Johnson
When trying to solve a problem, my first goal is to find the solution. The solution is not always elegant or pretty, but the goal is to find a solution, right? After that, the next step is to refactor your code and look for better performance. This book covers some aspects of ADO.NET performance, but a good book that delivers more in-depth information regarding ADO.NET performance tuning is Improving .NET Application Performance and Scalability, and you can download it for free. Chapter 12, “Improving ADO.NET Performance,” focuses on ADO.NET performance.
Many of the classes in the future chapters use the classes in this chapter. What do those higher-level classes offer that these classes don’t offer? They offer ease of programming for you, the developer. Generally, adding layers to provide ease of programming can reduce performance, but the amount of performance degradation will vary based on the code you write. If your code runs fast enough, it makes sense to take advantage of the ease-of-programming benefit.
Obtaining the best performance in scenarios in which maximum performance is more important than ease of programming might mean using the classes covered in this chapter.
Lesson 1: Working with the DataTable and DataSet Classes
The ADO.NET class hierarchy can be split into two categories: connected and disconnected objects. Figure 1-1 shows the principal connected and disconnected classes. This lesson describes the two primary disconnected classes, DataTable and DataSet, as shown in the diagram, and many other classes of this category as well. The disconnected classes are covered in detail because these classes can be used without ever creating a connection to a data store.
ADO.NET Classes
Disconnected Classes
Connected Classes
.NET Data Provider
DataAdapter
DataTableCollection
DataTable
DataRowCollection
DataColumnCollection
ConstraintCollection
DataRelationCollection
DataSet XML
SelectCommand
Inser tCommand
UpdateCommand
DeleteCommand
DataReader Command Connection
Data Store
The classes shown in Figure 1-1 are the primary ADO.NET classes and are important for successfully implementing an ADO.NET solution. With each new version of ADO.NET, changes have been made to these primary classes to improve functionality and performance.
The disconnected data access classes you instantiate in your applications are implemented in the System.Data.dll assembly from the .NET Framework. These classes are in the System. Data namespace. Because you must use the DataTable object when you’re using disconnected classes, this chapter begins by covering the DataTable object and the objects with which the DataTable object works closely. The DataSet object is covered in detail later on.
FIGURE 1-1 The common ADO.NET classes are shown here.
After this lesson, you will be able to:
■ Use a DataTable object to hold tabular rows of data.
■ Use a DataSet class to hold DataTable objects that are related.
■ Implement a DataView object to provide sorting and filtering of a data table.
Estimated lesson time: 45 minutes
The DataTable Class
A DataTable object represents tabular data as an in-memory, tabular cache of rows, columns, and constraints. You typically use the DataTable class to perform any disconnected data access. You start by creating an instance of the DataTable class, and then add DataColumn objects that define the type of data to be held and insert DataRow objects that contain the data. The following code, which creates a table for storing cars information, demonstrates the creation of a data table:
Sample of Visual Basic Code
'Create the DataTable named "Cars" Dim cars As New DataTable("Cars")
Sample of C# Code
//Create the DataTable named "Cars"
DataTable cars = new DataTable ("Cars");
NOTE ON THE COMPANION MEDIA USING THE SAMPLE CODE
The sample code is included in the accompanying media. Many of these are small samples that couldn’t run by themselves, so they have been joined to create a sample project that does run. Look for the projects that end with “SampleCode.” For example, these samples are in the DisconnectedClassesSampleCode project of the DisconnectedClassesSampleCodeSolution solution.
This code creates an empty data table for which the TableName property is set to Cars
You can use the TableName property to access this data table when it is in a DataTable collection (as detailed later in this chapter in the section titled “Using a DataSet Object to Coordinate Work between Data Tables”).
Adding DataColumn Objects to Create a Schema
The DataTable object is not useful until it has a schema, which is created by adding DataColumn objects and setting the constraints of each column. Constraints help maintain data integrity by limiting the data that can be placed in the column. The following code adds DataColumn objects to the cars DataTable object:
Dim make As New DataColumn("Make") 'default is String make.MaxLength = 35 'default is -1 make.AllowDBNull = False 'default is True cars.Columns.Add(make)
Dim year As New DataColumn("Year",GetType(Integer)) year.AllowDBNull = False cars.Columns.Add(year)
'Derived column using expression
Dim yearMake As New DataColumn("Year and Make") yearMake.MaxLength = 70 yearMake.Expression = "Year + ' ' + Make" cars.Columns.Add(yearMake)
The DataColumn object has several constructor overloads, so you can choose the overload that accepts the parameter values that fit best to your scenario. In this example, the constructor of each DataColumn object expects the column’s name. The DataType property
is set to String for all the DataColumn objects except the year, which is set to an Integer (int) that limits this column to be numeric data. The MaxLength property limits the length of the string data. Setting the Unique property to true creates an index to prevent duplication of entries. The AllowDBNull property is set to false to ensure that the column is populated with data. If AllowDBNull is set to true, you are not obligated to populate the column with data, and the column’s default value is DBNull, which is stored to the database as a null value. The Caption property isn’t really a constraint; it’s a string that holds the column heading when this DataTable object is used with graphic data grid controls. The yearMake DataColumn object demonstrates the creation of a calculated column. In this particular case, the string expression defines a formula to concatenate the value of the Year column with a space and the value of the Make column to shape what this column contains. Adding a calculated column is especially beneficial when data is available but not in the correct format.
Some of the DataColumn objects were created without specifying values for all the properties. The default values for the common properties are shown in Table 1-1.
TABLE 1-1 DataColumn Defaults
DATACOLUMN
DataType
MaxLength
Unique
AllowDBNull
PROPERTY
DEFAULT VALUE
Default is the string type.
Default is –1, which means that no check for maximum length is performed.
Default is false, which allows the existence of duplicate values.
Default is true, which means the data column does not need to have a value. If no value is provided, its value will be DBNull
Caption
Default is the ColumnName property value passed in the constructor.
Creating Primary Key Columns
The primary key of a DataTable object consists of a column or columns that make up a unique identity for each data row. In the previous example, the vehicle identification number (VIN) is considered as a unique key from which data for a given car can be retrieved. In other situations, getting a unique key might require combining two or more fields. For example, a sales order might contain sales order details that comprise the items being purchased on the sales order. The primary key for each of the sales order detail rows might be the combination of the order number and the line number. The PrimaryKey property must be set to an array of DataColumn objects to accommodate composite (multiple) keys. The following code shows how to set the PrimaryKey property for the cars DataTable object:
Sample of Visual Basic Code
'Set the Primary Key cars.PrimaryKey = new DataColumn(){vin}
Sample of C# Code
//Set the Primary Key cars.PrimaryKey = new DataColumn[] {vin};
Using Automatic Numbering for the Primary Key Column
You can also designate a column in your table as an auto-increment column. This column will be automatically populated with a number that will be the primary key. To set up an auto-increment column, set the AutoIncrement property of your data column to true After that, you set AutoIncrementSeed to the value of the first number you want and set AutoIncrementStep to the value you want to increment by each time a new row is added.
Auto incrementing is found in many database products, but how can it possibly work properly in your application? The connected classes haven’t been covered yet, but you can imagine that at some point you might want to send your new data to a back-end database. If your application supplies the auto-increment values, what will the database do, especially if it receives duplicate values from different client applications?
The answer is that these auto-increment values are never sent to the database because the auto-increment column in the database table will provide a value when the new row is added. After each new row is added, the back-end database table generates a new auto-increment number, and then your application will query the database to get the newly created number. Your application will then update its primary key number to the values that came from the database. This means that all foreign key references will need to be updated as well.
So what happens if you add new rows in your application to generate auto-increment values of 1 to 100 and then send these rows back to the database table, and the table already has 10 rows? When the first row is sent from your application, it has an auto-increment value of 1. The new auto-increment number created in the database will be 11. Your application queries for the 11 and tries to change the 1 to an 11 but throws an exception because 11 is already in your data table.
To solve this problem, set AutoIncrementSeed to -1 and set AutoIncrementStep to -1. This will cause negative numbers to be generated; they won’t conflict with the values coming from the database because the database doesn’t generate negative numbers.
EXAM TIP
For the exam, don’t forget that setting AutoIncementStep and AutoIncrementSeed to -1 will ensure that your numbers don’t conflict with values retrieved from the database server, because you will be questioned on this.
Creating DataRow Objects to Hold Data
After the DataTable object is created and contains DataColumn objects, you can populate the DataTable object by adding DataRow objects. A DataRow object can be created only in the context of a data table because the data row must conform to constraints of the DataTable object’s columns.
Adding Data to the Data Table
The DataTable object contains a Rows property of type DataRowCollection that stores DataRow objects. There are several ways to insert data into this collection.
DataRowCollection has an Add method that accepts a DataRow object. The Add method is also overloaded to accept an array of objects instead of a DataRow object. If an array of objects is passed to the Add method, the array object count must match the exact number of DataColumn objects the data table has.
The Add method works well when you are creating a new row of data. If you want to import DataRow objects that have been modified, you can use the ImportDataRow method, which will preserve the original state and all other settings. The DataTable class also provides several overloaded Load methods, which can be used to update existing DataRow objects or load new DataRow objects. The data table requires the PrimaryKey property to be set so the DataTable object can locate the rows to be updated. If you need to generate a data row, you can use the LoadDataRow method, which accepts an array of objects, and a LoadOption enumeration value. The possible values for the LoadOption enumeration are shown in Table 1-2.
LOADOPTION MEMBER
OverwriteChanges
PreserveChanges (default)
Upsert
DESCRIPTION
Overwrites the original data row version and the current data row version and changes the row state to Unchanged. New rows will have a row state of Unchanged as well.
Overwrites the original data row version but does not modify the current data row version. New rows will have a row state of Unchanged as well.
Overwrites the current data row version but does not modify the original data row version. New rows will have a row state of Added. Rows that had a row state of Unchanged will have a row state of Unchanged if the current data row version is the same as the original data row version, but if they are different, the row state will be Modified
The following code sample demonstrates the methods of creating and adding data into the cars DataTable object:
TABLE 1-2 LoadOption Enumeration Members
Sample of Visual Basic Code
'Add new DataRow by creating the DataRow first Dim newCar As DataRow = cars.NewRow() newCar ("Vin") = "123456789ABCD " newCar ("Make") = "Ford" newCar ("Year") = 2002 cars.Rows.Add(newCar)
'Add new DataRow by simply passing the values cars.Rows.Add("987654321XYZ", "Buick", 2001)
This code adds new DataRow objects to the cars data table. The first example explicitly creates a new data row, using the NewRow method on the cars data table. The next example adds a new data row by simply passing the values to the cars.Rows.Add method. Remember that nothing has been permanently stored to a database. Sending updates to a database will be covered in Chapter 2, “ADO.NET Connected Classes.”
Viewing the State of the DataRow Object by Using DataRowState
DataRow goes through a series of states that can be viewed and filtered at any time. You can retrieve the current state of a data row from its RowState property, which returns a value from the DataRowState enumeration. The DataRowState values are described in Table 1-3.
TABLE 1-3 RowState Enumeration Members
ROWSTATE VALUE DESCRIPTION
Detached The data row has been created but not added to a data table. Added The data row has been created and added to the data table.
Unchanged
Modified
Deleted
The data row has not changed since the last call to the AcceptChanges method. When the AcceptChanges method is called, the data row changes to this state.
The data row has been modified since the last time the AcceptChanges method was called. Adding a row and modifying the row will keep the row in the Added state. The row changes to the Modified state only if it was previously in the Unchanged state.
An attached data row is deleted by using the Delete method of the DataRow object or when it is removed from its table by calling the DataTable.DeleteRow method.
You can read the RowState property of the data row at any time to determine the current state of the data row. Figure 1-2 shows the RowState transitions at different times in the DataRow object’s life.
Dim dr as DataRow = dt.NewRow( )
dt.Rows.Add(dr)
dr("CustomerID")="AAAA"
Back to empty row
Back to “BBBB”
dt.RejectChanges( )
dt.Rows.Add(dr)
dt.AcceptChanges( )
dr("CustomerID")=“BBBB"
dt.AcceptChanges( )
dr("CustomerID")="ZZZZ"
dt.RejectChanges ( )
dr.Delete ( )
dt.RejectChanges
RowState = Detached
RowState = Added
RowState = Added
RowState = Detached
RowState = Added
RowState = Unchanged
RowState = Modified
RowState = Unchanged
RowState = Modified
RowState = Unchanged
RowState = Deleted
RowState = Unchanged
FIGURE 1-2 RowState is shown as it changes during the lifetime of a DataRow object.
After the CustomerID is assigned a value of “AAAA,” the row state does not change to Modified. The row state is still Added because RowState is an indicator of an action required to send an update of this data to the database. The fact that “AAAA” was placed into the CustomerID is not as important as the fact that the data row needs to be added to the database.
Another random document with no related content on Scribd:
THE EDITOR OF “BELGRAVIA,”
c/o F. V. WHITE & CO., 14 Bedford Street, Strand, W.C.
PRICE ONE SHILLING.
L O N D O N S O C I E T Y . (ESTABLISHED 1862.)
A MONTHLY MAGAZINE
Of Light and Amusing Literature by the most popular Authors of the Day.
TERMS OF SUBSCRIPTION: PAYABLE IN ADVANCE.
Twelve Months (post free),
Do. including the Summer Number and Christmas Number,
Handsomely BoundVolumes of “London Society”witha Gilt Edge (780 pages), Price 10s. 6d. each. Vol. LXIV. is now ready. Cases for binding Volumes, 2s. each.
(At all Booksellers’ and Bookstalls.)
12s. 14s.
“Readers who like to be amused should take in ‘London Society.’ ... ‘London Society’ is a good shilling’s worth.”—Ladies’Pictorial.
“This attractive magazine is remarkable for variety of subject and excellence of its light literature.”—PublicOpinion.
Allcommunicationstobeaddressedto
THE EDITOR OF “LONDON SOCIETY,”
c/o F. V. WHITE & CO., 14 Bedford Street, Strand, W.C.
Transcriber’s Note:
Words may have multiple spelling variations or inconsistent hyphenation in the text. Jargon, dialect, obsolete and alternative spellings were left unchanged. Misspelled words were corrected.
Obvious printing errors, such as upside down, reversed order, or partially printed letters and punctuation, were corrected. Final stops missing at the end of sentences and abbreviations were added. Duplicate words and printer’s marks were removed.
The volume number was added to the cover image.
The following items were changed:
Added missing word ‘of’. Changed ‘its’ to ‘the’.
***
END OF
THE PROJECT GUTENBERG EBOOK A BANKRUPT HEART, VOL. 3 (OF 3)
***
Updated editions will replace the previous one—the old editions will be renamed.
Creating the works from print editions not protected by U.S. copyright law means that no one owns a United States copyright in these works, so the Foundation (and you!) can copy and distribute it in the United States without permission and without paying copyright royalties. Special rules, set forth in the General Terms of Use part of this license, apply to copying and distributing Project Gutenberg™ electronic works to protect the PROJECT GUTENBERG™ concept and trademark. Project Gutenberg is a registered trademark, and may not be used if you charge for an eBook, except by following the terms of the trademark license, including paying royalties for use of the Project Gutenberg trademark. If you do not charge anything for copies of this eBook, complying with the trademark license is very easy. You may use this eBook for nearly any purpose such as creation of derivative works, reports, performances and research. Project Gutenberg eBooks may be modified and printed and given away—you may do practically ANYTHING in the United States with eBooks not protected by U.S. copyright law. Redistribution is subject to the trademark license, especially commercial redistribution.
START: FULL LICENSE
THE FULL PROJECT GUTENBERG LICENSE
PLEASE READ THIS BEFORE YOU DISTRIBUTE OR USE THIS WORK
To protect the Project Gutenberg™ mission of promoting the free distribution of electronic works, by using or distributing this work (or any other work associated in any way with the phrase “Project Gutenberg”), you agree to comply with all the terms of the Full Project Gutenberg™ License available with this file or online at www.gutenberg.org/license.
Section 1. General Terms of Use and Redistributing Project Gutenberg™ electronic works
1.A. By reading or using any part of this Project Gutenberg™ electronic work, you indicate that you have read, understand, agree to and accept all the terms of this license and intellectual property (trademark/copyright) agreement. If you do not agree to abide by all the terms of this agreement, you must cease using and return or destroy all copies of Project Gutenberg™ electronic works in your possession. If you paid a fee for obtaining a copy of or access to a Project Gutenberg™ electronic work and you do not agree to be bound by the terms of this agreement, you may obtain a refund from the person or entity to whom you paid the fee as set forth in paragraph 1.E.8.
1.B. “Project Gutenberg” is a registered trademark. It may only be used on or associated in any way with an electronic work by people who agree to be bound by the terms of this agreement. There are a few things that you can do with most Project Gutenberg™ electronic works even without complying with the full terms of this agreement. See paragraph 1.C below. There are a lot of things you can do with Project Gutenberg™ electronic works if you follow the terms of this agreement and help preserve free future access to Project Gutenberg™ electronic works. See paragraph 1.E below.
1.C. The Project Gutenberg Literary Archive Foundation (“the Foundation” or PGLAF), owns a compilation copyright in the collection of Project Gutenberg™ electronic works. Nearly all the individual works in the collection are in the public domain in the United States. If an individual work is unprotected by copyright law in the United States and you are located in the United States, we do not claim a right to prevent you from copying, distributing, performing, displaying or creating derivative works based on the work as long as all references to Project Gutenberg are removed. Of course, we hope that you will support the Project Gutenberg™ mission of promoting free access to electronic works by freely sharing Project Gutenberg™ works in compliance with the terms of this agreement for keeping the Project Gutenberg™ name associated with the work. You can easily comply with the terms of this agreement by keeping this work in the same format with its attached full Project Gutenberg™ License when you share it without charge with others.
1.D. The copyright laws of the place where you are located also govern what you can do with this work. Copyright laws in most countries are in a constant state of change. If you are outside the United States, check the laws of your country in addition to the terms of this agreement before downloading, copying, displaying, performing, distributing or creating derivative works based on this work or any other Project Gutenberg™ work. The Foundation makes no representations concerning the copyright status of any work in any country other than the United States.
1.E. Unless you have removed all references to Project Gutenberg:
1.E.1. The following sentence, with active links to, or other immediate access to, the full Project Gutenberg™ License must appear prominently whenever any copy of a Project Gutenberg™ work (any work on which the phrase “Project Gutenberg” appears, or with which the phrase “Project Gutenberg” is associated) is accessed, displayed, performed, viewed, copied or distributed:
This eBook is for the use of anyone anywhere in the United States and most other parts of the world at no cost and with almost no restrictions whatsoever. You may copy it, give it away or re-use it under the terms of the Project Gutenberg License included with this eBook or online at www.gutenberg.org. If you are not located in the United States, you will have to check the laws of the country where you are located before using this eBook.
1.E.2. If an individual Project Gutenberg™ electronic work is derived from texts not protected by U.S. copyright law (does not contain a notice indicating that it is posted with permission of the copyright holder), the work can be copied and distributed to anyone in the United States without paying any fees or charges. If you are redistributing or providing access to a work with the phrase “Project Gutenberg” associated with or appearing on the work, you must comply either with the requirements of paragraphs 1.E.1 through 1.E.7 or obtain permission for the use of the work and the Project Gutenberg™ trademark as set forth in paragraphs 1.E.8 or 1.E.9.
1.E.3. If an individual Project Gutenberg™ electronic work is posted with the permission of the copyright holder, your use and distribution must comply with both paragraphs 1.E.1 through 1.E.7 and any additional terms imposed by the copyright holder. Additional terms will be linked to the Project Gutenberg™ License for all works posted with the permission of the copyright holder found at the beginning of this work.
1.E.4. Do not unlink or detach or remove the full Project Gutenberg™ License terms from this work, or any files containing a part of this work or any other work associated with Project Gutenberg™.
1.E.5. Do not copy, display, perform, distribute or redistribute this electronic work, or any part of this electronic work, without prominently displaying the sentence set forth in paragraph 1.E.1
with active links or immediate access to the full terms of the Project Gutenberg™ License.
1.E.6. You may convert to and distribute this work in any binary, compressed, marked up, nonproprietary or proprietary form, including any word processing or hypertext form. However, if you provide access to or distribute copies of a Project Gutenberg™ work in a format other than “Plain Vanilla ASCII” or other format used in the official version posted on the official Project Gutenberg™ website (www.gutenberg.org), you must, at no additional cost, fee or expense to the user, provide a copy, a means of exporting a copy, or a means of obtaining a copy upon request, of the work in its original “Plain Vanilla ASCII” or other form. Any alternate format must include the full Project Gutenberg™ License as specified in paragraph 1.E.1.
1.E.7. Do not charge a fee for access to, viewing, displaying, performing, copying or distributing any Project Gutenberg™ works unless you comply with paragraph 1.E.8 or 1.E.9.
1.E.8. You may charge a reasonable fee for copies of or providing access to or distributing Project Gutenberg™ electronic works provided that:
• You pay a royalty fee of 20% of the gross profits you derive from the use of Project Gutenberg™ works calculated using the method you already use to calculate your applicable taxes. The fee is owed to the owner of the Project Gutenberg™ trademark, but he has agreed to donate royalties under this paragraph to the Project Gutenberg Literary Archive Foundation. Royalty payments must be paid within 60 days following each date on which you prepare (or are legally required to prepare) your periodic tax returns. Royalty payments should be clearly marked as such and sent to the Project Gutenberg Literary Archive Foundation at the address specified in Section 4, “Information
about donations to the Project Gutenberg Literary Archive Foundation.”
• You provide a full refund of any money paid by a user who notifies you in writing (or by e-mail) within 30 days of receipt that s/he does not agree to the terms of the full Project Gutenberg™ License. You must require such a user to return or destroy all copies of the works possessed in a physical medium and discontinue all use of and all access to other copies of Project Gutenberg™ works.
• You provide, in accordance with paragraph 1.F.3, a full refund of any money paid for a work or a replacement copy, if a defect in the electronic work is discovered and reported to you within 90 days of receipt of the work.
• You comply with all other terms of this agreement for free distribution of Project Gutenberg™ works.
1.E.9. If you wish to charge a fee or distribute a Project Gutenberg™ electronic work or group of works on different terms than are set forth in this agreement, you must obtain permission in writing from the Project Gutenberg Literary Archive Foundation, the manager of the Project Gutenberg™ trademark. Contact the Foundation as set forth in Section 3 below.
1.F.
1.F.1. Project Gutenberg volunteers and employees expend considerable effort to identify, do copyright research on, transcribe and proofread works not protected by U.S. copyright law in creating the Project Gutenberg™ collection. Despite these efforts, Project Gutenberg™ electronic works, and the medium on which they may be stored, may contain “Defects,” such as, but not limited to, incomplete, inaccurate or corrupt data, transcription errors, a copyright or other intellectual property infringement, a defective or