I have a problem with my code regarding editing data in database using a DataGridView.
I have an error at da.update(dt); It says,
Dynamic SQL generation for the UpdateCommand is not supported against a SelectCommand that does not return any key column information.
When i change the SELECT to UPDATE/INSERT I get an error at da.fill(dt);.
What is wrong with my code?
Here's my code:
private void btnEdit_Click(object sender, EventArgs e) > {
con.Open();
DataTable dt = new DataTable();
SqlDataAdapter da = new SqlDataAdapter("SELECT * FROM RegistrationTable", con);
da.Fill(dt);
dt.Rows[dgvREGtable.CurrentRow.Index].BeginEdit();
dt.Rows[dgvREGtable.CurrentRow.Index][0] = tbFirstname.Text;
dt.Rows[dgvREGtable.CurrentRow.Index][1] = tbLastname.Text;
dt.Rows[dgvREGtable.CurrentRow.Index][2] = tbEmail.Text;
dt.Rows[dgvREGtable.CurrentRow.Index][3] = tbContacts.Text;
dt.Rows[dgvREGtable.CurrentRow.Index][4] = tbUsername.Text;
dt.Rows[dgvREGtable.CurrentRow.Index][5] = tbPassword.Text;
dt.Rows[dgvREGtable.CurrentRow.Index].EndEdit();
SqlCommandBuilder cb = new SqlCommandBuilder(da);
da.Update(dt);
displayrecords();
con.Close();
}