Click here to Skip to main content
11,930,830 members (56,697 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as


3 bookmarked

DataBase Updation With DataGridView in simple steps

, 7 Dec 2011 CPOL
Rate this:
Please Sign up or sign in to vote.
Here is a step by step process to update database through datagridview in Windows applications


DataGridView control is used for displaying data from database. Display a table from the database on the DataGridView, usingDataAdapter and data logic. You can update the database from datagridView in a few simple steps.
Brief about DataAdapter: DataAdapter works as a bridge between DataSource and DataSet to save and fetch data.The Fill() method is used to load data in DataSet. A DataAdapter has various queries (In Properties) like:

  • SelectCommand
  • InsertCommand
  • DeleteCommand
  • UpdateCommand
Update() method is used for making changes in database.
OleDbDataAdapter is a sealed class that inherits abstract DbDataAdapter class and implements IDbDataAdapter, IDataAdapter, ICloneable interfaces.
Here is an example of OledbDataAdapter:
Example of DataAdapter:
Step 1
Create a Windows Application Project, and take a gridview on Windows form.
Step 2
Click on pin button on right-up side of datagridview and click add project DataSource and follow the simple steps:
->Choose DataSourceType database
->New Connection,
->make Connection
->Select Table and Column names
Step 3
Your dataSet has now been created. You can see it from Solution explorer.
When you create DataSet EmpTableAdapter and when you check the properties of this adapter, you will find Insert, Delete, Update, Select queries that are automatically generated as in Step 4.
Step 4
See the properties of Adapter on DataSet, whether it has query for Update or not. If not, add update query.
Step 5
A line is auto generated, when you bind datagrid to dataset as:
private void testGrid_Load(object sender, EventArgs e)
            // TODO: This line of code loads data into the 
            // 'gridTestDataSet.Emp' table. You can move, or remove it, as needed.
TheFill() method retrieves rows from the data source using the SELECT statement specified by an associated SelectCommand property of DataAdapter.
On Click event of Update button:
private void button3_Click(object sender, EventArgs e)
            //Update button update dataset after insertion, updation or deletion
            DialogResult dr = MessageBox.Show("Are you sure to save Changes",
            if (dr == DialogResult.Yes)
                MessageBox.Show("Record Updated");
Points of Interest
  • You can insert a row and click update button, row in database will be inserted.
  • If you update any cell and click update button, the database will be updated.
  • To delete, select rows and press Delete key and click update button, rows will be deleted.
*All your insertion, updation, deletion will be effected by a single button.


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


About the Author

Software Developer (Senior)
India India

A technology enthusiast and software developer by profession. He is developing .Net/database based enterprise applications from past 4 years.

His skills includes C# ,ASP.NET, ASP.NET MVC,WCF,JQuery,Javascript,SQL Server,Oracle . His areas of interests are database development and application software development using Microsoft Technologies.

Visit his blog:

Blog | Articles | Answers |Facebook
The best anti-virus is a smart user

You may also be interested in...

Comments and Discussions

GeneralReason for my vote of 1 .... Pin
Vijay Gill9-Dec-11 0:23
memberVijay Gill9-Dec-11 0:23 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    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
Web02 | 2.8.151126.1 | Last Updated 7 Dec 2011
Article Copyright 2011 by uspatel
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid