简体   繁体   中英

Adding UPDATE and DELETE functionality in DataGridView C#

How can i add update and delete functionality in DataGridView? I want to add 2 buttons with that functionality.

Here's how my DataGridView works:

const string filename = @"database.db";
const string sql = "select * from legal_tbl;";
var conn = new SQLiteConnection("Data Source=" + filename + ";Version=3;");
try
{
   conn.Open();
   DataSet ds = new DataSet();
   var da = new SQLiteDataAdapter(sql, conn);
   da.Fill(ds);
   DataTable dt = ds.Tables[0];
   this.data_view.DataSource = dt;
}
catch (Exception ex)
{
   MessageBox.Show(ex + "");
}

For Update functionality you need to write code for : RowEditing , RowUpdating and RowCancelingEdit

You also need to create EditItemTemplate in the grid code in aspx file.

For Delete functionality you need to write code for : RowDeleting

Refer this

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM