I am having a hard time figuring out how to delete a row from the datagridview using a datasource that will also delete the row in SQL Database.
public partial class Form1 : Form
{
const String sStr = "Server= ************;Database=***; Integrated Security=SSPI";
SqlConnection sConn;
SqlDataAdapter daCourse;
DataSet ds;
SqlCommandBuilder cb;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
sConn = new SqlConnection(sStr);
daCourse = new SqlDataAdapter("SELECT * from Course ", sConn);
ds = new DataSet();
daCourse.Fill(ds, "Course");
dgvCourse.DataSource = ds.Tables["Course"];
}
private void btnDelete_Click(object sender, EventArgs e)
{ [B]THIS PART DOES DELETE FROM DATAGRIDVIEW BUT NOT IN MSSQL DB[/B]
//remove the row from datagridview
dgvCourse.Rows.Remove(dgvCourse.CurrentRow);
ds.Tables["Course"].AcceptChanges();
daCourse.Update(ds, "Course");
}
}
Thanks to all who can help :)