private void btnSave_Click(object sender, EventArgs e) { if (RoomID == 0) { try { this.Validate(); this.ValidateChildren(); RoomsTableAdapter roomsTableAdapter = new RoomsTableAdapter(); roomsTableAdapter.Insert( Convert.ToInt32(cbxRoomType.SelectedValue), Convert.ToByte(cbxRoomStatus.SelectedValue), tbxRoomNO.Text.Trim(), tbxFlow.Text.Trim(), tbxBuilding.Text.Trim()); MessageBox.Show("บันทึกเสร็จสมบูรณ์"); DialogResult = System.Windows.Forms.DialogResult.Yes; } catch (Exception ex) { Console.WriteLine(ex.ToString()); MessageBox.Show("ไม่สามารถบันทึกได้"); DialogResult = System.Windows.Forms.DialogResult.No; throw; } } else { try { this.Validate(); this.ValidateChildren(); this.roomsBindingSource.EndEdit(); this.roomsTableAdapter.Update(this.apartmentDataSet.Rooms); MessageBox.Show("บันทึกเสร็จสมบูรณ์"); DialogResult = System.Windows.Forms.DialogResult.Yes; } catch (Exception ex) { Console.WriteLine(ex.ToString()); MessageBox.Show("ไม่สามารถบันทึกได้"); DialogResult = System.Windows.Forms.DialogResult.No; throw; } } }