Chapter 5. Copying and Transferring Data

Introduction

This chapter focuses on copying data between ADO.NET classes and between ADO and ADO.NET classes, serializing and deserializing data, and encrypting data and login credentials to build secure applications.

Copying rows from one DataTable to another and copying tables from one DataSet to another are operations performed frequently in data-centric applications. Recipe 5.1 and Recipe 5.2 show different ways to copy data and discuss the advantages, limitations, and disadvantages of the different approaches.

The DataReader provides connected forward-only, read-only access to a data stream while the DataSet provides disconnected access to data stored as an in-memory relational database. There is no built-in method to convert a DataReader to a DataSet, so Recipe 5.3 shows how it’s done.

In addition, this chapter covers:

Serializing and deserializing data

Serialization allows data conversion to a format that can be persisted or transported. The .NET framework supports serialization and deserialization with the System.Runtime.Serialization namespace. Support for binary, XML, and SOAP formats is built in and serialization can easily be customized if required. Recipe 5.4 and Recipe 5.5 show how to serialize and deserialize data.

As well as copying data, ADO.NET supports merging disconnected data in DataTable or DataSet objects into each other. Recipe 5.6 shows how merging works and how to use the arguments that control the merge operation.

Security ...

Get ADO.NET Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.