Click here to Skip to main content
Click here to Skip to main content

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

By , 23 Feb 2004
 

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)

About the Author

Pete2004
President Bioxing
United States United States
Member
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.

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
Hint: For improved responsiveness ensure Javascript is enabled and choose 'Normal' from the Layout dropdown and hit 'Update'.
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
GeneralDifference between DataSet and DataTable in asp.netmemberLalit24rocks15 May '13 - 19:45 
Difference between DataSet and DataTable in asp.net http://www.webcodeexpert.com/2013/03/difference-between-dataset-and.html
GeneralMy vote of 1memberCH Guravaiah17 Dec '12 - 0:16 
fhj,hk
Answerthanksmemberanhlada20027 Oct '08 - 16:15 
This article is useful with me.
GeneralArticals not found in this sectionmemberanu91411 Dec '07 - 3:59 
there are certain articles which are not found in this section. Please upload them since they are really useful.   Thank you
GeneralIndexingmemberIndexing service system26 Sep '05 - 23:12 
The search word c+++ is not working while using the Indexing servicing system..can u give me the solution...
GeneralRe: IndexingmemberPete200429 Sep '05 - 11:28 
Can you provide more details? I am not sure what you are trying to do?
Generaldownload this article as a single documentmembermooncow7 Feb '05 - 21:36 
it would be much more convenient to download this article with all its sections as a single document - it´s very detailled and helpful.
GeneralRe: download this article as a single documentmemberPete20048 Feb '05 - 4:44 
The complete document with all of its sections can be downloaded from my website: www.bioxing.com in the 'News' section.
GeneralRe: download this article as a single documentmemberferuzi18 Sep '05 - 6:02 
Thanks man, this doc is very helpful
GeneralRe: download this article as a single documentmembermysofttech6 Mar '06 - 19:41 
it is now in the http://www.bioxing.com/publications.htm
AnswerRe: download this article as a single documentmemberko_marek15 Apr '09 - 3:03 
A lot of thanks for Pete Smietana. Its very good, helpfull work. 1 sample is more valuable as 1000 words [especially in alien language ]   ko_marek
GeneralPopulating Datagrid using XMLmemberanilnair_m7 Jan '05 - 2: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) Regards
GeneralThanksmemberPhil_B29 Sep '04 - 15:15 
I found the DataTable, DataSet and DataGrid articles really helpful. Like most poeple I never fully understood what was going on because I just wanted to get it working asap and I had not come accross an easily readable explanation. Hence I had existed on code examples etc.  ...
General.ThankssussAnonymous29 Sep '04 - 15:08 
I found the articles(s) really helpful
GeneralRe: .Thanksmemberz1m9b65 Jan '06 - 13:54 
thank you very much
GeneralRe: .ThanksmemberPortatofe2 Oct '08 - 6:09 
I think you are totally right here. Good article   Cake Shop Cooking Dash Lost Secrets: Bermuda Triangle Cinema Tycoon 2: Movie Mania The Hidden Object Show: Season 2
GeneralWin XP and DataGridmembermsenkerik28 Sep '04 - 23:19 
In WinXP I can't to enter sign minus into textbox (on DataGrid) on NumericPad. In Win98,2000 it's OK.   Thanks.
QuestionHow to implemet of functionality of dataset in MyOwn Classmembershahzadarfan15 Jul '04 - 2:40 
Hi i want to myOwn Class in c# that give me the functionality as same as System.Data.Dataset in .NET i wnat to i try to implement interface IListSource,ISerilizable but i cannot do it Tell me if any one have knowledge about it Thanks shahzad
AnswerRe: How to implemet of functionality of dataset in MyOwn ClassmemberPete200415 Jul '04 - 6:53 
Are you attempting to write your own version of the DataSet class or do you want to inherent the DataSet class and then add additional methods and properties?
GeneralRe: How to implemet of functionality of dataset in MyOwn Classmembershahzadarfan15 Jul '04 - 21:45 
Yes I want to write my own version of DataSet class for it what i have to do Thanks shahzad
GeneralRe: How to implemet of functionality of dataset in MyOwn ClassmemberPete200416 Jul '04 - 4:55 
I am familar with, but I have not used any of the interfaces directly that you want information about, thus I am sorry but I will not be able to help you on your ambitious endeavor.   Good Luck.
GeneralSuggestions and CorrectionsmemberPete200425 Feb '04 - 5:35 
From the Author: I am updating the document correcting sections that were not clear and also adding new sections. If you have have suggestions and/or corrections do not hesitate to let me know. The goal is to provide a workable reference guide. Thanks.
GeneralFivememberNemanja Trifunovic24 Feb '04 - 19:12 
GeneralRe: Fivemembernetclectic24 Feb '04 - 23:34 
GeneralRe: FivememberRichard Boesiger25 Feb '04 - 0:39 

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

Permalink | Advertise | Privacy | Mobile
Web02 | 2.6.130516.1 | Last Updated 24 Feb 2004
Article Copyright 2004 by Pete2004
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid