+ All Categories
Home > Documents > C# Programming IV-4A: - sheepsqueezers.com

C# Programming IV-4A: - sheepsqueezers.com

Date post: 21-Apr-2023
Category:
Upload: khangminh22
View: 0 times
Download: 0 times
Share this document with a friend
81
sheepsqueezers.com Copyright ©2011 sheepsqueezers.com C# Programming IV-4A: System.Data Namespace
Transcript

sheepsqueezers.com

Copyright ©2011 sheepsqueezers.com

C# Programming IV-4A: System.Data Namespace

sheepsqueezers.com

Copyright ©2011 sheepsqueezers.com

This work may be reproduced and redistributed, in whole or in part, without alteration and without prior written permission, provided all copies contain the following statement:

Copyright ©2011 sheepsqueezers.com. This

work is reproduced and distributed with the

permission of the copyright holder.

Legal Stuff

This presentation as well as other presentations and documents found on the sheepsqueezers.com website may contain quoted material from outside sources such as books, articles and websites. It is our intention to diligently reference all outside sources. Occasionally, though, a reference may be missed. No copyright infringement whatsoever is intended, and all outside source materials are copyright of their respective author(s).

sheepsqueezers.com

Copyright ©2011 sheepsqueezers.com

.NET Lecture Series

C# Programming V:

Introduction to LINQ

C# Programming I: Concepts of OOP

C# Programming II:

Beginning C#

C# Programming III:

Advanced C#

C# Programming IV-1:

System Namespace

C# Programming IV-2: System.Collections

Namespace

C# Programming IV-3: System.Collections.

Generic Namespace

C# Programming IV-4A:

System.Data Namespace

C# Programming IV-4B: System.Data.Odbc

Namespace

C# Programming IV-4C: System.Data.OleDb

Namespace

C# Programming IV-4E:

System.Data.SqlClient Namespace

C# Programming IV-4F:

System.Data.SqlTypes Namespace

C# Programming IV-5:

System.Drawing/(2D) Namespace

C# Programming IV-7: System.Numerics

C# Programming IV-6:

System.IO Namespace

C# Programming IV-8: System.Text and

System.Text. RegularExpressions

Namespaces

C# Programming IV-4D:

Oracle.DataAccess.Client Namespace

C#

Self-Inflicted

Project #1

Address

Cleaning

C#

Self-Inflicted

Project #2

Large

Intersection Problem

sheepsqueezers.com

Copyright ©2011 sheepsqueezers.com Copyright ©2011 sheepsqueezers.com

sheepsqueezers.com

Charting Our Course The System.Data Namespace

What Next?

sheepsqueezers.com

Copyright ©2011 sheepsqueezers.com Copyright ©2011 sheepsqueezers.com

sheepsqueezers.com

The System.Data Namespace

The System.Data namespace is defined by Microsoft as follows:

The System.Data namespace provides access to classes that represent the ADO.NET architecture. ADO.NET lets you build components that efficiently manage data from multiple data sources. In a disconnected scenario such as the Internet, ADO.NET provides the tools to request, update, and reconcile data in multiple tier systems. The ADO.NET architecture is also implemented in client applications, such as Windows Forms, or HTML pages created by ASP.NET. The centerpiece of the ADO.NET architecture is the DataSet class. Each DataSet can contain multiple DataTable objects, with each DataTable containing data from a single data source, such as SQL Server. Each DataTable contains a DataColumnCollection--a collection of DataColumn objects--that determines the schema of each DataTable. The DataType property determines the type of data held by the DataColumn. The ReadOnly and AllowDBNull properties let you further guarantee data integrity. The Expression property lets you construct calculated columns. If a DataTable participates in a parent/child relationship with another DataTable, the relationship is constructed by adding a DataRelation to the DataRelationCollection of a DataSet object. When such a relation is added, a UniqueConstraint and a ForeignKeyConstraint are both created automatically, depending on the parameter settings for the constructor. The UniqueConstraint guarantees that values that are contained in a column are unique. The ForeignKeyConstraint determines what action will happen to the child row or column when a primary key value is changed or deleted.

sheepsqueezers.com

Copyright ©2011 sheepsqueezers.com Copyright ©2011 sheepsqueezers.com

sheepsqueezers.com

The System.Data Namespace

Using the System.Data.SqlClient namespace (the.NET Framework Data Provider for SQL Server), the System.Data.Odbc namespace (the.NET Framework Data Provider for ODBC), the System.Data.OleDb namespace (the.NET Framework Data Provider for OLE DB), or the System.Data.OracleClient namespace (the .NET Framework Data Provider for Oracle), you can access a data source to use together with a DataSet. Each.NET Framework data provider has a corresponding DataAdapter that you use as a bridge between a data source and a DataSet.

Now, for those of you thinking that this is the namespace that will allow you to pull data from a database, I have some bad news for you: the System.Data

namespace is not responsible for pulling data from or pushing data to a database. But, don't stop reading just yet!! The System.Data namespace

allows you to create a database – complete with tables, constraints, views, and so on – in your application whether it's a console application, a standalone GUI application, a web application using ASP.NET, etc. With that said, it is the responsibility of the following namespaces to pull data from and push data to a database:

• System.Data.Odbc (for an ODBC connection created in the ODBC Applet)

• System.Data.Oledb (for OLEDB providers)

• System.Data.OracleClient (for Oracle databases)

• System.Data.SqlClient (for SQL Server databases).

Note that Oracle provides the following downloads in their Oracle Data Access Components (ODAC) bundle:

sheepsqueezers.com

Copyright ©2011 sheepsqueezers.com Copyright ©2011 sheepsqueezers.com

sheepsqueezers.com

The System.Data Namespace • Oracle Developer Tools for Visual Studio 11.2.0.2.0

• Oracle Data Provider for .NET 4 11.2.0.2.0

• Oracle Data Provider for .NET 2.0 11.2.0.2.0

• Oracle Providers for ASP.NET 4 11.2.0.2.0

• Oracle Providers for ASP.NET 2.0 11.2.0.2.0

• Oracle Database Extensions for .NET 4 11.2.0.2.0 -- for upgrade only

• Oracle Database Extensions for .NET 2.0 11.2.0.2.0 -- for upgrade only

• Oracle Provider for OLE DB 11.2.0.2.0

• Oracle Objects for OLE 11.2.0.2.0

• Oracle Services for Microsoft Transaction Server 11.2.0.2.0

• Oracle ODBC Driver 11.2.0.2.0

• Oracle SQL*Plus 11.2.0.2.0

• Oracle Instant Client 11.2.0.2.0

You can download the ODAC (for both 32-bit and 64-bit Windows) from Oracle's website at:

http://www.oracle.com/technetwork/database/windows/downloads/index.html.

Microsoft recommends that you use the Oracle third-party data providers instead of using the System.Data.OracleClient namespace.

Note that the System.Data.Common namespace contains classes shared by the

.NET Framework data providers. The classes in System.Data.Common are intended to give developers a way to write ADO.NET code that will work against all .NET Framework data providers.

This lecture focuses solely on the System.Data namespace.

sheepsqueezers.com

Copyright ©2011 sheepsqueezers.com Copyright ©2011 sheepsqueezers.com

sheepsqueezers.com

The System.Data Namespace

As you could guess, the System.Data namespace is made up of several classes. Duh! But, you can think of these classes as being arrange hierarchically as follows:

DataSet - Represents an in-memory cache of data.

DataTableCollection - Represents the collection of tables for the DataSet.

DataTable - Represents one table of in-memory data.

DataColumnCollection - Represents a collection of DataColumn objects for a DataTable.

DataColumn - Represents the schema of a column in a DataTable.

ConstraintCollection - Represents a collection of constraints for a DataTable.

Constraint - Represents a constraint that can be enforced on one or more DataColumn objects.

ForeignKeyConstraint - Represents an action restriction enforced on a set of columns in a primary

key/foreign key relationship when a value or row is either deleted or updated.

UniqueConstraint - Represents a restriction on a set of columns in which all values must be unique.

DataRowCollection - Represents a collection of rows for a DataTable.

DataRow - Represents a row of data in a DataTable.

DataRelationCollection - Represents the collection of DataRelation objects for this DataSet.

DataRelation - Represents a parent/child relationship between two DataTable objects.

DataTableReader - The DataTableReader obtains the contents of one or more DataTable objects in the form

of one or more read-only, forward-only result sets.

DataView - Represents a databindable, customized view of a DataTable for sorting, filtering, searching,

editing, and navigation.

As you see, the DataSet is at the top of the hierarchy. Each DataSet contains one or more DataTables. (This is sounding a little like a regular database!) Each DataTable contains one or more DataColumns (Wow…this is really sounding like a regular database!!) as well as one or more DataRows. Now, each DataColumn can have zero or more constraints on them and each DataTable can

have a parent/child relationship between other tables.

sheepsqueezers.com

Copyright ©2011 sheepsqueezers.com Copyright ©2011 sheepsqueezers.com

sheepsqueezers.com

The System.Data Namespace

So, as you can see, the hierarchy shown on the previous slide really does mimic what happens in a real database with tables, columns, rows, primary keys, etc.

Note, also, that if you application accepts changes to a column in a table, you can merge those changes to the master table or reject the changes. This way your tables are up-to-date based on the information entered by the user.

I have created a simple example (see next slide) that you can use to follow the discussion on the next few slides.

Note that there are several infrastructure-only classes (such as DataRowBuilder and TypedTableBaseExtensions) that we don't talk about in this presentation.

sheepsqueezers.com

Copyright ©2011 sheepsqueezers.com Copyright ©2011 sheepsqueezers.com

sheepsqueezers.com

The System.Data Namespace using System;

using System.Data;

//*---------------------------------------------------------------------------*

//* The DataSet we will create is called "FatKids". It will contain two *

//* DataTables with the following columns: *

//* *

//* 1. Table: FatKidsData *

//* Columns: FK_ID - Id of the Fat Kid (Int32) *

//* FNAME - First name of the Fat Kid (String) *

//* HEIGHT - Height of the Fat Kid (Int32) *

//* WEIGHT - Weight of the Fat Kid (Int32) *

//* FATTYINDEX - Fatty Index (Double) *

//* *

//* 2. Table: FatKidsPhone *

//* Columns: FK_ID - Id of the Fat Kid (Int32) *

//* PHONENUM - Phone Number of the Fat Kid (String) *

//* *

//* There will be primary key constraints on all FK_ID columns. *

//*---------------------------------------------------------------------------*

class MainProgram {

public static void Main() {

//Create a new DataSet

DataSet dsFatKidsDB = new DataSet("FatKids");

//Create two tables within the DataSet

DataTableCollection dtcFatKids = dsFatKidsDB.Tables;

dtcFatKids.Add("FatKids");

//Create an additional table using the DataTable class...

DataTable dtFatKidsPhone = new DataTable("FatKidsPhone");

//...then add this new table to the Fat Kids Database using the DataTableCollection's Add method

dtcFatKids.Add(dtFatKidsPhone);

…continued on next slide…

sheepsqueezers.com

Copyright ©2011 sheepsqueezers.com Copyright ©2011 sheepsqueezers.com

sheepsqueezers.com

The System.Data Namespace //Write out the count of the DataTables within the DataSet.

Console.WriteLine("Total Number of DataTables in the DataSet={0}",dtcFatKids.Count);

//Create all of the columns we will need to add to our tables.

DataColumn dcFID1 = new DataColumn("FID",System.Type.GetType("System.Int32")); dcFID1.AllowDBNull = false;

DataColumn dcFID2 = new DataColumn("FID",System.Type.GetType("System.Int32")); dcFID2.AllowDBNull = false;

DataColumn dcFNAME = new DataColumn("FNAME",System.Type.GetType("System.String")); dcFNAME.AllowDBNull =

false; dcFNAME.MaxLength=8;

DataColumn dcHEIGHT = new DataColumn("HEIGHT",System.Type.GetType("System.Int32")); dcHEIGHT.AllowDBNull =

true;

DataColumn dcWEIGHT = new DataColumn("WEIGHT",System.Type.GetType("System.Int32")); dcWEIGHT.AllowDBNull =

true;

DataColumn dcFATTYINDEX = new DataColumn("FATTYINDEX",System.Type.GetType("System.Double"));

dcFATTYINDEX.AllowDBNull = true;

DataColumn dcBMI = new DataColumn("BMI",System.Type.GetType("System.Double"));

DataColumn dcPHONENUM = new DataColumn("PHONENUM",System.Type.GetType("System.String"));

dcPHONENUM.AllowDBNull = true; dcPHONENUM.MaxLength=12;

//Next, add columns to our FatKids table. Note that dtcFatKids.Columns returns a DataColumnCollection!

dtcFatKids["FatKids"].Columns.Add(dcFID1);

dtcFatKids["FatKids"].Columns.Add(dcFNAME);

dtcFatKids["FatKids"].Columns.Add(dcHEIGHT);

dtcFatKids["FatKids"].Columns.Add(dcWEIGHT);

dtcFatKids["FatKids"].Columns.Add(dcFATTYINDEX);

dtcFatKids["FatKids"].Columns.Add(dcBMI);

//Create an expression for the BMI

dtcFatKids["FatKids"].Columns["BMI"].Expression = "703*WEIGHT/(HEIGHT*HEIGHT)";

//Next, add columns to the FatKidsPhone table.

dtcFatKids["FatKidsPhone"].Columns.Add(dcFID2);

dtcFatKids["FatKidsPhone"].Columns.Add(dcPHONENUM);

…continued on next slide…

sheepsqueezers.com

Copyright ©2011 sheepsqueezers.com Copyright ©2011 sheepsqueezers.com

sheepsqueezers.com

The System.Data Namespace //Create primary keys on the two identifier columns.

dtcFatKids["FatKids"].PrimaryKey = new DataColumn[] {dtcFatKids["FatKids"].Columns["FID"]};

dtcFatKids["FatKidsPhone"].PrimaryKey = new DataColumn[] {dtcFatKids["FatKidsPhone"].Columns["FID"]};

//Next, add data to the FatKidsPhone table.

DataRow drROWP;

drROWP = dsFatKidsDB.Tables["FatKidsPhone"].NewRow();drROWP["FID"] = 1; drROWP["PHONENUM"] = "215-123-

4567"; dsFatKidsDB.Tables["FatKidsPhone"].Rows.Add(drROWP);

drROWP = dsFatKidsDB.Tables["FatKidsPhone"].NewRow();drROWP["FID"] = 2; drROWP["PHONENUM"] = "215-123-

5678"; dsFatKidsDB.Tables["FatKidsPhone"].Rows.Add(drROWP);

drROWP = dsFatKidsDB.Tables["FatKidsPhone"].NewRow();drROWP["FID"] = 3; drROWP["PHONENUM"] = "215-123-

6789"; dsFatKidsDB.Tables["FatKidsPhone"].Rows.Add(drROWP);

drROWP = dsFatKidsDB.Tables["FatKidsPhone"].NewRow();drROWP["FID"] = 4; drROWP["PHONENUM"] = "215-123-

7890"; dsFatKidsDB.Tables["FatKidsPhone"].Rows.Add(drROWP);

drROWP = dsFatKidsDB.Tables["FatKidsPhone"].NewRow();drROWP["FID"] = 5; drROWP["PHONENUM"] = "215-123-

8901"; dsFatKidsDB.Tables["FatKidsPhone"].Rows.Add(drROWP);

drROWP = dsFatKidsDB.Tables["FatKidsPhone"].NewRow();drROWP["FID"] = 6; drROWP["PHONENUM"] = "215-123-

9012"; dsFatKidsDB.Tables["FatKidsPhone"].Rows.Add(drROWP);

drROWP = dsFatKidsDB.Tables["FatKidsPhone"].NewRow();drROWP["FID"] = 7; drROWP["PHONENUM"] = "215-123-

0123"; dsFatKidsDB.Tables["FatKidsPhone"].Rows.Add(drROWP);

//Next, add data to the FatKids table.

DataRow drROW;

drROW = dsFatKidsDB.Tables["FatKids"].NewRow();drROW["FID"] = 1; drROW["FNAME"] = "ALBERT"; drROW["HEIGHT"]

= 45; drROW["WEIGHT"] = 150; drROW["FATTYINDEX"] = 3.3333; dsFatKidsDB.Tables["FatKids"].Rows.Add(drROW);

drROW = dsFatKidsDB.Tables["FatKids"].NewRow();drROW["FID"] = 2; drROW["FNAME"] = "ROSEMARY";

drROW["HEIGHT"] = 35; drROW["WEIGHT"] = 123; drROW["FATTYINDEX"] = 3.5143;

dsFatKidsDB.Tables["FatKids"].Rows.Add(drROW);

drROW = dsFatKidsDB.Tables["FatKids"].NewRow();drROW["FID"] = 3; drROW["FNAME"] = "TOMMY"; drROW["HEIGHT"]

= 78; drROW["WEIGHT"] = 167; drROW["FATTYINDEX"] = 2.1410; dsFatKidsDB.Tables["FatKids"].Rows.Add(drROW);

drROW = dsFatKidsDB.Tables["FatKids"].NewRow();drROW["FID"] = 4; drROW["FNAME"] = "BUDDY"; drROW["HEIGHT"]

= 12; drROW["WEIGHT"] = 189; drROW["FATTYINDEX"] = 15.7500; dsFatKidsDB.Tables["FatKids"].Rows.Add(drROW);

drROW = dsFatKidsDB.Tables["FatKids"].NewRow();drROW["FID"] = 5; drROW["FNAME"] = "FARQUAR";

drROW["HEIGHT"] = 76; drROW["WEIGHT"] = 198; drROW["FATTYINDEX"] = 2.6053;

dsFatKidsDB.Tables["FatKids"].Rows.Add(drROW);

…continued on next slide…

sheepsqueezers.com

Copyright ©2011 sheepsqueezers.com Copyright ©2011 sheepsqueezers.com

sheepsqueezers.com

The System.Data Namespace drROW = dsFatKidsDB.Tables["FatKids"].NewRow();drROW["FID"] = 6; drROW["FNAME"] = "SIMON"; drROW["HEIGHT"]

= 87; drROW["WEIGHT"] = 256; drROW["FATTYINDEX"] = 2.9425; dsFatKidsDB.Tables["FatKids"].Rows.Add(drROW);

drROW = dsFatKidsDB.Tables["FatKids"].NewRow();drROW["FID"] = 7; drROW["FNAME"] = "LAUREN"; drROW["HEIGHT"]

= 54; drROW["WEIGHT"] = 876; drROW["FATTYINDEX"] = 16.2222; dsFatKidsDB.Tables["FatKids"].Rows.Add(drROW);

//Add a foreign key between the FID columns in the FatKids and FatKidsPhone tables. Note that we

//are adding this to the FatKidsPhone table instead of the FatKids table!

ForeignKeyConstraint fkcFID = new

ForeignKeyConstraint("CONSTRAINT_01",dsFatKidsDB.Tables["FatKids"].Columns["FID"],dsFatKidsDB.Tables["FatKids

Phone"].Columns["FID"]);

fkcFID.DeleteRule = Rule.Cascade; //Cascade delete...that is, when a row is deleted from FatKids, the

corresponding row is deleted from FatKidsPhone!

dsFatKidsDB.Tables["FatKidsPhone"].Constraints.Add(fkcFID);

//Printout the data in the tables

foreach(DataTable dtThisTable in dsFatKidsDB.Tables) {

Console.Write("DataTable={0}\n",dtThisTable.TableName);

foreach(DataRow drThisRow in dtThisTable.Rows) {

Console.Write("\t");

foreach(DataColumn dtThisColumn in dtThisTable.Columns) {

Console.Write("{0} ",drThisRow[dtThisColumn]);

}

Console.WriteLine();

}

}

//Next, let's delete a row from the FatKids table and see if our

//ForeignKeyConstraint will remove the corresponding row in FatKidsPhone.

dsFatKidsDB.Tables["FatKids"].Rows[0].Delete();

…continued on next slide…

sheepsqueezers.com

Copyright ©2011 sheepsqueezers.com Copyright ©2011 sheepsqueezers.com

sheepsqueezers.com

The System.Data Namespace //Printout the data in the tables

foreach(DataTable dtThisTable in dsFatKidsDB.Tables) {

Console.Write("DataTable={0}\n",dtThisTable.TableName);

foreach(DataRow drThisRow in dtThisTable.Rows) {

Console.Write("\t");

foreach(DataColumn dtThisColumn in dtThisTable.Columns) {

Console.Write("{0} ",drThisRow[dtThisColumn]);

}

Console.WriteLine();

}

}

}

}

The results are below:

Total Number of DataTables in the DataSet=2

DataTable=FatKids

1 ALBERT 45 150 3.3333 52.0740740740741

2 ROSEMARY 35 123 3.5143 70.5869387755102

3 TOMMY 78 167 2.141 19.2966798159106

4 BUDDY 12 189 15.75 922.6875

5 FARQUAR 76 198 2.6053 24.0986842105263

6 SIMON 87 256 2.9425 23.7769850706831

7 LAUREN 54 876 16.2222 211.189300411523

DataTable=FatKidsPhone

1 215-123-4567

2 215-123-5678

3 215-123-6789

4 215-123-7890

5 215-123-8901

6 215-123-9012

7 215-123-0123

sheepsqueezers.com

Copyright ©2011 sheepsqueezers.com Copyright ©2011 sheepsqueezers.com

sheepsqueezers.com

The System.Data Namespace

And after we delete the first row:

DataTable=FatKids

2 ROSEMARY 35 123 3.5143 70.5869387755102

3 TOMMY 78 167 2.141 19.2966798159106

4 BUDDY 12 189 15.75 922.6875

5 FARQUAR 76 198 2.6053 24.0986842105263

6 SIMON 87 256 2.9425 23.7769850706831

7 LAUREN 54 876 16.2222 211.189300411523

DataTable=FatKidsPhone

2 215-123-5678

3 215-123-6789

4 215-123-7890

5 215-123-8901

6 215-123-9012

7 215-123-0123

sheepsqueezers.com

Copyright ©2011 sheepsqueezers.com Copyright ©2011 sheepsqueezers.com

sheepsqueezers.com

The System.Data Namespace

Classes

DataSet

sheepsqueezers.com

Copyright ©2011 sheepsqueezers.com Copyright ©2011 sheepsqueezers.com

sheepsqueezers.com

DataSet

The DataSet class represents an in-memory cache of data.

Constructors • DataSet() - Initializes a new instance of the DataSet class.

• DataSet(String) - Initializes a new instance of a DataSet class with the given name.

• DataSet(SerializationInfo, StreamingContext) - Infrastructure. Initializes a new instance of a DataSet class that has the given serialization information and context.

• DataSet(SerializationInfo, StreamingContext, Boolean) - Infrastructure. Initializes a new instance of the DataSet class.

Properties • CaseSensitive - Gets or sets a value indicating whether string comparisons within DataTable objects are case-sensitive.

• Container - Gets the container for the component. (Inherited from MarshalByValueComponent.)

• DataSetName - Gets or sets the name of the current DataSet.

• DefaultViewManager - Gets a custom view of the data contained in the DataSet to allow filtering, searching, and navigating using a custom DataViewManager.

• DesignMode - Gets a value indicating whether the component is currently in design mode. (Inherited from MarshalByValueComponent.)

• EnforceConstraints - Gets or sets a value indicating whether constraint rules are followed when attempting any update operation.

• Events - Gets the list of event handlers that are attached to this component. (Inherited from MarshalByValueComponent.)

• ExtendedProperties - Gets the collection of customized user information associated with the DataSet.

• HasErrors - Gets a value indicating whether there are errors in any of the DataTable objects within this DataSet.

• IsInitialized - Gets a value that indicates whether the DataSet is initialized.

• Locale - Gets or sets the locale information used to compare strings within the table.

• Namespace - Gets or sets the namespace of the DataSet.

• Prefix - Gets or sets an XML prefix that aliases the namespace of the DataSet.

• Relations - Get the collection of relations that link tables and allow navigation from parent tables to child tables.

• RemotingFormat - Gets or sets a SerializationFormat for the DataSet used during remoting.

• SchemaSerializationMode - Gets or sets a SchemaSerializationMode for a DataSet.

• Site - Gets or sets an System.ComponentModel.ISite for the DataSet. (Overrides MarshalByValueComponent.Site.)

• Tables - Gets the collection of tables contained in the DataSet.

sheepsqueezers.com

Copyright ©2011 sheepsqueezers.com Copyright ©2011 sheepsqueezers.com

sheepsqueezers.com

DataSet

Methods • AcceptChanges - Commits all the changes made to this DataSet since it was loaded or since the last time AcceptChanges

was called.

• BeginInit - Begins the initialization of a DataSet that is used on a form or used by another component. The initialization occurs at run time.

• Clear - Clears the DataSet of any data by removing all rows in all tables.

• Clone - Copies the structure of the DataSet, including all DataTable schemas, relations, and constraints. Does not copy any data.

• Copy - Copies both the structure and data for this DataSet.

• CreateDataReader() - Returns a DataTableReader with one result set per DataTable, in the same sequence as the tables appear in the Tables collection.

• CreateDataReader(DataTable[]) - Returns a DataTableReader with one result set per DataTable.

• DetermineSchemaSerializationMode(XmlReader) - Determines the SchemaSerializationMode for a DataSet.

• DetermineSchemaSerializationMode(SerializationInfo, StreamingContext) - Determines the SchemaSerializationMode for a DataSet.

• Dispose() - Releases all resources used by the MarshalByValueComponent. (Inherited from MarshalByValueComponent.)

• Dispose(Boolean) - Releases the unmanaged resources used by the MarshalByValueComponent and optionally releases the managed resources. (Inherited from MarshalByValueComponent.)

• EndInit - Ends the initialization of a DataSet that is used on a form or used by another component. The initialization occurs at run time.

• Equals(Object) - Determines whether the specified Object is equal to the current Object. (Inherited from Object.)

• Finalize - Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from MarshalByValueComponent.)

• GetChanges() - Gets a copy of the DataSet that contains all changes made to it since it was loaded or since AcceptChanges was last called.

• GetChanges(DataRowState) - Gets a copy of the DataSet containing all changes made to it since it was last loaded, or since AcceptChanges was called, filtered by DataRowState.

• GetDataSetSchema - Infrastructure. Gets a copy of XmlSchemaSet for the DataSet.

• GetHashCode - Serves as a hash function for a particular type. (Inherited from Object.)

• GetObjectData - Populates a serialization information object with the data needed to serialize the DataSet.

• GetSchemaSerializable - Infrastructure. Returns a serializable XMLSchema instance.

• GetSerializationData - Infrastructure. Deserializes the table data from the binary or XML stream.

• GetService - Gets the implementer of the IServiceProvider. (Inherited from MarshalByValueComponent.)

• GetType - Gets the Type of the current instance. (Inherited from Object.)

• GetXml - Returns the XML representation of the data stored in the DataSet.

• GetXmlSchema - Returns the XML Schema for the XML representation of the data stored in the DataSet.

sheepsqueezers.com

Copyright ©2011 sheepsqueezers.com Copyright ©2011 sheepsqueezers.com

sheepsqueezers.com

DataSet

Methods (continued) • HasChanges() - Gets a value indicating whether the DataSet has changes, including new, deleted, or modified rows.

• HasChanges(DataRowState) - Gets a value indicating whether the DataSet has changes, including new, deleted, or modified rows, filtered by DataRowState.

• InferXmlSchema(Stream, String[]) - Applies the XML schema from the specified Stream to the DataSet.

• InferXmlSchema(String, String[]) - Applies the XML schema from the specified file to the DataSet.

• InferXmlSchema(TextReader, String[]) - Applies the XML schema from the specified TextReader to the DataSet.

• InferXmlSchema(XmlReader, String[]) - Applies the XML schema from the specified XmlReader to the DataSet.

• InitializeDerivedDataSet - Infrastructure. Deserialize all of the tables data of the DataSet from the binary or XML stream.

• IsBinarySerialized - Inspects the format of the serialized representation of the DataSet.

• Load(IDataReader, LoadOption, DataTable[]) - Fills a DataSet with values from a data source using the supplied IDataReader, using an array of DataTable instances to supply the schema and namespace information.

• Load(IDataReader, LoadOption, String[]) - Fills a DataSet with values from a data source using the supplied IDataReader, using an array of strings to supply the names for the tables within the DataSet.

• Load(IDataReader, LoadOption, FillErrorEventHandler, DataTable[]) - Fills a DataSet with values from a data source using the supplied IDataReader, using an array of DataTable instances to supply the schema and namespace information.

• MemberwiseClone - Creates a shallow copy of the current Object. (Inherited from Object.)

• Merge(DataRow[]) - Merges an array of DataRow objects into the current DataSet.

• Merge(DataSet) - Merges a specified DataSet and its schema into the current DataSet.

• Merge(DataTable) - Merges a specified DataTable and its schema into the current DataSet.

• Merge(DataSet, Boolean) - Merges a specified DataSet and its schema into the current DataSet, preserving or discarding any changes in this DataSet according to the given argument.

• Merge(DataRow[], Boolean, MissingSchemaAction) - Merges an array of DataRow objects into the current DataSet, preserving or discarding changes in the DataSet and handling an incompatible schema according to the given arguments.

• Merge(DataSet, Boolean, MissingSchemaAction) - Merges a specified DataSet and its schema with the current DataSet, preserving or discarding changes in the current DataSet and handling an incompatible schema according to the given arguments.

• Merge(DataTable, Boolean, MissingSchemaAction) - Merges a specified DataTable and its schema into the current DataSet, preserving or discarding changes in the DataSet and handling an incompatible schema according to the given arguments.

• OnPropertyChanging - Raises the OnPropertyChanging event.

• OnRemoveRelation - Occurs when a DataRelation object is removed from a DataTable.

• OnRemoveTable - Occurs when a DataTable is removed from a DataSet.

• RaisePropertyChanging - Sends a notification that the specified DataSet property is about to change.

• ReadXml(Stream) - Reads XML schema and data into the DataSet using the specified System.IO.Stream.

• ReadXml(String) - Reads XML schema and data into the DataSet using the specified file.

sheepsqueezers.com

Copyright ©2011 sheepsqueezers.com Copyright ©2011 sheepsqueezers.com

sheepsqueezers.com

DataSet

Methods (continued) • ReadXml(TextReader) - Reads XML schema and data into the DataSet using the specified System.IO.TextReader.

• ReadXml(XmlReader) - Reads XML schema and data into the DataSet using the specified System.Xml.XmlReader.

• ReadXml(Stream, XmlReadMode) - Reads XML schema and data into the DataSet using the specified System.IO.Stream and XmlReadMode.

• ReadXml(String, XmlReadMode) - Reads XML schema and data into the DataSet using the specified file and XmlReadMode.

• ReadXml(TextReader, XmlReadMode) - Reads XML schema and data into the DataSet using the specified System.IO.TextReader and XmlReadMode.

• ReadXml(XmlReader, XmlReadMode) - Reads XML schema and data into the DataSet using the specified System.Xml.XmlReader and XmlReadMode.

• ReadXmlSchema(Stream) - Reads the XML schema from the specified Stream into the DataSet.

• ReadXmlSchema(String) - Reads the XML schema from the specified file into the DataSet.

• ReadXmlSchema(TextReader) - Reads the XML schema from the specified TextReader into the DataSet.

• ReadXmlSchema(XmlReader) - Reads the XML schema from the specified XmlReader into the DataSet.

• ReadXmlSerializable - Infrastructure. Ignores attributes and returns an empty DataSet.

• RejectChanges - Rolls back all the changes made to the DataSet since it was created, or since the last time DataSet.AcceptChanges was called.

• Reset - Resets the DataSet to its original state. Subclasses should override Reset to restore a DataSet to its original state.

• ShouldSerializeRelations - Gets a value indicating whether Relations property should be persisted.

• ShouldSerializeTables - Gets a value indicating whether Tables property should be persisted.

• ToString - Returns a String containing the name of the Component, if any. This method should not be overridden. (Inherited from MarshalByValueComponent.)

• WriteXml(Stream) - Writes the current data for the DataSet using the specified System.IO.Stream.

• WriteXml(String) - Writes the current data for the DataSet to the specified file.

• WriteXml(TextWriter) - Writes the current data for the DataSet using the specified TextWriter.

• WriteXml(XmlWriter) - Writes the current data for the DataSet to the specified XmlWriter.

• WriteXml(Stream, XmlWriteMode) - Writes the current data, and optionally the schema, for the DataSet using the specified System.IO.Stream and XmlWriteMode. To write the schema, set the value for the mode parameter to WriteSchema.

• WriteXml(String, XmlWriteMode) - Writes the current data, and optionally the schema, for the DataSet to the specified file using the specified XmlWriteMode. To write the schema, set the value for the mode parameter to WriteSchema.

• WriteXml(TextWriter, XmlWriteMode) - Writes the current data, and optionally the schema, for the DataSet using the specified TextWriter and XmlWriteMode. To write the schema, set the value for the mode parameter to WriteSchema.

• WriteXml(XmlWriter, XmlWriteMode) - Writes the current data, and optionally the schema, for the DataSet using the specified XmlWriter and XmlWriteMode. To write the schema, set the value for the mode parameter to WriteSchema.

• WriteXmlSchema(Stream) - Writes the DataSet structure as an XML schema to the specified System.IO.Stream object.

sheepsqueezers.com

Copyright ©2011 sheepsqueezers.com Copyright ©2011 sheepsqueezers.com

sheepsqueezers.com

DataSet

Methods (continued) • WriteXmlSchema(String) - Writes the DataSet structure as an XML schema to a file.

• WriteXmlSchema(TextWriter) - Writes the DataSet structure as an XML schema to the specified TextWriter object.

• WriteXmlSchema(XmlWriter) - Writes the DataSet structure as an XML schema to an XmlWriter object.

• WriteXmlSchema(Stream, Converter<Type, String>) - Writes the DataSet structure as an XML schema to the specified System.IO.Stream object.

• WriteXmlSchema(String, Converter<Type, String>) - Writes the DataSet structure as an XML schema to a file.

• WriteXmlSchema(TextWriter, Converter<Type, String>) - Writes the DataSet structure as an XML schema to the specified TextWriter.

• WriteXmlSchema(XmlWriter, Converter<Type, String>) - Writes the DataSet structure as an XML schema to the specified XmlWriter.

Events • Disposed - Adds an event handler to listen to the Disposed event on the component. (Inherited from

MarshalByValueComponent.)

• Initialized - Occurs after the DataSet is initialized.

• MergeFailed - Occurs when a target and source DataRow have the same primary key value, and EnforceConstraints is set to true.

As you can see, there are several XML-related methods available with this class. They allow you to save your DataSet in XML format, transport it to another location and then read in that XML data to re-create your DataSet.

If you are a SAS programmer, the DataSet you see here is NOT equivalent to a SAS dataset! The DataSet class represents one or more tables whereas a SAS

dataset represents ONLY one table!

sheepsqueezers.com

Copyright ©2011 sheepsqueezers.com Copyright ©2011 sheepsqueezers.com

sheepsqueezers.com

The System.Data Namespace

Classes

DataTableCollection

sheepsqueezers.com

Copyright ©2011 sheepsqueezers.com Copyright ©2011 sheepsqueezers.com

sheepsqueezers.com

DataTableCollection

The DataTableCollection class represents the collection of tables for the DataSet. According to Microsoft's website: The DataTableCollection contains all the DataTable objects for a particular DataSet. To access the DataTableCollection of a DataSet, use the Tables property. The DataTableCollection uses methods such as Add, Clear, and Remove to manage the items in the collection. Use the Contains method to determine whether a particular table (specified by either index or name) is in the collection. To navigate from one table to another, use the ChildRelations or ParentRelations property of the DataTable to access its collection of DataRelation objects. You can also use the Relations property to navigate through the parent/child relationships of the DataTables in a particular DataSet collection.

Properties • Count Gets the total number of elements in a collection. (Inherited from InternalDataCollectionBase.)

• IsReadOnly Gets a value that indicates whether the InternalDataCollectionBase is read-only. (Inherited from InternalDataCollectionBase.)

• IsSynchronized Gets a value that indicates whether the InternalDataCollectionBase is synchonized. (Inherited from InternalDataCollectionBase.)

• Item[Int32] Gets the DataTable object at the specified index.

• Item[String] Gets the DataTable object with the specified name.

• Item[String, String] Gets the DataTable object with the specified name in the specified namespace.

• List Gets the items of the collection as a list. (Inherited from InternalDataCollectionBase.)

• SyncRoot Gets an object that can be used to synchronize the collection. (Inherited from InternalDataCollectionBase.)

Events • CollectionChanged - Occurs after the DataTableCollection is changed because of DataTable objects being added or removed.

• CollectionChanging - Occurs while the DataTableCollection is changing because of DataTable objects being added or removed.

sheepsqueezers.com

Copyright ©2011 sheepsqueezers.com Copyright ©2011 sheepsqueezers.com

sheepsqueezers.com

DataTableCollection

Methods • Add()- Creates a new DataTable object by using a default name and adds it to the collection.

• Add(DataTable) - Adds the specified DataTable to the collection.

• Add(String) - Creates a DataTable object by using the specified name and adds it to the collection.

• Add(String, String) - Creates a DataTable object by using the specified name and adds it to the collection.

• AddRange - Copies the elements of the specified DataTable array to the end of the collection.

• CanRemove - Verifies whether the specified DataTable object can be removed from the collection.

• Clear - Clears the collection of all DataTable objects.

• Contains(String) - Gets a value that indicates whether a DataTable object with the specified name exists in the collection.

• Contains(String, String) - Gets a value that indicates whether a DataTable object with the specified name and table namespace exists in the collection.

• CopyTo(Array, Int32) - Copies all the elements of the current InternalDataCollectionBase to a one-dimensional Array, starting at the specified InternalDataCollectionBase index. (Inherited from InternalDataCollectionBase.)

• CopyTo(DataTable[], Int32) - Copies all the elements of the current DataTableCollection to a one-dimensional Array, starting at the specified destination array index.

• Equals(Object) - Determines whether the specified Object is equal to the current Object. (Inherited from Object.)

• Finalize - Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)

• GetEnumerator - Gets an IEnumerator for the collection. (Inherited from InternalDataCollectionBase.)

• GetHashCode - Serves as a hash function for a particular type. (Inherited from Object.)

• GetType - Gets the Type of the current instance. (Inherited from Object.)

• IndexOf(DataTable) - Gets the index of the specified DataTable object.

• IndexOf(String) - Gets the index in the collection of the DataTable object with the specified name.

• IndexOf(String, String) - Gets the index in the collection of the specified DataTable object.

• MemberwiseClone - Creates a shallow copy of the current Object. (Inherited from Object.)

• Remove(DataTable) - Removes the specified DataTable object from the collection.

• Remove(String) - Removes the DataTable object with the specified name from the collection.

• Remove(String, String) - Removes the DataTable object with the specified name from the collection.

• RemoveAt - Removes the DataTable object at the specified index from the collection.

• ToString - Returns a string that represents the current object. (Inherited from Object.)

sheepsqueezers.com

Copyright ©2011 sheepsqueezers.com Copyright ©2011 sheepsqueezers.com

sheepsqueezers.com

DataTableCollection

Note that the DataSet class has the Tables property which returns a DataTableCollection. Once you have this, you can then use the Add method of the DataTableCollection class to add blank tables to the dataset.

sheepsqueezers.com

Copyright ©2011 sheepsqueezers.com Copyright ©2011 sheepsqueezers.com

sheepsqueezers.com

The System.Data Namespace

Classes

DataTable

sheepsqueezers.com

Copyright ©2011 sheepsqueezers.com Copyright ©2011 sheepsqueezers.com

sheepsqueezers.com

DataTable

The DataTable class represents one table of in-memory data.

Constructors • DataTable() - Initializes a new instance of the DataTable class with no arguments.

• DataTable(String) - Initializes a new instance of the DataTable class with the specified table name.

• DataTable(SerializationInfo, StreamingContext) - Initializes a new instance of the DataTable class with the SerializationInfo and the StreamingContext.

• DataTable(String, String) - Initializes a new instance of the DataTable class using the specified table name and namespace.

Properties • CaseSensitive - Indicates whether string comparisons within the table are case-sensitive.

• ChildRelations - Gets the collection of child relations for this DataTable.

• Columns - Gets the collection of columns that belong to this table.

• Constraints - Gets the collection of constraints maintained by this table.

• Container - Gets the container for the component. (Inherited from MarshalByValueComponent.)

• DataSet - Gets the DataSet to which this table belongs.

• DefaultView - Gets a customized view of the table that may include a filtered view, or a cursor position.

• DesignMode - Gets a value indicating whether the component is currently in design mode. (Inherited from MarshalByValueComponent.)

• DisplayExpression - Gets or sets the expression that returns a value used to represent this table in the user interface. The DisplayExpression property lets you display the name of this table in a user interface.

• Events - Gets the list of event handlers that are attached to this component. (Inherited from MarshalByValueComponent.)

• ExtendedProperties - Gets the collection of customized user information.

• HasErrors - Gets a value indicating whether there are errors in any of the rows in any of the tables of the DataSet to which the table belongs.

• IsInitialized - Gets a value that indicates whether the DataTable is initialized.

• Locale - Gets or sets the locale information used to compare strings within the table.

• MinimumCapacity - Gets or sets the initial starting size for this table.

• Namespace - Gets or sets the namespace for the XML representation of the data stored in the DataTable.

• ParentRelations - Gets the collection of parent relations for this DataTable.

• Prefix - Gets or sets the namespace for the XML representation of the data stored in the DataTable.

• PrimaryKey - Gets or sets an array of columns that function as primary keys for the data table.

sheepsqueezers.com

Copyright ©2011 sheepsqueezers.com Copyright ©2011 sheepsqueezers.com

sheepsqueezers.com

DataTable

Properties (continued) • RemotingFormat - Gets or sets the serialization format.

• Rows - Gets the collection of rows that belong to this table.

• Site - Gets or sets an System.ComponentModel.ISite for the DataTable. (Overrides MarshalByValueComponent.Site.)

• TableName - Gets or sets the name of the DataTable.

Methods • AcceptChanges - Commits all the changes made to this table since the last time AcceptChanges was called.

• BeginInit - Begins the initialization of a DataTable that is used on a form or used by another component. The initialization occurs at run time.

• BeginLoadData - Turns off notifications, index maintenance, and constraints while loading data.

• Clear - Clears the DataTable of all data.

• Clone - Clones the structure of the DataTable, including all DataTable schemas and constraints.

• Compute - Computes the given expression on the current rows that pass the filter criteria.

• Copy - Copies both the structure and data for this DataTable.

• CreateDataReader - Returns a DataTableReader corresponding to the data within this DataTable.

• CreateInstance - Infrastructure. Creates a new instance of DataTable.

• Dispose() - Releases all resources used by the MarshalByValueComponent. (Inherited from MarshalByValueComponent.)

• Dispose(Boolean) - Releases the unmanaged resources used by the MarshalByValueComponent and optionally releases the managed resources. (Inherited from MarshalByValueComponent.)

• EndInit - Ends the initialization of a DataTable that is used on a form or used by another component. The initialization occurs at run time.

• EndLoadData - Turns on notifications, index maintenance, and constraints after loading data.

• Equals(Object) - Determines whether the specified Object is equal to the current Object. (Inherited from Object.)

• Finalize - Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from MarshalByValueComponent.)

• GetChanges() - Gets a copy of the DataTable that contains all changes made to it since it was loaded or AcceptChanges was last called.

• GetChanges(DataRowState) - Gets a copy of the DataTable containing all changes made to it since it was last loaded, or since AcceptChanges was called, filtered by DataRowState.

• GetDataTableSchema - This method returns an XmlSchemaSet instance containing the Web Services Description Language (WSDL) that describes the DataTable for Web Services.

sheepsqueezers.com

Copyright ©2011 sheepsqueezers.com Copyright ©2011 sheepsqueezers.com

sheepsqueezers.com

DataTable

Methods (continued) • GetErrors - Gets an array of DataRow objects that contain errors.

• GetHashCode - Serves as a hash function for a particular type. (Inherited from Object.)

• GetObjectData - Populates a serialization information object with the data needed to serialize the DataTable.

• GetRowType - Infrastructure. Gets the row type.

• GetSchema - Infrastructure. For a description of this member, see IXmlSerializable.GetSchema.

• GetService - Gets the implementer of the IServiceProvider. (Inherited from MarshalByValueComponent.)

• GetType - Gets the Type of the current instance. (Inherited from Object.)

• ImportRow - Copies a DataRow into a DataTable, preserving any property settings, as well as original and current values.

• Load(IDataReader) - Fills a DataTable with values from a data source using the supplied IDataReader. If the DataTable already contains rows, the incoming data from the data source is merged with the existing rows.

• Load(IDataReader, LoadOption) - Fills a DataTable with values from a data source using the supplied IDataReader. If the DataTable already contains rows, the incoming data from the data source is merged with the existing rows according to the value of the loadOption parameter.

• Load(IDataReader, LoadOption, FillErrorEventHandler) - Fills a DataTable with values from a data source using the supplied IDataReader using an error-handling delegate.

• LoadDataRow(Object[], Boolean) - Finds and updates a specific row. If no matching row is found, a new row is created using the given values.

• LoadDataRow(Object[], LoadOption) - Finds and updates a specific row. If no matching row is found, a new row is created using the given values.

• MemberwiseClone - Creates a shallow copy of the current Object. (Inherited from Object.)

• Merge(DataTable) - Merge the specified DataTable with the current DataTable.

• Merge(DataTable, Boolean) - Merge the specified DataTable with the current DataTable, indicating whether to preserve changes in the current DataTable.

• Merge(DataTable, Boolean, MissingSchemaAction) - Merge the specified DataTable with the current DataTable, indicating whether to preserve changes and how to handle missing schema in the current DataTable.

• NewRow - Creates a new DataRow with the same schema as the table.

• NewRowArray - Infrastructure. Returns an array of DataRow.

• NewRowFromBuilder - Creates a new row from an existing row.

• OnColumnChanged - Raises the ColumnChanged event.

• OnColumnChanging - Raises the ColumnChanging event.

• OnPropertyChanging - Raises the PropertyChanged event.

• OnRemoveColumn - Notifies the DataTable that a DataColumn is being removed.

• OnRowChanged - Raises the RowChanged event.

sheepsqueezers.com

Copyright ©2011 sheepsqueezers.com Copyright ©2011 sheepsqueezers.com

sheepsqueezers.com

DataTable

Methods (continued) • OnRowChanging - Raises the RowChanging event.

• OnRowDeleted - Raises the RowDeleted event.

• OnRowDeleting - Raises the RowDeleting event.

• OnTableCleared - Raises the TableCleared event.

• OnTableClearing - Raises the TableClearing event.

• OnTableNewRow - Raises the TableNewRow event.

• ReadXml(Stream) - Reads XML schema and data into the DataTable using the specified Stream.

• ReadXml(String) - Reads XML schema and data into the DataTable from the specified file.

• ReadXml(TextReader) - Reads XML schema and data into the DataTable using the specified TextReader.

• ReadXml(XmlReader) - Reads XML Schema and Data into the DataTable using the specified XmlReader.

• ReadXmlSchema(Stream) - Reads an XML schema into the DataTable using the specified stream.

• ReadXmlSchema(String) - Reads an XML schema into the DataTable from the specified file.

• ReadXmlSchema(TextReader) - Reads an XML schema into the DataTable using the specified TextReader.

• ReadXmlSchema(XmlReader) - Reads an XML schema into the DataTable using the specified XmlReader.

• ReadXmlSerializable - Infrastructure. Reads from an XML stream.

• RejectChanges - Rolls back all changes that have been made to the table since it was loaded, or the last time AcceptChanges was called.

• Reset - Resets the DataTable to its original state.

• Select() - Gets an array of all DataRow objects.

• Select(String) - Gets an array of all DataRow objects that match the filter criteria in order of primary key (or lacking one, order of addition.)

• Select(String, String) - Gets an array of all DataRow objects that match the filter criteria, in the specified sort order.

• Select(String, String, DataViewRowState) - Gets an array of all DataRow objects that match the filter in the order of the sort that match the specified state.

• ToString - Gets the TableName and DisplayExpression, if there is one as a concatenated string. (Overrides MarshalByValueComponent.ToString().)

• WriteXml(Stream) - Writes the current contents of the DataTable as XML using the specified Stream.

• WriteXml(String) - Writes the current contents of the DataTable as XML using the specified file.

• WriteXml(TextWriter) - Writes the current contents of the DataTable as XML using the specified TextWriter.

• WriteXml(XmlWriter) - Writes the current contents of the DataTable as XML using the specified XmlWriter.

• WriteXml(Stream, Boolean) - Writes the current contents of the DataTable as XML using the specified Stream. To save the data for the table and all its descendants, set the writeHierarchy parameter to true.

sheepsqueezers.com

Copyright ©2011 sheepsqueezers.com Copyright ©2011 sheepsqueezers.com

sheepsqueezers.com

DataTable

Methods (continued) • WriteXml(Stream, XmlWriteMode) - Writes the current data, and optionally the schema, for the DataTable to the specified file

using the specified XmlWriteMode. To write the schema, set the value for the mode parameter to WriteSchema.

• WriteXml(String, Boolean) - Writes the current contents of the DataTable as XML using the specified file. To save the data for the table and all its descendants, set the writeHierarchy parameter to true.

• WriteXml(String, XmlWriteMode) - Writes the current data, and optionally the schema, for the DataTable using the specified file and XmlWriteMode. To write the schema, set the value for the mode parameter to WriteSchema.

• WriteXml(TextWriter, Boolean) - Writes the current contents of the DataTable as XML using the specified TextWriter. To save the data for the table and all its descendants, set the writeHierarchy parameter to true.

• WriteXml(TextWriter, XmlWriteMode) - Writes the current data, and optionally the schema, for the DataTable using the specified TextWriter and XmlWriteMode. To write the schema, set the value for the mode parameter to WriteSchema.

• WriteXml(XmlWriter, Boolean) - Writes the current contents of the DataTable as XML using the specified XmlWriter.

• WriteXml(XmlWriter, XmlWriteMode) - Writes the current data, and optionally the schema, for the DataTable using the specified XmlWriter and XmlWriteMode. To write the schema, set the value for the mode parameter to WriteSchema.

• WriteXml(Stream, XmlWriteMode, Boolean) - Writes the current data, and optionally the schema, for the DataTable to the specified file using the specified XmlWriteMode. To write the schema, set the value for the mode parameter to WriteSchema. To save the data for the table and all its descendants, set the writeHierarchy parameter to true.

• WriteXml(String, XmlWriteMode, Boolean) - Writes the current data, and optionally the schema, for the DataTable using the specified file and XmlWriteMode. To write the schema, set the value for the mode parameter to WriteSchema. To save the data for the table and all its descendants, set the writeHierarchy parameter to true.

• WriteXml(TextWriter, XmlWriteMode, Boolean) - Writes the current data, and optionally the schema, for the DataTable using the specified TextWriter and XmlWriteMode. To write the schema, set the value for the mode parameter to WriteSchema. To save the data for the table and all its descendants, set the writeHierarchy parameter to true.

• WriteXml(XmlWriter, XmlWriteMode, Boolean) - Writes the current data, and optionally the schema, for the DataTable using the specified XmlWriter and XmlWriteMode. To write the schema, set the value for the mode parameter to WriteSchema. To save the data for the table and all its descendants, set the writeHierarchy parameter to true.

• WriteXmlSchema(Stream) - Writes the current data structure of the DataTable as an XML schema to the specified stream.

• WriteXmlSchema(String) - Writes the current data structure of the DataTable as an XML schema to the specified file.

• WriteXmlSchema(TextWriter) - Writes the current data structure of the DataTable as an XML schema using the specified TextWriter.

• WriteXmlSchema(XmlWriter) - Writes the current data structure of the DataTable as an XML schema using the specified XmlWriter.

• WriteXmlSchema(Stream, Boolean) - Writes the current data structure of the DataTable as an XML schema to the specified stream. To save the schema for the table and all its descendants, set the writeHierarchy parameter to true.

sheepsqueezers.com

Copyright ©2011 sheepsqueezers.com Copyright ©2011 sheepsqueezers.com

sheepsqueezers.com

DataTable

Methods (continued) • WriteXmlSchema(String, Boolean) - Writes the current data structure of the DataTable as an XML schema to the specified file.

To save the schema for the table and all its descendants, set the writeHierarchy parameter to true.

• WriteXmlSchema(TextWriter, Boolean) - Writes the current data structure of the DataTable as an XML schema using the specified TextWriter. To save the schema for the table and all its descendants, set the writeHierarchy parameter to true.

• WriteXmlSchema(XmlWriter, Boolean) - Writes the current data structure of the DataTable as an XML schema using the specified XmlWriter. To save the schema for the table and all its descendants, set the writeHierarchy parameter to true.

Events • ColumnChanged - Occurs after a value has been changed for the specified DataColumn in a DataRow.

• ColumnChanging - Occurs when a value is being changed for the specified DataColumn in a DataRow.

• Disposed - Adds an event handler to listen to the Disposed event on the component. (Inherited from MarshalByValueComponent.)

• Initialized - Occurs after the DataTable is initialized.

• RowChanged - Occurs after a DataRow has been changed successfully.

• RowChanging - Occurs when a DataRow is changing.

• RowDeleted - Occurs after a row in the table has been deleted.

• RowDeleting - Occurs before a row in the table is about to be deleted.

• TableCleared - Occurs after a DataTable is cleared.

• TableClearing - Occurs when a DataTable is cleared.

• TableNewRow - Occurs when a new DataRow is inserted.

Now, you can create a new DataTable with the provided constructors, but to get the table into the DataSet, use the DataTableCollection's Add method.

sheepsqueezers.com

Copyright ©2011 sheepsqueezers.com Copyright ©2011 sheepsqueezers.com

sheepsqueezers.com

The System.Data Namespace

Classes

DataColumnCollection

sheepsqueezers.com

Copyright ©2011 sheepsqueezers.com Copyright ©2011 sheepsqueezers.com

sheepsqueezers.com

DataColumnCollection

The DataColumnCollection class represents represents a collection of

DataColumn objects for a DataTable. According to Microsoft's website: The DataColumnCollection defines the schema of a DataTable, and determines what kind of data each DataColumn can contain. You can access the DataColumnCollection through the Columns property of the DataTable object. The DataColumnCollection uses the Add and Remove methods to insert and delete DataColumn objects. Use the Count property to determine how many DataColumn objects are in the collection. Use the Contains method to verify whether a specified index or column name exists in the collection.

Properties • Count - Gets the total number of elements in a collection. (Inherited from InternalDataCollectionBase.)

• IsReadOnly - Gets a value that indicates whether the InternalDataCollectionBase is read-only. (Inherited from InternalDataCollectionBase.)

• IsSynchronized - Gets a value that indicates whether the InternalDataCollectionBase is synchonized. (Inherited from InternalDataCollectionBase.)

• Item[Int32] - Gets the DataColumn from the collection at the specified index.

• Item[String] - Gets the DataColumn from the collection with the specified name.

• List - Gets the items of the collection as a list. (Inherited from InternalDataCollectionBase.)

• SyncRoot - Gets an object that can be used to synchronize the collection. (Inherited from InternalDataCollectionBase.)

Methods • Add() - Creates and adds a DataColumn object to the DataColumnCollection.

• Add(DataColumn) - Creates and adds the specified DataColumn object to the DataColumnCollection.

• Add(String) - Creates and adds a DataColumn object that has the specified name to the DataColumnCollection.

• Add(String, Type) - Creates and adds a DataColumn object that has the specified name and type to the DataColumnCollection.

• Add(String, Type, String) - Creates and adds a DataColumn object that has the specified name, type, and expression to the DataColumnCollection.

sheepsqueezers.com

Copyright ©2011 sheepsqueezers.com Copyright ©2011 sheepsqueezers.com

sheepsqueezers.com

DataColumnCollection

Methods (continued) • AddRange - Copies the elements of the specified DataColumn array to the end of the collection.

• CanRemove - Checks whether a specific column can be removed from the collection.

• Clear - Clears the collection of any columns.

• Contains - Checks whether the collection contains a column with the specified name.

• CopyTo(Array, Int32) - Copies all the elements of the current InternalDataCollectionBase to a one-dimensional Array, starting at the specified InternalDataCollectionBase index. (Inherited from InternalDataCollectionBase.)

• CopyTo(DataColumn[], Int32) - Copies the entire collection into an existing array, starting at a specified index within the array.

• Equals(Object) - Determines whether the specified Object is equal to the current Object. (Inherited from Object.)

• Finalize - Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)

• GetEnumerator - Gets an IEnumerator for the collection. (Inherited from InternalDataCollectionBase.)

• GetHashCode - Serves as a hash function for a particular type. (Inherited from Object.)

• GetType - Gets the Type of the current instance. (Inherited from Object.)

• IndexOf(DataColumn) - Gets the index of a column specified by name.

• IndexOf(String) - Gets the index of the column with the specific name (the name is not case sensitive).

• MemberwiseClone - Creates a shallow copy of the current Object. (Inherited from Object.)

• Remove(DataColumn) - Removes the specified DataColumn object from the collection.

• Remove(String) - Removes the DataColumn object that has the specified name from the collection.

• RemoveAt - Removes the column at the specified index from the collection.

• ToString - Returns a string that represents the current object. (Inherited from Object.)

Events • CollectionChanged - Occurs when the columns collection changes, either by adding or removing a column.

In a similar way that the DataTableCollection class represents a set of DataTables, the DataColumnCollection represents a set of columns within each table.

sheepsqueezers.com

Copyright ©2011 sheepsqueezers.com Copyright ©2011 sheepsqueezers.com

sheepsqueezers.com

The System.Data Namespace

Classes

DataColumn

sheepsqueezers.com

Copyright ©2011 sheepsqueezers.com Copyright ©2011 sheepsqueezers.com

sheepsqueezers.com

DataColumn

The DataColumn class represents the schema of a column in a DataTable.

According to Microsoft's website: The DataColumn is the fundamental building block for creating the schema of a DataTable. You build the schema by adding one or more DataColumn objects to the DataColumnCollection. Each DataColumn has a DataType property that determines the kind of data the DataColumn contains. For example, you can restrict the data type to integers, or strings, or decimals. Because data that is contained by the DataTable is typically merged back into its original data source, you must match the data types to those in the data source. For more information, see Data Type Mappings in ADO.NET. Properties such as AllowDBNull, Unique, and ReadOnly put restrictions on the entry and updating of data, thereby helping to guarantee data integrity. You can also use the AutoIncrement, AutoIncrementSeed, and AutoIncrementStep properties to control automatic data generation. For more information about AutoIncrement columns, see Creating AutoIncrement Columns (ADO.NET). For more information, see Defining Primary Keys (ADO.NET). You can also make sure that values in a DataColumn are unique by creating a UniqueConstraint and adding it to the ConstraintCollection of the DataTable to which the DataColumn belongs. For more information, see DataTable Constraints (ADO.NET). To create a relation between DataColumn objects, create a DataRelation object and add it to the DataRelationCollection of a DataSet. You can use the Expression property of the DataColumn object to calculate the values in a column, or create an aggregate column.

sheepsqueezers.com

Copyright ©2011 sheepsqueezers.com Copyright ©2011 sheepsqueezers.com

sheepsqueezers.com

DataColumn

Constructors • DataColumn() - Initializes a new instance of a DataColumn class as type string.

• DataColumn(String) - Inititalizes a new instance of the DataColumn class, as type string, using the specified column name.

• DataColumn(String, Type) - Inititalizes a new instance of the DataColumn class using the specified column name and data type.

• DataColumn(String, Type, String) - Initializes a new instance of the DataColumn class using the specified name, data type, and expression.

• DataColumn(String, Type, String, MappingType) - Initializes a new instance of the DataColumn class using the specified name, data type, expression, and value that determines whether the column is an attribute.

Properties • AllowDBNull - Gets or sets a value that indicates whether null values are allowed in this column for rows that belong to the

table.

• AutoIncrement - Gets or sets a value that indicates whether the column automatically increments the value of the column for new rows added to the table.

• AutoIncrementSeed - Gets or sets the starting value for a column that has its AutoIncrement property set to true.

• AutoIncrementStep - Gets or sets the increment used by a column with its AutoIncrement property set to true.

• Caption - Gets or sets the caption for the column.

• ColumnMapping - Gets or sets the MappingType of the column.

• ColumnName - Gets or sets the name of the column in the DataColumnCollection.

• Container - Gets the container for the component. (Inherited from MarshalByValueComponent.)

• DataType - Gets or sets the type of data stored in the column.

• DateTimeMode - Gets or sets the DateTimeMode for the column.

• DefaultValue - Gets or sets the default value for the column when you are creating new rows.

• DesignMode - Gets a value indicating whether the component is currently in design mode. (Inherited from MarshalByValueComponent.)

• Events - Gets the list of event handlers that are attached to this component. (Inherited from MarshalByValueComponent.)

• Expression - Gets or sets the expression used to filter rows, calculate the values in a column, or create an aggregate column.

• ExtendedProperties - Gets the collection of custom user information associated with a DataColumn.

• MaxLength - Gets or sets the maximum length of a text column.

• Namespace - Gets or sets the namespace of the DataColumn.

• Ordinal - Gets the position of the column in the DataColumnCollection collection.

sheepsqueezers.com

Copyright ©2011 sheepsqueezers.com Copyright ©2011 sheepsqueezers.com

sheepsqueezers.com

DataColumn

Properties (continued) • Prefix - Gets or sets an XML prefix that aliases the namespace of the DataTable.

• ReadOnly - Gets or sets a value that indicates whether the column allows for changes as soon as a row has been added to the table.

• Site - Gets or sets the site of the component. (Inherited from MarshalByValueComponent.)

• Table - Gets the DataTable to which the column belongs to.

• Unique - Gets or sets a value that indicates whether the values in each row of the column must be unique.

Methods • CheckNotAllowNull - Infrastructure. This member supports the .NET Framework infrastructure and is not intended to be used

directly from your code.

• CheckUnique - Infrastructure. This member supports the .NET Framework infrastructure and is not intended to be used directly from your code.

• Dispose() - Releases all resources used by the MarshalByValueComponent. (Inherited from MarshalByValueComponent.)

• Dispose(Boolean) - Releases the unmanaged resources used by the MarshalByValueComponent and optionally releases the managed resources. (Inherited from MarshalByValueComponent.)

• Equals(Object) - Determines whether the specified Object is equal to the current Object. (Inherited from Object.)

• Finalize - Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from MarshalByValueComponent.)

• GetHashCode - Serves as a hash function for a particular type. (Inherited from Object.)

• GetService - Gets the implementer of the IServiceProvider. (Inherited from MarshalByValueComponent.)

• GetType - Gets the Type of the current instance. (Inherited from Object.)

• MemberwiseClone - Creates a shallow copy of the current Object. (Inherited from Object.)

• OnPropertyChanging - This member supports the .NET Framework infrastructure and is not intended to be used directly from your code.

• RaisePropertyChanging - This member supports the .NET Framework infrastructure and is not intended to be used directly from your code.

• SetOrdinal - Changes the ordinal or position of the DataColumn to the specified ordinal or position.

• ToString - Gets the Expression of the column, if one exists. (Overrides MarshalByValueComponent.ToString().)

Events • Disposed - Adds an event handler to listen to the Disposed event on the component. (Inherited from

MarshalByValueComponent.)

sheepsqueezers.com

Copyright ©2011 sheepsqueezers.com Copyright ©2011 sheepsqueezers.com

sheepsqueezers.com

DataColumn

Note that the DataColumnCollection property Column returns a DataColumnCollection which allows you to use the Add method to add your

new column.

in order to add a DataColumn to a DataTable, you can instantiate an object using one of the DataColumn constructors listed above and then add that column

to the table. In order to specify the data type of the column, you will have to use the System.Type.GetType() method passing it the type that you want your column to have, such as System.Int32, System.String, System.Double, etc.

Note that you can compute column values by using the DataColumn.Expression

property. In the big example above, I compute the Body Mass Index (BMI) as 703*Weight/(Height*Height).

sheepsqueezers.com

Copyright ©2011 sheepsqueezers.com Copyright ©2011 sheepsqueezers.com

sheepsqueezers.com

The System.Data Namespace

Classes

ConstraintCollection

sheepsqueezers.com

Copyright ©2011 sheepsqueezers.com Copyright ©2011 sheepsqueezers.com

sheepsqueezers.com

ConstraintCollection

The ConstraintCollection class represents a collection of constraints for a

DataTable. According to Microsoft's website: The ConstraintCollection is accessed through the DataTable.Constraints property. The ConstraintCollection can contain both UniqueConstraint and ForeignKeyConstraint objects for the DataTable. A UniqueConstraint object makes sure that data in a specific column is always unique to preserve the data integrity. The ForeignKeyConstraint determines what will occur in related tables when data in the DataTable is either updated or deleted. For example, if a row is deleted, the ForeignKeyConstraint will determine whether the related rows are also deleted (a cascade), or some other course of action.

Properties • Count - Gets the total number of elements in a collection. (Inherited from InternalDataCollectionBase.)

• IsReadOnly - Gets a value that indicates whether the InternalDataCollectionBase is read-only. (Inherited from InternalDataCollectionBase.)

• IsSynchronized - Gets a value that indicates whether the InternalDataCollectionBase is synchonized. (Inherited from InternalDataCollectionBase.)

• Item[Int32] - Gets the Constraint from the collection at the specified index.

• Item[String] - Gets the Constraint from the collection with the specified name.

• List - Gets the items of the collection as a list. (Inherited from InternalDataCollectionBase.)

• SyncRoot - Gets an object that can be used to synchronize the collection. (Inherited from InternalDataCollectionBase.)

Methods • Add(Constraint) - Adds the specified Constraint object to the collection.

• Add(String, DataColumn, Boolean) - Constructs a new UniqueConstraint with the specified name, DataColumn, and value that indicates whether the column is a primary key, and adds it to the collection.

• Add(String, DataColumn, DataColumn) - Constructs a new ForeignKeyConstraint with the specified name, parent column, and child column, and adds the constraint to the collection.

• Add(String, DataColumn[], Boolean) - Constructs a new UniqueConstraint with the specified name, array of DataColumn objects, and value that indicates whether the column is a primary key, and adds it to the collection.

• Add(String, DataColumn[], DataColumn[]) - Constructs a new ForeignKeyConstraint, with the specified arrays of parent columns and child columns, and adds the constraint to the collection.

sheepsqueezers.com

Copyright ©2011 sheepsqueezers.com Copyright ©2011 sheepsqueezers.com

sheepsqueezers.com

ConstraintCollection

Methods • AddRange - Copies the elements of the specified ConstraintCollection array to the end of the collection.

• CanRemove - Indicates whether a Constraint can be removed.

• Clear - Clears the collection of any Constraint objects.

• Contains - Indicates whether the Constraint object specified by name exists in the collection.

• CopyTo(Array, Int32) - Copies all the elements of the current InternalDataCollectionBase to a one-dimensional Array, starting at the specified InternalDataCollectionBase index. (Inherited from InternalDataCollectionBase.)

• CopyTo(Constraint[], Int32) - Copies the collection objects to a one-dimensional Array instance starting at the specified index.

• Equals(Object) - Determines whether the specified Object is equal to the current Object. (Inherited from Object.)

• Finalize - Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)

• GetEnumerator - Gets an IEnumerator for the collection. (Inherited from InternalDataCollectionBase.)

• GetHashCode - Serves as a hash function for a particular type. (Inherited from Object.)

• GetType - Gets the Type of the current instance. (Inherited from Object.)

• IndexOf(Constraint) - Gets the index of the specified Constraint.

• IndexOf(String) - Gets the index of the Constraint specified by name.

• MemberwiseClone - Creates a shallow copy of the current Object. (Inherited from Object.)

• Remove(Constraint) - Removes the specified Constraint from the collection.

• Remove(String) - Removes the Constraint object specified by name from the collection.

• RemoveAt - Removes the Constraint object at the specified index from the collection.

• ToString - Returns a string that represents the current object. (Inherited from Object.)

Events • CollectionChanged - Occurs whenever the ConstraintCollection is changed because of Constraint objects being added or

removed.

Similar to the other collection classes, this class holds the constraints (one or more) for each of your tables.

sheepsqueezers.com

Copyright ©2011 sheepsqueezers.com Copyright ©2011 sheepsqueezers.com

sheepsqueezers.com

The System.Data Namespace

Classes

Constraint

ForeignKeyConstraint

UniqueConstraint

sheepsqueezers.com

Copyright ©2011 sheepsqueezers.com Copyright ©2011 sheepsqueezers.com

sheepsqueezers.com

Constraint, ForeignKeyConstraint, UniqueConstraint

The Contraint class represents a constraint that can be enforced on one or more DataColumn objects. According to Microsoft's website: A constraint is a

rule used to maintain the integrity of the data in the DataTable. For example, when you delete a value that is used in one or more related tables, a ForeignKeyConstraint determines whether the values in the related tables are also deleted, set to null values, set to default values, or whether no action occurs. A UniqueConstraint, on the other hand, just makes sure that all values within a particular table are unique.

Constructors • Constraint - Initializes a new instance of the Constraint class.

Properties • _DataSet - Infrastructure. Gets the DataSet to which this constraint belongs.

• ConstraintName - The name of a constraint in the ConstraintCollection.

• ExtendedProperties - Gets the collection of user-defined constraint properties.

• Table - Gets the DataTable to which the constraint applies.

Methods • CheckStateForProperty - Infrastructure. Gets the DataSet to which this constraint belongs.

• Equals(Object) - Determines whether the specified Object is equal to the current Object. (Inherited from Object.)

• Finalize - Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)

• GetHashCode - Serves as a hash function for a particular type. (Inherited from Object.)

• GetType - Gets the Type of the current instance. (Inherited from Object.)

• MemberwiseClone - Creates a shallow copy of the current Object. (Inherited from Object.)

• SetDataSet - Sets the constraint's DataSet.

• ToString - Gets the ConstraintName, if there is one, as a string. (Overrides Object.ToString.)

sheepsqueezers.com

Copyright ©2011 sheepsqueezers.com Copyright ©2011 sheepsqueezers.com

sheepsqueezers.com

Constraint

Now, there are two classes that derive from the Constraint class: ForeignKeyConstraint and UniqueConstraint.

A foreign key constraint represents an action restriction enforced on a set of columns in a primary key/foreign key relationship when a value or row is either deleted or updated.

A unique constraint represents a restriction on a set of columns in which all values must be unique. Note that a unique constraint is added when the Unique

property of the column is set to true.

In order to add a constraint, you must first instantiate the constraint. Then, you must obtain the ConstraintCollection for the table using the Constraints property and then you can use the Add method to add in your new constraint.

Now, in order to create a primary key constraint (and you'll notice that there is no primary key constraint class!), you must use the table's PrimaryKey property.

Note that you should add your constraints AFTER you have added your data rows to your tables!

See Microsoft's website for more on the ForeignKeyConstaint and UniqueConstraint classes.

sheepsqueezers.com

Copyright ©2011 sheepsqueezers.com Copyright ©2011 sheepsqueezers.com

sheepsqueezers.com

The System.Data Namespace

Classes

DataRowCollection

sheepsqueezers.com

Copyright ©2011 sheepsqueezers.com Copyright ©2011 sheepsqueezers.com

sheepsqueezers.com

DataRowCollection

The DataRowCollection class represents a collection of rows for a DataTable.

According to Microsoft's website: The DataRowCollection is a major component of the DataTable. While the DataColumnCollection defines the schema of the table, the DataRowCollection contains the actual data for the table, where each DataRow in the DataRowCollection represents a single row. You can call the Add and Remove methods to insert and delete DataRow objects from the DataRowCollection. You can also call the Find method to search for DataRow objects that contain specific values in primary key columns, and the Contains method to search character-based data for single words or phrases.

Properties • Count - Gets the total number of DataRow objects in this collection. (Overrides InternalDataCollectionBase.Count.)

• IsReadOnly - Gets a value that indicates whether the InternalDataCollectionBase is read-only. (Inherited from InternalDataCollectionBase.)

• IsSynchronized - Gets a value that indicates whether the InternalDataCollectionBase is synchonized. (Inherited from InternalDataCollectionBase.)

• Item - Gets the row at the specified index.

• List - Gets the items of the collection as a list. (Inherited from InternalDataCollectionBase.)

• SyncRoot - Gets an object that can be used to synchronize the collection. (Inherited from InternalDataCollectionBase.)

Methods • Add(DataRow) - Adds the specified DataRow to the DataRowCollection object.

• Add(Object[]) - Creates a row using specified values and adds it to the DataRowCollection.

• Clear - Clears the collection of all rows.

• Contains(Object) - Gets a value that indicates whether the primary key of any row in the collection contains the specified value.

• Contains(Object[]) - Gets a value that indicates whether the primary key columns of any row in the collection contain the values specified in the object array.

sheepsqueezers.com

Copyright ©2011 sheepsqueezers.com Copyright ©2011 sheepsqueezers.com

sheepsqueezers.com

DataRowCollection

Methods (continued) • CopyTo(Array, Int32) - Copies all the DataRow objects from the collection into the given array, starting at the given

destination array index. (Overrides InternalDataCollectionBase.CopyTo(Array, Int32).)

• CopyTo(DataRow[], Int32) - Copies all the DataRow objects from the collection into the given array, starting at the given destination array index.

• Equals(Object) - Determines whether the specified Object is equal to the current Object. (Inherited from Object.)

• Finalize - Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)

• Find(Object) - Gets the row specified by the primary key value.

• Find(Object[]) - Gets the row that contains the specified primary key values.

• GetEnumerator - Gets an IEnumerator for this collection. (Overrides InternalDataCollectionBase.GetEnumerator().)

• GetHashCode - Serves as a hash function for a particular type. (Inherited from Object.)

• GetType - Gets the Type of the current instance. (Inherited from Object.)

• IndexOf - Gets the index of the specified DataRow object.

• InsertAt - Inserts a new row into the collection at the specified location.

• MemberwiseClone - Creates a shallow copy of the current Object. (Inherited from Object.)

• Remove - Removes the specified DataRow from the collection.

• RemoveAt - Removes the row at the specified index from the collection.

• ToString - Returns a string that represents the current object. (Inherited from Object.)

sheepsqueezers.com

Copyright ©2011 sheepsqueezers.com Copyright ©2011 sheepsqueezers.com

sheepsqueezers.com

The System.Data Namespace

Classes

DataRow

sheepsqueezers.com

Copyright ©2011 sheepsqueezers.com Copyright ©2011 sheepsqueezers.com

sheepsqueezers.com

DataRow

The DataRow class represents a row of data in a DataTable. According to Microsoft's website: The DataRow and DataColumn objects are primary components of a DataTable. Use the DataRow object and its properties and methods to retrieve and evaluate; and insert, delete, and update the values in the DataTable. The DataRowCollection represents the actual DataRow objects in the DataTable, and the DataColumnCollection contains the DataColumn objects that describe the schema of the DataTable. Use the overloaded Item property to return or set the value of a DataColumn. Use the HasVersion and IsNull properties to determine the status of a particular row value, and the RowState property to determine the state of the row relative to its parent DataTable. To create a new DataRow, use the NewRow method of the DataTable object. After creating a new DataRow, use the Add method to add the new DataRow to the DataRowCollection. Finally, call the AcceptChanges method of the DataTable object to confirm the addition. For more information about adding data to a DataTable, see Adding Data to a DataTable. You can delete a DataRow from the DataRowCollection by calling the Remove method of the DataRowCollection, or by calling the Delete method of the DataRow object. The Remove method removes the row from the collection. In contrast, Delete marks the DataRow for removal. The actual removal occurs when you call AcceptChanges method. By calling Delete, you can programmatically check which rows are marked for removal before actually deleting them.

sheepsqueezers.com

Copyright ©2011 sheepsqueezers.com Copyright ©2011 sheepsqueezers.com

sheepsqueezers.com

DataRow

Constructors • DataRow - Infrastructure. Initializes a new instance of the DataRow. Constructs a row from the builder. Only for internal

usage.

Properties • HasErrors - Gets a value that indicates whether there are errors in a row.

• Item[DataColumn] - Gets or sets the data stored in the specified DataColumn.

• Item[Int32] - Gets or sets the data stored in the column specified by index.

• Item[String] - Gets or sets the data stored in the column specified by name.

• Item[DataColumn, DataRowVersion] - Gets the specified version of data stored in the specified DataColumn.

• Item[Int32, DataRowVersion] - Gets the data stored in the column, specified by index and version of the data to retrieve.

• Item[String, DataRowVersion] - Gets the specified version of data stored in the named column.

• ItemArray - Gets or sets all the values for this row through an array.

• RowError - Gets or sets the custom error description for a row.

• RowState - Gets the current state of the row with regard to its relationship to the DataRowCollection.

• Table - Gets the DataTable for which this row has a schema.

Methods • AcceptChanges Commits all the changes made to this row since the last time AcceptChanges was called.

• BeginEdit Starts an edit operation on a DataRow object.

• CancelEdit Cancels the current edit on the row.

• ClearErrors Clears the errors for the row. This includes the RowError and errors set with SetColumnError.

• Delete Deletes the DataRow.

• EndEdit Ends the edit occurring on the row.

• Equals(Object) Determines whether the specified Object is equal to the current Object. (Inherited from Object.)

• Finalize Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)

• GetChildRows(DataRelation) Gets the child rows of this DataRow using the specified DataRelation.

• GetChildRows(String) Gets the child rows of a DataRow using the specified RelationName of a DataRelation.

sheepsqueezers.com

Copyright ©2011 sheepsqueezers.com Copyright ©2011 sheepsqueezers.com

sheepsqueezers.com

DataRow

Methods (continued) • GetChildRows(DataRelation, DataRowVersion) Gets the child rows of a DataRow using the specified DataRelation, and

DataRowVersion.

• GetChildRows(String, DataRowVersion) Gets the child rows of a DataRow using the specified RelationName of a DataRelation, and DataRowVersion.

• GetColumnError(DataColumn) Gets the error description of the specified DataColumn.

• GetColumnError(Int32) Gets the error description for the column specified by index.

• GetColumnError(String) Gets the error description for a column, specified by name.

• GetColumnsInError Gets an array of columns that have errors.

• GetHashCode Serves as a hash function for a particular type. (Inherited from Object.)

• GetParentRow(DataRelation) Gets the parent row of a DataRow using the specified DataRelation.

• GetParentRow(String) Gets the parent row of a DataRow using the specified RelationName of a DataRelation.

• GetParentRow(DataRelation, DataRowVersion) Gets the parent row of a DataRow using the specified DataRelation, and DataRowVersion.

• GetParentRow(String, DataRowVersion) Gets the parent row of a DataRow using the specified RelationName of a DataRelation, and DataRowVersion.

• GetParentRows(DataRelation) Gets the parent rows of a DataRow using the specified DataRelation.

• GetParentRows(String) Gets the parent rows of a DataRow using the specified RelationName of a DataRelation.

• GetParentRows(DataRelation, DataRowVersion) Gets the parent rows of a DataRow using the specified DataRelation, and DataRowVersion.

• GetParentRows(String, DataRowVersion) Gets the parent rows of a DataRow using the specified RelationName of a DataRelation, and DataRowVersion.

• GetType Gets the Type of the current instance. (Inherited from Object.)

• HasVersion Gets a value that indicates whether a specified version exists.

• IsNull(DataColumn) Gets a value that indicates whether the specified DataColumn contains a null value.

• IsNull(Int32) Gets a value that indicates whether the column at the specified index contains a null value.

• IsNull(String) Gets a value that indicates whether the named column contains a null value.

• IsNull(DataColumn, DataRowVersion) Gets a value that indicates whether the specified DataColumn and DataRowVersion contains a null value.

• MemberwiseClone Creates a shallow copy of the current Object. (Inherited from Object.)

• RejectChanges Rejects all changes made to the row since AcceptChanges was last called.

• SetAdded Changes the Rowstate() of a DataRow to Added.

• SetColumnError(DataColumn, String) Sets the error description for a column specified as a DataColumn.

sheepsqueezers.com

Copyright ©2011 sheepsqueezers.com Copyright ©2011 sheepsqueezers.com

sheepsqueezers.com

DataRow

Methods (continued) • SetColumnError(Int32, String) Sets the error description for a column specified by index.

• SetColumnError(String, String) Sets the error description for a column specified by name.

• SetModified Changes the Rowstate() of a DataRow to Modified.

• SetNull Sets the value of the specified DataColumn to a null value.

• SetParentRow(DataRow) Sets the parent row of a DataRow with specified new parent DataRow.

• SetParentRow(DataRow, DataRelation) Sets the parent row of a DataRow with specified new parent DataRow and DataRelation.

• ToString Returns a string that represents the current object. (Inherited from Object.)

sheepsqueezers.com

Copyright ©2011 sheepsqueezers.com Copyright ©2011 sheepsqueezers.com

sheepsqueezers.com

The System.Data Namespace

Classes

DataTableReader

sheepsqueezers.com

Copyright ©2011 sheepsqueezers.com Copyright ©2011 sheepsqueezers.com

sheepsqueezers.com

DataTableReader

The DataTableReader class obtains the contents of one or more DataTable

objects in the form of one or more read-only, forward-only result sets. According to Microsoft's website: The DataTableReader works much like any other data reader, such as the SqlDataReader, except that the DataTableReader provides for iterating over rows in a DataTable. In other words, it provides for iterating over rows in a cache. The cached data can be modified while the DataTableReader is active, and the reader automatically maintains its position.

When you create a DataTableReader from a DataTable, the resulting DataTableReader object contains one result set with the same data as the DataTable from which it was created, except for any rows that have been marked as deleted. The columns appear in the same order as in the original DataTable. The structure of the returned result is identical in schema and data to the original DataTable. A DataTableReader that was created by calling the GetDataReader() method of a DataSet object contains multiple result sets if the DataSet contains more than one table. The results are in the same sequence as the DataTable objects in the DataTableCollection of the DataSet object.

The returned result set contains only the current version of each DataRow; rows that are marked for deletion are skipped.

The DataTableReader provides a stable iterator; that is, the contents of the DataTableReader are not invalidated if the size of the underlying collection is modified during iteration. For example, if one or more rows in the Rows collection are deleted or removed during iteration, the current position within the DataTableReader is maintained appropriately and it does not invalidate the iterator.

sheepsqueezers.com

Copyright ©2011 sheepsqueezers.com Copyright ©2011 sheepsqueezers.com

sheepsqueezers.com

DataTableReader

Constructors • DataTableReader(DataTable) - Initializes a new instance of the DataTableReader class by using data from the supplied

DataTable.

• DataTableReader(DataTable[]) - Initializes a new instance of the DataTableReader class using the supplied array of DataTable objects.

Properties • Depth - The depth of nesting for the current row of the DataTableReader. (Overrides DbDataReader.Depth.)

• FieldCount - Returns the number of columns in the current row. (Overrides DbDataReader.FieldCount.)

• HasRows - Gets a value that indicates whether the DataTableReader contains one or more rows. (Overrides DbDataReader.HasRows.)

• IsClosed - Gets a value that indicates whether the DataTableReader is closed. (Overrides DbDataReader.IsClosed.)

• Item[Int32] - Gets the value of the specified column in its native format given the column ordinal. (Overrides DbDataReader.Item[Int32].)

• Item[String] - Gets the value of the specified column in its native format given the column name. (Overrides DbDataReader.Item[String].)

• RecordsAffected - Gets the number of rows inserted, changed, or deleted by execution of the SQL statement. (Overrides DbDataReader.RecordsAffected.)

• VisibleFieldCount - Gets the number of fields in the DbDataReader that are not hidden. (Inherited from DbDataReader.)

Methods • Close - Closes the current DataTableReader. (Overrides DbDataReader.Close().)

• CreateObjRef - Creates an object that contains all the relevant information required to generate a proxy used to communicate with a remote object. (Inherited from MarshalByRefObject.)

• Dispose() - Releases all resources used by the current instance of the DbDataReader class. (Inherited from DbDataReader.)

• Dispose(Boolean) - Releases the managed resources used by the DbDataReader and optionally releases the unmanaged resources. (Inherited from DbDataReader.)

• Equals(Object) - Determines whether the specified Object is equal to the current Object. (Inherited from Object.)

• Finalize - Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)

• GetBoolean - Gets the value of the specified column as a Boolean. (Overrides DbDataReader.GetBoolean(Int32).)

• GetByte - Gets the value of the specified column as a byte. (Overrides DbDataReader.GetByte(Int32).)

sheepsqueezers.com

Copyright ©2011 sheepsqueezers.com Copyright ©2011 sheepsqueezers.com

sheepsqueezers.com

DataTableReader

Methods (continued) • GetBytes - Reads a stream of bytes starting at the specified column offset into the buffer as an array starting at the specified

buffer offset. (Overrides DbDataReader.GetBytes(Int32, Int64, Byte[], Int32, Int32).)

• GetChar - Gets the value of the specified column as a character. (Overrides DbDataReader.GetChar(Int32).)

• GetChars - Returns the value of the specified column as a character array. (Overrides DbDataReader.GetChars(Int32, Int64, Char[], Int32, Int32).)

• GetData - Returns a DbDataReader object for the requested column ordinal. (Inherited from DbDataReader.)

• GetDataTypeName - Gets a string representing the data type of the specified column. (Overrides DbDataReader.GetDataTypeName(Int32).)

• GetDateTime - Gets the value of the specified column as a DateTime object. (Overrides DbDataReader.GetDateTime(Int32).)

• GetDbDataReader - Returns a DbDataReader object for the requested column ordinal that can be overridden with a provider-specific implementation. (Inherited from DbDataReader.)

• GetDecimal - Gets the value of the specified column as a Decimal. (Overrides DbDataReader.GetDecimal(Int32).)

• GetDouble - Gets the value of the column as a double-precision floating point number. (Overrides DbDataReader.GetDouble(Int32).)

• GetEnumerator - Returns an enumerator that can be used to iterate through the item collection. (Overrides DbDataReader.GetEnumerator().)

• GetFieldType - Gets the Type that is the data type of the object. (Overrides DbDataReader.GetFieldType(Int32).)

• GetFloat - Gets the value of the specified column as a single-precision floating point number. (Overrides DbDataReader.GetFloat(Int32).)

• GetGuid - Gets the value of the specified column as a globally-unique identifier (GUID). (Overrides DbDataReader.GetGuid(Int32).)

• GetHashCode - Serves as a hash function for a particular type. (Inherited from Object.)

• GetInt16 - Gets the value of the specified column as a 16-bit signed integer. (Overrides DbDataReader.GetInt16(Int32).)

• GetInt32 - Gets the value of the specified column as a 32-bit signed integer. (Overrides DbDataReader.GetInt32(Int32).)

• GetInt64 - Gets the value of the specified column as a 64-bit signed integer. (Overrides DbDataReader.GetInt64(Int32).)

• GetLifetimeService - Retrieves the current lifetime service object that controls the lifetime policy for this instance. (Inherited from MarshalByRefObject.)

• GetName - Gets the value of the specified column as a String. (Overrides DbDataReader.GetName(Int32).)

• GetOrdinal - Gets the column ordinal, given the name of the column. (Overrides DbDataReader.GetOrdinal(String).)

• GetProviderSpecificFieldType - Gets the type of the specified column in provider-specific format. (Overrides DbDataReader.GetProviderSpecificFieldType(Int32).)

• GetProviderSpecificValue - Gets the value of the specified column in provider-specific format. (Overrides DbDataReader.GetProviderSpecificValue(Int32).)

sheepsqueezers.com

Copyright ©2011 sheepsqueezers.com Copyright ©2011 sheepsqueezers.com

sheepsqueezers.com

DataTableReader

Methods (continued) • GetProviderSpecificValues - Fills the supplied array with provider-specific type information for all the columns in the

DataTableReader. (Overrides DbDataReader.GetProviderSpecificValues(Object[]).)

• GetSchemaTable - Returns a DataTable that describes the column metadata of the DataTableReader. (Overrides DbDataReader.GetSchemaTable().)

• GetString - Gets the value of the specified column as a string. (Overrides DbDataReader.GetString(Int32).)

• GetType - Gets the Type of the current instance. (Inherited from Object.)

• GetValue - Gets the value of the specified column in its native format. (Overrides DbDataReader.GetValue(Int32).)

• GetValues - Populates an array of objects with the column values of the current row. (Overrides DbDataReader.GetValues(Object[]).)

• InitializeLifetimeService - Obtains a lifetime service object to control the lifetime policy for this instance. (Inherited from MarshalByRefObject.)

• IsDBNull - Gets a value that indicates whether the column contains non-existent or missing values. (Overrides DbDataReader.IsDBNull(Int32).)

• MemberwiseClone() - Creates a shallow copy of the current Object. (Inherited from Object.)

• MemberwiseClone(Boolean) - Creates a shallow copy of the current MarshalByRefObject object. (Inherited from MarshalByRefObject.)

• NextResult - Advances the DataTableReader to the next result set, if any. (Overrides DbDataReader.NextResult().)

• Read - Advances the DataTableReader to the next record. (Overrides DbDataReader.Read().)

• ToString - Returns a string that represents the current object. (Inherited from Object.)

You can use the data reader with code similar to this:

//Print out the data using the DataTableReader class

DataTableReader dtrFATKIDS = new DataTableReader(dsFatKidsDB.Tables["FatKids"]);

while(dtrFATKIDS.Read()) {

Console.WriteLine(dtrFATKIDS[1]); //Print out the first name

}

sheepsqueezers.com

Copyright ©2011 sheepsqueezers.com Copyright ©2011 sheepsqueezers.com

sheepsqueezers.com

The System.Data Namespace

Classes

DataView

sheepsqueezers.com

Copyright ©2011 sheepsqueezers.com Copyright ©2011 sheepsqueezers.com

sheepsqueezers.com

DataView

The DataView class represents a data-bindable, customized view of a DataTable

for sorting, filtering, searching, editing, and navigation.

Constructors • DataView() - Initializes a new instance of the DataView class.

• DataView(DataTable) - Initializes a new instance of the DataView class with the specified DataTable.

• DataView(DataTable, String, String, DataViewRowState) - Initializes a new instance of the DataView class with the specified DataTable, RowFilter, Sort, and DataViewRowState

Properties • AllowDelete - Sets or gets a value that indicates whether deletes are allowed.

• AllowEdit - Gets or sets a value that indicates whether edits are allowed.

• AllowNew - Gets or sets a value that indicates whether the new rows can be added by using the AddNew method.

• ApplyDefaultSort - Gets or sets a value that indicates whether to use the default sort.

• Container - Gets the container for the component. (Inherited from MarshalByValueComponent.)

• Count - Gets the number of records in the DataView after RowFilter and RowStateFilter have been applied.

• DataViewManager - Gets the DataViewManager associated with this view.

• DesignMode - Gets a value indicating whether the component is currently in design mode. (Inherited from MarshalByValueComponent.)

• Events - Gets the list of event handlers that are attached to this component. (Inherited from MarshalByValueComponent.)

• IsInitialized - Gets a value that indicates whether the component is initialized.

• IsOpen - Gets a value that indicates whether the data source is currently open and projecting views of data on the DataTable.

• Item - Gets a row of data from a specified table.

• RowFilter - Gets or sets the expression used to filter which rows are viewed in the DataView.

• RowStateFilter - Gets or sets the row state filter used in the DataView.

• Site - Gets or sets the site of the component. (Inherited from MarshalByValueComponent.)

• Sort - Gets or sets the sort column or columns, and sort order for the DataView.

• Table - Gets or sets the source DataTable.

Events • Disposed - Adds an event handler to listen to the Disposed event on the component. (Inherited from

MarshalByValueComponent.)

• Initialized - Occurs when initialization of the DataView is completed.

• ListChanged - Occurs when the list managed by the DataView changes.

sheepsqueezers.com

Copyright ©2011 sheepsqueezers.com Copyright ©2011 sheepsqueezers.com

sheepsqueezers.com

DataView

Methods • AddNew - Adds a new row to the DataView.

• BeginInit - Starts the initialization of a DataView that is used on a form or used by another component. The initialization occurs at runtime.

• Close - Closes the DataView.

• ColumnCollectionChanged - Occurs after a DataColumnCollection has been changed successfully.

• CopyTo - Copies items into an array. Only for Web Forms Interfaces.

• Delete - Deletes a row at the specified index.

• Dispose() - Releases all resources used by the MarshalByValueComponent. (Inherited from MarshalByValueComponent.)

• Dispose(Boolean) - Disposes of the resources (other than memory) used by the DataView object. (Overrides MarshalByValueComponent.Dispose(Boolean).)

• EndInit - Ends the initialization of a DataView that is used on a form or used by another component. The initialization occurs at runtime.

• Equals(DataView) - Determines whether the specified DataView instances are considered equal.

• Equals(Object) - Determines whether the specified Object is equal to the current Object. (Inherited from Object.)

• Finalize - Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from MarshalByValueComponent.)

• Find(Object) - Finds a row in the DataView by the specified sort key value.

• Find(Object[]) - Finds a row in the DataView by the specified sort key values.

• FindRows(Object) - Returns an array of DataRowView objects whose columns match the specified sort key value.

• FindRows(Object[]) - Returns an array of DataRowView objects whose columns match the specified sort key value.

• GetEnumerator - Gets an enumerator for this DataView.

• GetHashCode - Serves as a hash function for a particular type. (Inherited from Object.)

• GetService - Gets the implementer of the IServiceProvider. (Inherited from MarshalByValueComponent.)

• GetType - Gets the Type of the current instance. (Inherited from Object.)

• IndexListChanged - Occurs after a DataView has been changed successfully.

• MemberwiseClone - Creates a shallow copy of the current Object. (Inherited from Object.)

• OnListChanged - Raises the ListChanged event.

• Open - Opens a DataView.

• ToString - Returns a String containing the name of the Component, if any. This method should not be overridden. (Inherited from MarshalByValueComponent.)

• ToTable() - Creates and returns a new DataTable based on rows in an existing DataView.

• ToTable(String) - Creates and returns a new DataTable based on rows in an existing DataView.

• ToTable(Boolean, String[]) - Creates and returns a new DataTable based on rows in an existing DataView.

• ToTable(String, Boolean, String[]) - Creates and returns a new DataTable based on rows in an existing DataView.

sheepsqueezers.com

Copyright ©2011 sheepsqueezers.com Copyright ©2011 sheepsqueezers.com

sheepsqueezers.com

DataView

Please see Microsoft's website for more on the DataView class.

sheepsqueezers.com

Copyright ©2011 sheepsqueezers.com Copyright ©2011 sheepsqueezers.com

sheepsqueezers.com

The System.Data Namespace

Attributes

sheepsqueezers.com

Copyright ©2011 sheepsqueezers.com Copyright ©2011 sheepsqueezers.com

sheepsqueezers.com

Attributes The following are the attributes available in the System.Data namespace.

Attributes • DataSysDescriptionAttribute - Obsolete. Marks a property, event, or extender with a description. Visual designers can display this

description when referencing the member.

sheepsqueezers.com

Copyright ©2011 sheepsqueezers.com Copyright ©2011 sheepsqueezers.com

sheepsqueezers.com

The System.Data Namespace

EventArgs

sheepsqueezers.com

Copyright ©2011 sheepsqueezers.com Copyright ©2011 sheepsqueezers.com

sheepsqueezers.com

EventArgs The following are the EventArgs available in the System.Data namespace.

EventArgs • DataColumnChangeEventArgs - Provides data for the ColumnChanging event. • DataRowChangeEventArgs - Provides data for the RowChanged, RowChanging, OnRowDeleting, and OnRowDeleted events. • DataTableClearEventArgs - Provides data for the Clear method. • DataTableNewRowEventArgs - Provides data for the NewRow method. • FillErrorEventArgs - Provides data for the FillError event of a DbDataAdapter. • StateChangeEventArgs - Provides data for the state change event of a .NET Framework data provider. • StatementCompletedEventArgs - Provides additional information for the StatementCompleted event.

sheepsqueezers.com

Copyright ©2011 sheepsqueezers.com Copyright ©2011 sheepsqueezers.com

sheepsqueezers.com

The System.Data Namespace

Structures

sheepsqueezers.com

Copyright ©2011 sheepsqueezers.com Copyright ©2011 sheepsqueezers.com

sheepsqueezers.com

Structures The are no structures in the System.Data namespace.

sheepsqueezers.com

Copyright ©2011 sheepsqueezers.com Copyright ©2011 sheepsqueezers.com

sheepsqueezers.com

The System.Data Namespace

Interfaces

sheepsqueezers.com

Copyright ©2011 sheepsqueezers.com Copyright ©2011 sheepsqueezers.com

sheepsqueezers.com

Interfaces The interfaces of the System.Data namespace are listed below.

Interfaces • IColumnMapping - Associates a data source column with a DataSet column, and is implemented by the DataColumnMapping class,

which is used in common by .NET Framework data providers. • IColumnMappingCollection - Contains a collection of DataColumnMapping objects, and is implemented by the

DataColumnMappingCollection, which is used in common by .NET Framework data providers. • IDataAdapter - Allows an object to implement a DataAdapter, and represents a set of methods and mapping action-related

properties that are used to fill and update a DataSet and update a data source. • IDataParameter - Represents a parameter to a Command object, and optionally, its mapping to DataSet columns; and is

implemented by .NET Framework data providers that access data sources. • IDataParameterCollection - Collects all parameters relevant to a Command object and their mappings to DataSet columns, and is

implemented by .NET Framework data providers that access data sources. • IDataReader - Provides a means of reading one or more forward-only streams of result sets obtained by executing a command at

a data source, and is implemented by .NET Framework data providers that access relational databases. • IDataRecord - Provides access to the column values within each row for a DataReader, and is implemented by .NET Framework

data providers that access relational databases. • IDbCommand - Represents an SQL statement that is executed while connected to a data source, and is implemented by .NET

Framework data providers that access relational databases. • IDbConnection - Represents an open connection to a data source, and is implemented by .NET Framework data providers that

access relational databases. • IDbDataAdapter - Represents a set of command-related properties that are used to fill the DataSet and update a data source, and

is implemented by .NET Framework data providers that access relational databases. • IDbDataParameter - Used by the Visual Basic .NET Data Designers to represent a parameter to a Command object, and

optionally, its mapping to DataSet columns. • IDbTransaction - Represents a transaction to be performed at a data source, and is implemented by .NET Framework data

providers that access relational databases. • IExtendedDataRecord - Provides access to the column values within each row of a DbDataRecord for a DbDataReader. • ITableMapping - Associates a source table with a table in a DataSet, and is implemented by the DataTableMapping class, which is

used in common by .NET Framework data providers. • ITableMappingCollection - Contains a collection of TableMapping objects, and is implemented by the DataTableMappingCollection,

which is used in common by .NET Framework data providers.

sheepsqueezers.com

Copyright ©2011 sheepsqueezers.com Copyright ©2011 sheepsqueezers.com

sheepsqueezers.com

The System.Data Namespace

Delegates

sheepsqueezers.com

Copyright ©2011 sheepsqueezers.com Copyright ©2011 sheepsqueezers.com

sheepsqueezers.com

Delegates There following are the delegates available in the System.Data namespace.

Delegates • DataColumnChangeEventHandler - Represents the method that will handle the ColumnChanging event. • DataRowChangeEventHandler - Represents the method that will handle the RowChanging, RowChanged, RowDeleting, and

RowDeleted events of a DataTable. • DataTableClearEventHandler - Represents the method that handles the Clear method. • DataTableNewRowEventHandler - Represents the method that handles the NewRow method. • FillErrorEventHandler - Represents the method that will handle the FillError event. • MergeFailedEventHandler - Represents the method that will handle the MergeFailed event. • StateChangeEventHandler - Represents the method that will handle the StateChange event. • StatementCompletedEventHandler - The delegate type for the event handlers of the StatementCompleted event.

sheepsqueezers.com

Copyright ©2011 sheepsqueezers.com Copyright ©2011 sheepsqueezers.com

sheepsqueezers.com

The System.Data Namespace

Enumerations

sheepsqueezers.com

Copyright ©2011 sheepsqueezers.com Copyright ©2011 sheepsqueezers.com

sheepsqueezers.com

Enumerations The following are the enumerations available in the System.Data namespace.

Enumerations • AcceptRejectRule - Determines the action that occurs when the AcceptChanges or RejectChanges method is invoked on a

DataTable with a ForeignKeyConstraint. • CommandBehavior - Provides a description of the results of the query and its effect on the database. • CommandType - Specifies how a command string is interpreted. • ConflictOption - Specifies how conflicting changes to the data source will be detected and resolved. • ConnectionState - Describes the current state of the connection to a data source. • DataRowAction - Describes an action performed on a DataRow. • DataRowState - Gets the state of a DataRow object. • DataRowVersion - Describes the version of a DataRow. • DataSetDateTime - Describes the serialization format for DateTime columns in a DataSet. • DataViewRowState - Describes the version of data in a DataRow. • DbType - Specifies the data type of a field, a property, or a Parameter object of a .NET Framework data provider. • EntityState - The state of an entity object. • IsolationLevel - Specifies the transaction locking behavior for the connection. • KeyRestrictionBehavior - Identifies a list of connection string parameters identified by the KeyRestrictions property that are either

allowed or not allowed. • LoadOption - Controls how the values from the data source will be applied to existing rows when using the Load or Load method. • MappingType - Specifies how a DataColumn is mapped. • MissingMappingAction - Determines the action that occurs when a mapping is missing from a source table or a source column. • MissingSchemaAction - Specifies the action to take when adding data to the DataSet and the required DataTable or DataColumn is

missing. • ParameterDirection - Specifies the type of a parameter within a query relative to the DataSet. • PropertyAttributes - Obsolete. Specifies the attributes of a property. • Rule - Indicates the action that occurs when a ForeignKeyConstraint is enforced. • SchemaSerializationMode - Indicates the schema serialization mode for a typed DataSet. • SchemaType - Specifies how to handle existing schema mappings when performing a FillSchema operation. • SerializationFormat - Determines the serialization format for a DataSet. • SqlDbType - Specifies SQL Server-specific data type of a field, property, for use in a SqlParameter. • StatementType - Specifies the type of SQL query to be used by the OleDbRowUpdatedEventArgs, OleDbRowUpdatingEventArgs,

SqlRowUpdatedEventArgs, or SqlRowUpdatingEventArgs class. • UpdateRowSource - Specifies how query command results are applied to the row being updated. • UpdateStatus - Specifies the action to take with regard to the current and remaining rows during an Update. • XmlReadMode - Specifies how to read XML data and a relational schema into a DataSet. • XmlWriteMode - Specifies how to write XML data and a relational schema from a DataSet.

sheepsqueezers.com

Copyright ©2011 sheepsqueezers.com Copyright ©2011 sheepsqueezers.com

sheepsqueezers.com

The System.Data Namespace

Exceptions

sheepsqueezers.com

Copyright ©2011 sheepsqueezers.com Copyright ©2011 sheepsqueezers.com

sheepsqueezers.com

Exceptions Below are the classes derived from Exception in the System.Data namespace.

Exceptions • ConstraintException - Represents the exception that is thrown when attempting an action that violates a constraint. • DataException - Represents the exception that is thrown when errors are generated using ADO.NET components. • DBConcurrencyException - The exception that is thrown by the DataAdapter during an insert, update, or delete operation if the

number of rows affected equals zero. • DeletedRowInaccessibleException - Represents the exception that is thrown when an action is tried on a DataRow that has been

deleted. • DuplicateNameException - Represents the exception that is thrown when a duplicate database object name is encountered during

an add operation in a DataSet -related object. • EntityCommandCompilationException - Represents errors that occur during command compilation; when a command tree could

not be produced to represent the command text. • EntityCommandExecutionException - Represents errors that occur when the underlying storage provider could not execute the

specified command. This exception usually wraps a provider-specific exception. • EntityException - Represents Entity Framework-related errors that occur in the EntityClient namespace. The EntityException is the

base class for all Entity Framework exceptions thrown by the EntityClient. • EntitySqlException - Represents errors that occur when parsing Entity SQL command text. This exception is thrown when

syntactic or semantic rules are violated. • EvaluateException -Represents the exception that is thrown when the Expression property of a DataColumn cannot be evaluated. • InRowChangingEventException - Represents the exception that is thrown when you call the EndEdit method within the

RowChanging event. • InvalidCommandTreeException - The exception that is thrown to indicate that a command tree is invalid. This exception is

currently not thrown anywhere in the Entity Framework. • InvalidConstraintException - Represents the exception that is thrown when incorrectly trying to create or access a relation. • InvalidExpressionException - Represents the exception that is thrown when you try to add a DataColumn that contains an invalid

Expression to a DataColumnCollection. • MappingException - The exception that is thrown when mapping related service requests fail. • MergeFailedEventArgs - Occurs when a target and source DataRow have the same primary key value, and the EnforceConstraints

property is set to true. • MetadataException - The exception that is thrown when metadata related service requests fails. • MissingPrimaryKeyException - Represents the exception that is thrown when you try to access a row in a table that has no

primary key. • NoNullAllowedException - Represents the exception that is thrown when you try to insert a null value into a column where

AllowDBNull is set to false. • ObjectNotFoundException - The exception that is thrown when an object is not present. • OperationAbortedException - This exception is thrown when an ongoing operation is aborted by the user. • OptimisticConcurrencyException - The exception that is thrown when an optimistic concurrency violation occurs.

sheepsqueezers.com

Copyright ©2011 sheepsqueezers.com Copyright ©2011 sheepsqueezers.com

sheepsqueezers.com

Exceptions Exceptions (continued) • ProviderIncompatibleException - The exception that is thrown when the underlying data provider is incompatible with the Entity

Framework. • ReadOnlyException - Represents the exception that is thrown when you try to change the value of a read-only column. • RowNotInTableException - Represents the exception that is thrown when you try to perform an operation on a DataRow that is

not in a DataTable. • StrongTypingException - The exception that is thrown by a strongly typed DataSet when the user accesses a DBNull value. • SyntaxErrorException - Represents the exception that is thrown when the Expression property of a DataColumn contains a syntax

error. • TypedDataSetGeneratorException - The exception that is thrown when a name conflict occurs while generating a strongly typed

DataSet. • UpdateException - The exception that is thrown when modifications to object instances cannot be persisted to the data source. • VersionNotFoundException - Represents the exception that is thrown when you try to return a version of a DataRow that has been

deleted.

sheepsqueezers.com

Copyright ©2011 sheepsqueezers.com Copyright ©2011 sheepsqueezers.com

sheepsqueezers.com

What Next?

In C# Programming IV-#, we look at specific classes within specific namespaces such as the System namespace, the System.Data namespace, etc.

sheepsqueezers.com

Copyright ©2011 sheepsqueezers.com Copyright ©2011 sheepsqueezers.com

sheepsqueezers.com

References

Introducing Microsoft LINQ, Paolo Pialorsi and Marco Russo, Microsoft Press, ISBN:9780735623910

LINQ Pocket Reference, Joseph Albahari and Ben Albahari, O'Reilly Press, ISBN:9780596519247

Inside C#, Tom Archer and Andrew Whitechapel, Microsoft Press, ISBN:0735616485

C# 4.0 In a Nutshell, O'Reilly Press, Joseph Albahari and Ben Albahari, ISBN:9780596800956

The Object Primer, Scott W. Ambler, Cambridge Press, ISBN:0521540186

CLR via C#, Jeffrey Richter, Microsoft Press, ISBN:9780735621633

Click the book titles below to read more about these books on Amazon.com's website.

sheepsqueezers.com

Copyright ©2011 sheepsqueezers.com

Support sheepsqueezers.com If you found this information helpful, please consider

supporting sheepsqueezers.com. There are several

ways to support our site:

Buy me a cup of coffee by clicking on the

following link and donate to my PayPal

account: Buy Me A Cup Of Coffee?.

Visit my Amazon.com Wish list at the following

link and purchase an item:

http://amzn.com/w/3OBK1K4EIWIR6

Please let me know if this document was useful by e-mailing me at [email protected].


Recommended