private void btnUpdate_Click(object sender, EventArgs e) { Employee upEmp = new Employee(); upEmp.FullName1 = tbxFullName.Text; upEmp.ShortName1 = tbxShortName.Text; upEmp.Title1 = cbxTitle.Text; upEmp.OfficePhone1 = cbxOfficePhone.Text; upEmp.HomePhone1 = mtbHomePhone.Text; upEmp.MobilePhone1 = mtbMobilePhone.Text; upEmp.DateOfBirth1 = Convert.ToDateTime(mtbxDoB.Text); upEmp.Active1 = cbxActive.Text; upEmp.Type1 = cbxType.Text; upEmp.EmergPhone1 = mtbContactPhone.Text; upEmp.EmergContact1 = tbxEmergContact.Text; int index = empMainListView.SelectedItems[0].Index; List<Employee> empUpdate = dbconnect.Load(); upEmp.ID1 = empUpdate[index].ID1; dbconnect.Update(upEmp); }
public void Update(Employee upEmp) { try { dbcommand.CommandText = "UPDATE tblEmployee SET FullName=@vFullName, ShortName=@vShortName, Title=@vTitle, OfficePhone=@vOffice, HomePhone=@vHome, MobilePHone=@vMobile, DateOfBirth=@vDob, Type=@vType, Active=@vActive, EmergPhone=@vEPhone, EmergContact=@vEContact WHERE ID=@vID"; dbcommand.Parameters.AddWithValue("@vFullName", upEmp.FullName1); dbcommand.Parameters.AddWithValue("@vShortName", upEmp.ShortName1); dbcommand.Parameters.AddWithValue("@vTitle", upEmp.Title1); dbcommand.Parameters.AddWithValue("@vOffice", upEmp.OfficePhone1); dbcommand.Parameters.AddWithValue("@vHome", upEmp.HomePhone1); dbcommand.Parameters.AddWithValue("@vMobile", upEmp.MobilePhone1); dbcommand.Parameters.AddWithValue("@vDob", upEmp.DateOfBirth1); dbcommand.Parameters.AddWithValue("@vType", upEmp.Type1); dbcommand.Parameters.AddWithValue("@vActive", upEmp.Active1); dbcommand.Parameters.AddWithValue("@vEPhone", upEmp.EmergPhone1); dbcommand.Parameters.AddWithValue("@vEContact", upEmp.EmergContact1); dbcommand.Parameters.AddWithValue("@vID", upEmp.ID1); dbcommand.CommandType = System.Data.CommandType.Text; dbconnect.Open(); dbcommand.ExecuteNonQuery(); } catch (Exception ex) { System.Windows.Forms.MessageBox.Show(ex.Message); } finally { dbconnect.Close(); } }