I have a datagridview that adds the table data using code, I want to delete a row of data and have it update in the database table also. How do I do this? Any tips?
The code is presented below:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.Sql;
using System.Data.SqlClient;
namespace project
{
public partial class frmTestPrint : Form
{
//with code
SqlConnection cn = new SqlConnection("Data Source=(LocalDB)\\v11.0;AttachDbFilename=F:etc");
SqlDataAdapter da;
DataTable dt = new DataTable();
public frmTestPrint()
{
InitializeComponent();
}
//with code
private void BindDataGridView2()
{
string command = "select * from booking";
da = new SqlDataAdapter(command,cn);
da.Fill(dt);
dataGridView2.DataSource = dt;
}
private void frmTestPrint_Load(object sender, EventArgs e)
{
//with code
BindDataGridView2();
}
private void btnDelete_Click(object sender, EventArgs e)
{
}
}
}
I have tried many different ways and am stuck, I really need some assistance to guide me through this so if anyone can assist please do.