Click here to Skip to main content
11,437,002 members (67,385 online)
Click here to Skip to main content

A Practical Guide to .NET DataTables, DataSets and DataGrids - Part 1

, 23 Feb 2004 CPOL
Rate this:
Please Sign up or sign in to vote.
The purpose of this document is to provide a practical guide to using Microsoft’s .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

The purpose of this document is to provide a practical guide to using Microsoft’s .NET DataTables, DataSets and DataGrid. Most articles illustrate how to use the DataGrid when 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. Microsoft’s 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. Microsoft’s 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 DataGrids for 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 DataGrid content to the clipboard, importing and exporting in XML and printing will be presented. Techniques for linking DataGrid content 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 DataTables and 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.

Figure 1 DataGrid, DataSet and DataTable relationship diagram

Next...

Tables.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Pete2004
President Bioxing
United States United States
Ph.D. in BioPhysics and over 20 years of experience in managing, architecting and hands-on 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 Bio-Crossing) 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.

Comments and Discussions

 
GeneralDifference between DataSet and DataTable in asp.net Pin
Lalit24rocks15-May-13 20:45
memberLalit24rocks15-May-13 20:45 
GeneralMy vote of 1 Pin
CH Guravaiah17-Dec-12 1:16
memberCH Guravaiah17-Dec-12 1:16 
Answerthanks Pin
anhlada20027-Oct-08 17:15
memberanhlada20027-Oct-08 17:15 
GeneralArticals not found in this section Pin
anu91411-Dec-07 4:59
memberanu91411-Dec-07 4:59 
GeneralIndexing Pin
Indexing service system27-Sep-05 0:12
memberIndexing service system27-Sep-05 0:12 
GeneralRe: Indexing Pin
Pete200429-Sep-05 12:28
memberPete200429-Sep-05 12:28 
Generaldownload this article as a single document Pin
mooncow7-Feb-05 22:36
membermooncow7-Feb-05 22:36 
GeneralRe: download this article as a single document Pin
Pete20048-Feb-05 5:44
memberPete20048-Feb-05 5:44 
GeneralRe: download this article as a single document Pin
feruzi18-Sep-05 7:02
memberferuzi18-Sep-05 7:02 
GeneralRe: download this article as a single document Pin
mysofttech6-Mar-06 20:41
membermysofttech6-Mar-06 20:41 
AnswerRe: download this article as a single document Pin
ko_marek15-Apr-09 4:03
memberko_marek15-Apr-09 4:03 
GeneralPopulating Datagrid using XML Pin
anilnair_m7-Jan-05 3:24
memberanilnair_m7-Jan-05 3:24 
I am experiencing problems with populating the
Component One Datagrid with XML string .
To be precise, i am getting XML string from
Webservices and I've to use this to populate
User Interface(dataGrid)
RegardsSigh | :sigh: Sigh | :sigh: Cry | :(( Cry | :((
GeneralThanks Pin
Phil_B29-Sep-04 16:15
memberPhil_B29-Sep-04 16:15 
General.Thanks Pin
Anonymous29-Sep-04 16:08
sussAnonymous29-Sep-04 16:08 
GeneralRe: .Thanks Pin
z1m9b65-Jan-06 14:54
memberz1m9b65-Jan-06 14:54 
GeneralRe: .Thanks Pin
Portatofe2-Oct-08 7:09
memberPortatofe2-Oct-08 7:09 
GeneralWin XP and DataGrid Pin
msenkerik29-Sep-04 0:19
membermsenkerik29-Sep-04 0:19 
QuestionHow to implemet of functionality of dataset in MyOwn Class Pin
shahzadarfan15-Jul-04 3:40
membershahzadarfan15-Jul-04 3:40 
AnswerRe: How to implemet of functionality of dataset in MyOwn Class Pin
Pete200415-Jul-04 7:53
memberPete200415-Jul-04 7:53 
GeneralRe: How to implemet of functionality of dataset in MyOwn Class Pin
shahzadarfan15-Jul-04 22:45
membershahzadarfan15-Jul-04 22:45 
GeneralRe: How to implemet of functionality of dataset in MyOwn Class Pin
Pete200416-Jul-04 5:55
memberPete200416-Jul-04 5:55 
GeneralSuggestions and Corrections Pin
Pete200425-Feb-04 6:35
memberPete200425-Feb-04 6:35 
GeneralFive Pin
Nemanja Trifunovic24-Feb-04 20:12
memberNemanja Trifunovic24-Feb-04 20:12 
GeneralRe: Five Pin
netclectic25-Feb-04 0:34
membernetclectic25-Feb-04 0:34 
GeneralRe: Five Pin
Richard Boesiger25-Feb-04 1:39
memberRichard Boesiger25-Feb-04 1:39 
GeneralRe: Five Pin
mittalpa3-Mar-04 5:42
membermittalpa3-Mar-04 5:42 
GeneralRe: Five Pin
gmsm19-Mar-04 10:05
membergmsm19-Mar-04 10:05 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.150428.2 | Last Updated 24 Feb 2004
Article Copyright 2004 by Pete2004
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid