On my VS2015 Winforms
app, I created a DataGridView
along with a BindingNavigator
. The following code successfully displays the data in the DataGridView and I can navigate the data rows using the BindingNavigator. But when I try to add/delete a row using builtin Add/Delete buttons on the BindingNavigator the database does not reflect those changes.
The Code:
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}
SqlDataAdapter dadapter;
DataSet dset;
BindingSource bs;
string connstring = "database=emp;server=.;user=sa;password=wintellect";
private void Form2_Load(object sender, EventArgs e)
{
dadapter = new SqlDataAdapter("select * from emp_detail", connstring);
dset = new DataSet();
dadapter.Fill(dset);
bs = new BindingSource();
bs.DataSource = dset.Tables[0].DefaultView;
bindingNavigator1.BindingSource = bs;
dataGridView1.DataSource = bs;
}
}