Introduction
A DataGridView control can be used to display data from a database. A table can be displayed from a database in a DataGridView, using the DataAdapter class and data logic. You can easily update a database from a DataGridView.
Step 1
Create a Windows Forms Application Project, and place a DataGridView on the form.
Step 2
Click on the pin button on right-up side of DataGridView and click add project DataSource. And follow these simple steps.
- Choose DataSourceType Database
- New Connection, Make Connection
- Select Table and Column names
- Finish


Step 3
Your DataSet now has been created. You can see it from the Solution Explorer. 
Step 4
See the properties of the Adapter on DataSet, whether it has a query for updating or not. If not then add an update query.
Step 5
A line is automatically generated, when you bind the DataGridView to the 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.
this.empTableAdapter.Fill(this.gridTestDataSet.Emp);
}
On Click Event of Update button
private void button3_Click(object sender, EventArgs e)
{
//Update button update dataset after insertion,upadtion or deletion
DialogResult dr = MessageBox.Show("Are you sure to save Changes", "Message", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Information);
if (dr == DialogResult.Yes)
{
this.empTableAdapter.Update(gridTestDataSet.Emp);
dataGridView1.Refresh();
MessageBox.Show("Record Updated");
}
}
Points of Interest
You can insert a row and click the update button; a row in the database will be inserted.
If you update any cell and click the update button, then the database will be updated.
To delete, select the rows and then press the Delete key and click the update button; the rows will be deleted. All your insertions, updates, and deletions will be effected by the single button.

Krishna Rajput SinghPosted Mar 26, 2016, 5:42 AM
dipak shah for you i hope help for you http://www.c-sharpcorner.com/UploadFile/a5f59f/how-to-create-log-in-form-in-visual-studio-and-connection-wi/ if need more ask me question
lbs yinPosted Feb 12, 2014, 1:50 PM
very good
dipak shahPosted Sep 8, 2013, 2:22 PM
my mail id is [email protected] so please help in above query....
dipak shahPosted Sep 8, 2013, 2:21 PM
in my tableadapter properties not displayed properties like step 4 in above example.then what the error i have ...please help me...sir...thanks in advanced
Mohammed GamalPosted Dec 18, 2012, 4:46 AM
i like this article, but i have a question by this method how can i make a SQL query ?
Thabang SesediPosted Oct 4, 2012, 6:33 PM
It wont update
Thabang SesediPosted Oct 4, 2012, 6:33 PM
It wont update
Thabang SesediPosted Oct 4, 2012, 6:33 PM
It wont update
Anubhav sahuPosted Sep 6, 2012, 7:32 AM
nice....
Sunil SharmaPosted Aug 27, 2012, 12:25 PM
very simple
Bhushan InjePosted Mar 26, 2012, 7:37 AM
it is very nice code and trick
Sonakshi SinghPosted Feb 6, 2012, 10:57 PM
Useful for me
Dinesh BeniwalPosted Jan 6, 2012, 11:41 PM
Good start, Welcome to the C# Corner.
Akash AhlawatPosted Jan 6, 2012, 11:07 PM
Well done
Arjun PanwarPosted Jan 6, 2012, 11:05 PM
Thanks for sharing