Copying and Transferring Data

Table of contents:

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 and encryption

The .NET Framework provides extensive support for encryption in the System.Security.Cryptography namespace. The classes in the namespace are both easy and intuitive to use. You can use the cryptography classes to encrypt a disconnected data class such as a DataSet prior to transmission in a remoting or web services call. Encrypting the data allows it to be transmitted securely using HTTP as a transmission protocol. An encrypted protocol such as HTTPS is not required. Recipe 5.7 explores cryptographic algorithms, public keys, private keys, and demonstrates encryption solutions using symmetric and asymmetric keys.

ASP.NET uses the classes in the System.Web.Security namespace to implement security in web service applications. Securing authentication credentialsusually a username and passwordduring transmission and storage in a database is critical to building secure distributed applications. Recipe 5.8 demonstrates how to protect credentials using a hash algorithm with password salt.

ADO

The OLE DB DataAdapter supports importing ADO Recordset or Record objects into a DataTable or DataSet . This is a one-way operation: changes made to the DataTable or DataSet can't be updated back to ADO using the data adapter. ADO.NET does not, however, provide a way to convert a DataTable or DataSet to an ADO Recordset ; therefore, Recipe 5.10 shows how to do this.

With evolution of ADO to ADO.NET, a few functions got lost along the way. Recipe 5.11 and Recipe 5.12 recreate the ADO Recordset GetString( ) and GetRows( ) methods in ADO.NET.

Connecting to Data

Retrieving and Managing Data

Searching and Analyzing Data

Adding and Modifying Data

Copying and Transferring Data

Maintaining Database Integrity

Binding Data to .NET User Interfaces

Working with XML

Optimizing .NET Data Access

Enumerating and Maintaining Database Objects

Appendix A. Converting from C# to VB Syntax



ADO. NET Cookbook
ADO.NET 3.5 Cookbook (Cookbooks (OReilly))
ISBN: 0596101406
EAN: 2147483647
Year: 2002
Pages: 222
Authors: Bill Hamilton

Flylib.com © 2008-2020.
If you may any questions please contact us: flylib@qtcs.net