hello. I write this code in my project but when I change a value in my application,appeared a exception and don't update my database,this code work for new but dont work for delete and edit data.
CODE :
private void btnLecOk_Click(object sender, EventArgs e)
{
DataRow dr = (lecturesBindingSource.Current as DataRowView).Row;
dr["Section_ID"] = Convert.ToInt32(cmbLec_Section_Name.SelectedValue);
dr["Lecture_Type_ID"] = Convert.ToInt32(cmbLec_Lecture_Type.SelectedValue);
dr["Practicable_Unit"] = numLec_Practicable_Unit.Value;
dr["theoretical_Unit"] = numLec_Theoretical_Unit.Value;
dr["Term"] = numLec_Term.Value;
lecturesBindingSource.EndEdit();
lecturesTableAdapter.Update(dsSchedule.Lectures);
EnableLectureControls();
}
Exception :
System.Data.DBConcurrencyException was unhandled Message="Concurrency violation: the UpdateCommand affected 0 of the expected 1 records." Source="System.Data" RowCount=1
Sql query foe update :
UPDATE Lectures SET Lecture_Code = @Lecture_Code, Section_ID = @Section_ID, Lecture_Type_ID = @Lecture_Type_ID, Lecture_Name = @Lecture_Name, Practicable_Unit = @Practicable_Unit, theoretical_Unit = @theoretical_Unit, Lecture_Capacity = @Lecture_Capacity, Term = @Term WHERE (Lecture_Code = @Original_Lecture_Code) AND (Section_ID = @Original_Section_ID) AND (Lecture_Type_ID = @Original_Lecture_Type_ID) AND (Lecture_Name = @Original_Lecture_Name) AND (Practicable_Unit = @Original_Practicable_Unit) AND (theoretical_Unit = @Original_theoretical_Unit) AND (Lecture_Capacity = @Original_Lecture_Capacity) AND (Term = @Original_Term)