DataGridView CodeSample - Editing Customers in NorthWind using DataGridView and SQL database

From Visual WebGui Wiki

Jump to: navigation, search


Contents

Overview

This CodeSample will demonstrate a simple DataGridView editing of a table stored in an SQL database, and updating back to the database. The demo uses the Customers table from the NorthWind sample database.

Samples of use

VB.NET Code

'There is no special code to show here... see demo application

C# Code

// There is no special code to show here... see demo application

The demo application

The demo app chooses not to allow direct adding of rows in the DataGridView itself, rather to supply an "Add" button and firing up a details form for the user to enter details on new customers. This is in general a much simpler approach than to allow direct adding of new records to the DataGridView, especially when there are one or more conditions that need to be met befor the record is added. Adding records directly on the DataGridView itself will make the code much more complicated when there are constraints on the SQL table, like identity columns, multiple foreign keys etc.

The application should work for version 6.2.4 and later of Visual WebGui, but version 6.3.11 and above is recommended.

Before using the application, please verify the database connection string, stored in web.config.

Tips and Tricks

Using alternate colors of rows

The effect of having every other row in the DataGridView colored differently, is accomplished by the use of DataGridView1.AlternatingRowsDefaultCellStyle

Rererences

Code samples

Personal tools