Hey,
I currently have a dataGridView which displays information from my SQL database. I have a button that I use to update/add into the SQL database - for example a user ammends a field in the dataGridView this automatically updates the database.
I now want to implement a button that deletes the selected row from the database.
My dataGridView loadData:
private void LoadData()
{
string connectionString = @"Data Source=localhost\sqlexpress;Initial Catalog=coffee;Integrated Security=True;Pooling=False";
conn = new SqlConnection(connectionString);
sql = "SELECT * FROM coffeeType2";
da = new SqlDataAdapter(sql, conn);
conn.Open();
ds = new DataSet();
SqlCommandBuilder commandBuilder = new SqlCommandBuilder(da);
da.Fill(ds, "coffeeType2");
bsource.DataSource = ds.Tables["coffeeType2"];
dataGridView1.DataSource = bsource;
// this.dataGridView1.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
dataGridView1.AutoResizeColumns();
dataGridView1.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells;
}
Add/Update Button:
private void btnAdd_Click(object sender, EventArgs e)
{
DataTable dt = ds.Tables["coffeeType2"];
this.dataGridView1.BindingContext[dt].EndCurrentEdit();
this.da.Update(dt);
LoadData();
}
How can I now create a button to delete that particular row from the database?
Thank you.