I have somehow a problem to update my SQL Server database. I got an "Update" button so the user can change values manually in a DataGridView and then should click a button to save the changes to the database. I use the "Update" command for that but don't know how to manage it.
The button:
private void update_Click(object sender, EventArgs e)
{
sqlCmdBuilder = new SqlCommandBuilder(sqlDatAdapter);
dataGridView1.DataSource = datTable;
sqlDatAdapter.Fill(datTable);
sqlDatAdapter.Update(datTable);
}
The database gets loaded via another function. In my code I get a NullReferenceException
.
How can I catch the existing DataGrid and then register the users changes?
When I define the SqlDatAdapter
in the method then the exception doesn't occur anymore but it does absolutely nothing.