private void btnEdit_Click(object sender, EventArgs e) { if (txtID.Text == "") { MessageBox.Show("请选择要修改的记录"); return; } linq = new linqtosqlClassDataContext(strCon);//实例化Linq连接对象 //查找要修改的员工信息 var result = from employee in linq.tb_Employee where employee.ID == txtID.Text select employee; //对指定的员工信息进行修改 foreach (tb_Employee tbemployee in result) { tbemployee.Name = txtName.Text; tbemployee.Sex = cboxSex.Text; tbemployee.Age = Convert.ToInt32(txtAge.Text); tbemployee.Tel = txtTel.Text; tbemployee.Address = txtAddress.Text; tbemployee.QQ = Convert.ToInt32(txtQQ.Text); tbemployee.Email = txtEmail.Text; linq.SubmitChanges(); } MessageBox.Show("员工信息修改成功"); BindInfo(""); }
private void btnDel_Click(object sender, EventArgs e) { if (txtID.Text == "") { MessageBox.Show("请选择要删除的记录"); return; } linq = new linqtosqlClassDataContext(strCon);//实例化Linq连接对象 //查找要删除的员工信息 var result = from employee in linq.tb_Employee where employee.ID == txtID.Text select employee; linq.tb_Employee.DeleteAllOnSubmit(result); //删除员工信息 linq.SubmitChanges(); //实例化Linq连接对象提交操作 MessageBox.Show("员工信息删除成功"); BindInfo(""); }
private void btnAdd_Click(object sender, EventArgs e) { linq = new linqtosqlClassDataContext(strCon); //实例化Linq连接对象 tb_Employee employee = new tb_Employee(); //实例化tb_Employee类对象 //为tb_Employee类中的员工实体赋值 employee.ID = txtID.Text; employee.Name = txtName.Text; employee.Sex = cboxSex.Text; employee.Age = Convert.ToInt32(txtAge.Text); employee.Tel = txtTel.Text; employee.Address = txtAddress.Text; employee.QQ = Convert.ToInt32(txtQQ.Text); employee.Email = txtEmail.Text; linq.tb_Employee.InsertOnSubmit(employee); //添加员工信息 linq.SubmitChanges(); //提交操作 MessageBox.Show("员工信息添加成功"); BindInfo(""); }