Web Forms DataGrid and DataSet Programming

Introduction

This is a working C# .NET program that demonstrates how to integrate most of the features of the DataGrid and DataSet in a single project including select, insert, update, delete, confirm delete, sort, filter and page. This is a work in progress and feedback is an important factor in improving this tutorial. Please report any bugs and I will try to fix them.

A few general concepts are presented here and represent my best understanding of how the DataSet and DataGrid works.

The SqlDataAdapter provides a bridge between the DataSet and the data source. Calling Fill, refreshes the data in the DataSet. Calling Update, attempts to commit any changes in the DataSet. The SqlDataAdapter wizard simplifies building of data driven forms by automatically generating UPDATE, INSERT and DELETE statements from your SqlDataAdapter SELECT statement. By default, the UPDATE statement implements an Optimistic Concurrency scheme that looks for an unaltered row on UPDATE.

The DataSet can encapsulate a parent child hierarchy of zero or more data tables. The DataSet also stores its state, storing both the @original values and any new uncommitted values. These original values are used to enforce "Optimistic Concurrency" by searching for unaltered rows on UPDATE. Unlike the DataGrid, the DataSet does _not_ persist itself on post back.

The DataGrid is used to display data in the HTML page. If DataGrid paging is not enabled, the DataGrid will display all of the rows in the appropriate table in the corresponding DataSet. To enable sorting and filtering, the DataGrid is bound to a View, not to the DataSet.

The View is used to sort and filter data in the DataSet before it is passed to the DataGrid using the properties:

view.RowFilter
view.Sort

The data path looks like this:

DataBase --> DataSet --> View --> DataGrid

You might also like...

Comments

Contribute

Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“Java is to JavaScript what Car is to Carpet.” - Chris Heilmann