Exemplo n.º 1
0
        private void buttonSave_Click(object sender, EventArgs e)
        {
            TestDBDataContext dc = new TestDBDataContext();

            if (textBoxNo.ReadOnly == false)//Insert
            {
                Employee obj = new Employee();
                obj.ID      = int.Parse(textBoxNo.Text);
                obj.Name    = textBoxName.Text;
                obj.City    = textBoxCity.Text;
                obj.Address = textBoxAddress.Text;
                dc.Employees.InsertOnSubmit(obj);
                dc.SubmitChanges();
                MessageBox.Show("Records inserted into the table");
            }
            else//Update
            {
                Employee obj = dc.Employees.SingleOrDefault(E => E.ID == int.Parse(textBoxNo.Text));
                obj.Name    = textBoxName.Text;
                obj.City    = textBoxCity.Text;
                obj.Address = textBoxAddress.Text;
                dc.SubmitChanges();
                MessageBox.Show("Record updated in table");
            }
        }
Exemplo n.º 2
0
 private void buttonDelete_Click(object sender, EventArgs e)
 {
     if (dgView.SelectedRows.Count > 0)
     {
         if (MessageBox.Show("Are you sure of deleting the selected row?", "Conformation", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
         {
             int      ENo = Convert.ToInt32(dgView.SelectedRows[0].Cells[0].Value);
             Employee obj = dc.Employees.SingleOrDefault(E => E.ID == ENo);
             dc.Employees.DeleteOnSubmit(obj);
             dc.SubmitChanges();
             LoadData();
         }
     }
     else
     {
         MessageBox.Show("Please select record for deletion.", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }