Professional Documents
Culture Documents
APracticalGuideto.NETDataTables,DataSetsandDataGridsPart1CodeProject
articles
Q&A
forums
Sign in
lounge
Searchforarticles,questions,tips
CPOL
Rate this:
4.87 66 votes
The purpose of this document is to provide a practical guide to using Microsofts .NET DataTables, DataSets and DataGrid
Copyright
The contents of this document can be freely copied and disseminated with the condition that the document
retains reference to BioXing, the author and its Copyright notice. In addition, the document or any part of
the document cannot be incorporated into commercial products without prior permission of BioXing and its
author. BioXing retains all rights to commercial use of this document.
Table of Contents
1 Introduction
2 Overview
3 Tables
3.1 Table creation
3.2 Columns Creating and Adding to Tables
3.3 Deleting/Removing Columns
3.4 Modifying Column Properties
3.5 Clearing Column Collection
3.6 Cloning a Table
3.7 Rows creating and adding to a table
3.8 Modifying data within an existing table row
3.9 Fill Table using LoadDataRow method
3.10 Retrieving Table Content
3.11 Row Versions and Accepting/Rejecting Changes
3.11.1 Methods and Enumerations
3.11.2 Sample 1 Row States
3.11.3 Sample 2 Initial Loading of Table
3.11.4 Sample 3 DataRow AcceptChanges
3.11.5 Sample 4 Table AcceptChanges
3.11.6 Sample 5 DataRow BeginEdit
3.11.7 Sample 6 DataRow CancelEdit
http://www.codeproject.com/Articles/6178/APracticalGuidetoNETDataTablesDataSetsandD
1/7
9/30/2015
APracticalGuideto.NETDataTables,DataSetsandDataGridsPart1CodeProject
2/7
9/30/2015
APracticalGuideto.NETDataTables,DataSetsandDataGridsPart1CodeProject
6 References
1 Introduction
The purpose of this document is to provide a practical guide to using Microsofts .NET DataTables, DataSetsand
DataGrid. Most articles illustrate how to use the DataGridwhen directly bound to tables within a database and even
though this is an excellent way to use the DataGrid, it is also able to display and manage programmatically created and linked
tables and datasets composed of these tables without being bound to a database. Microsofts implementation has provided a
rich syntax for populating and accessing rows and their cells within tables, for managing collections of tables, columns, rows and
table styles and for managing inserts, updates, deletes and events. Microsofts Visual Studio .NET development environment
provides detailed explanations and code examples for the classes, which is excellent for obtaining a quick reference to a method
or property, but not for understanding how they all fit together and are used in applications.
This article will present different ways to create and manage bound and unbound tables and datasets and to bind them to
DataGridsfor use by WebForms and WinForms. The different behaviors of the DataGrid depending upon whether it is in a
WebForm or a WinForm will be presented. In addition, copying DataGridcontent to the clipboard, importing and exporting
in XML and printing will be presented. Techniques for linking DataGridcontent to features within graphics objects to
provide an interactive UI will be discussed in the last section.
The intent of this article is not to be a complete reference for all methods and members of the classes used for building Tables,
Datasets and DataGrids, but to illustrate systematically how to build and manage them using their essential methods and
properties. The article will also show equivalent ways for working with these entities to illustrate programming flexibility options.
Once they are built the tables can be added to a database and/or the content easily extracted for updating existing database
tables.
The structure and features of a table created using the DataTable class is at the heart of using the DataGrid; therefore, it will be
presented first. Next the DataSet that manages collections of independent and linked tables will be presented followed by the
DataGrid that displays and provides an interactive UI for its Tables and Datasets. All example code will be written in C# and the
periodic table with its elements and isotopes will be used as a model and source of data.
2 Overview
Figure 1 is a summary view of the essential relationships between the DataGrid, DataGridTableStyles, DataSets
and DataTablesand their various methods and properties. This article will delve into the details of each of these
components describing how to create them, to fill them with data and how they work together and thereby provide a clearer
understanding of this relationship diagram.
http://www.codeproject.com/Articles/6178/APracticalGuidetoNETDataTablesDataSetsandD
3/7
9/30/2015
APracticalGuideto.NETDataTables,DataSetsandDataGridsPart1CodeProject
Next...
Tables.
License
This article, along with any associated source code and files, is licensed under The Code Project Open License CPOL
Share
EMAIL
http://www.codeproject.com/Articles/6178/APracticalGuidetoNETDataTablesDataSetsandD
4/7
9/30/2015
APracticalGuideto.NETDataTables,DataSetsandDataGridsPart1CodeProject
Pete2004
President Bioxing
United States
Ph.D. in BioPhysics and over 20 years of experience in managing, architecting and handson developing software systems for
biotechnology companies that produced cutting edge instrumentation and data systems. These include DNA and Peptide
Synthesizers, cDNA, oligo and Protein microarrays and mass spectrometers used for protein sequencing.In 2001 founded
BioXing pronounced BioCrossing which has architected and developed an extensible relational database repository and
software system that includes Web Services, Client Workstation and Web Based applications. The system is used to track,
manage, integrate and data mine disparate laboratory data, protocols and experiments and link to reference proteomic and
genomic data. BioXing also does consulting and development for biotechnology companies.
Why NoSQL?
Go
First Prev Next
5/7
9/30/2015
APracticalGuideto.NETDataTables,DataSetsandDataGridsPart1CodeProject
Lalit24rocks
My vote of 1
CH Guravaiah
thanks
anhlada2002
15May13 19:45
17Dec12 0:16
7Oct08 16:15
26Sep05 23:12
Re: Indexing
Pete2004 29Sep05 11:28
download this article as a single document
mooncow 7Feb05 21:36
Re: download this article as a single document
Pete2004 8Feb05 4:44
Re: download this article as a single document
feruzi 18Sep05 6:02
Re: download this article as a single document
mysofttech 6Mar06 19:41
Re: download this article as a single document
ko_marek 15Apr09 3:03
Populating Datagrid using XML
anilnair_m 7Jan05 2:24
Thanks
Phil_B 29Sep04 15:15
.Thanks
Anonymous
29Sep04 15:08
Re: .Thanks
z1m9b6 5Jan06 13:54
Re: .Thanks
Portatofe 2Oct08 6:09
Win XP and DataGrid
msenkerik 28Sep04 23:19
How to implemet of functionality of dataset in MyOwn Class
shahzadarfan 15Jul04 2:40
http://www.codeproject.com/Articles/6178/APracticalGuidetoNETDataTablesDataSetsandD
6/7
9/30/2015
APracticalGuideto.NETDataTables,DataSetsandDataGridsPart1CodeProject
24Feb04 19:12
24Feb04 23:34
Re: Five
Richard Boesiger
Re: Five
mittalpa
25Feb04 0:39
3Mar04 4:42
Re: Five
gmsm 19Mar04 9:05
Refresh
General
News
1
Suggestion
Question
Bug
Answer
Joke
Rant
Admin
Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.
Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.1509028.1 | Last Updated 24 Feb 2004
Select Language
http://www.codeproject.com/Articles/6178/APracticalGuidetoNETDataTablesDataSetsandD
7/7