Introduction
This article shows how to insert, update, and delete records in a DataGridView in a C# Windows Forms application. In a previous article, we saw how to use a Chart Control in Windows Forms Application.
Let's Begin
- Create a new Windows Forms application.

- Create a database (named Sample). Add a table tbl_Record. The following is the table schema for creating tbl_Record.

- Create a form (named frmMain) and drop a Label, TextBox, Button, and DataGridView control from the ToolBox.

Now, go to frmMain.cs code and add the System.Data and System.Data.SqlClient namespaces.
frmMain.cs Code
In the preceding code, I created a dataGridView1_RowHeaderMouseClick Event for updating and deleting the selected record. When the user clicks on the Row Header of a row then the data present in the cell of the row is stored into the TextBoxes. The DisplayData() method fills in the data in the DataGridView.
The Clear() method clears the data present in the TextBox as well as in the ID(int) variable.
Final Preview
![Final Image]()
I hope you like it. Thanks.