I have this piece of code which should be pretty straight forward.
private void btnSave_Click(object sender, EventArgs e)
{
try
{
using (SqlConnection sqlConn = new SqlConnection(connString))
{
sqlConn.Open();
using (SqlDataAdapter da = new SqlDataAdapter())
{
da.SelectCommand = new SqlCommand("SELECT Id, FirstName, LastName, TcReadOnly FROM PersonTable", sqlConn);
using (SqlCommandBuilder builder = new SqlCommandBuilder(da))
{
DataTable dt = (DataTable)dgvUsers.DataSource;
da.UpdateCommand = builder.GetUpdateCommand();
da.Update(dt);
}
}
}
}
catch (Exception ex)
{
MessageBox.Show("Der er sket en fejl \r\n \r\n" + ex.ToString());
}
}
However, I recieve this error when the code is run.
Line 96 in Userform being
da.Update(dt);
I have already checked that my SelectCommand return a primary in Id, so that shouldn't be the problem.