发一下牢骚和主题无关:
方法一:Attach方法
EmployeeDAL
/// <summary>
/// 更新员雇信息
/// </summary>
/// <param name="e"></param>
public void UpdateEmploee(Employee e)
{
try
{
dc.Employee.Attach(e);
dc.Refresh(RefreshMode.KeepCurrentValues, e);
dc.SubmitChanges(ConflictMode.ContinueOnConflict);
}
catch(Exception ex)
{
throw ex;
}
}
ThreeTierBLL
/// <summary>
/// 更新员雇信息
/// </summary>
/// <param name="e"></param>
public static void UpdateEmploee(Employee e)
{
new EmployeeDAL().UpdateEmploee(e);
}
Web
protected void btnSubmit_Click(object sender, EventArgs e)
{
Employee emp = new Employee();
emp.EmployeeID = this.txtEmpID.Text;
emp.EmployeeName = this.txtEmpName.Text;
emp.EmployeePhone = this.txtEmpPhone.Text;
emp.DepartmentID = Convert.ToInt32(this.txtDepID.Text);
EmployeeBLL.UpdateEmploee(emp);
}
方法二:读出现有字段,变动
DAL
/// <summary>
/// 根据工号修改手机号
/// </summary>
/// <param name="num">工号</param>
/// <param name="newphone">新的手机号</param>
public void ModifyCellPhoneByNum(string num, string newphone)
{
try
{
var stu = (from s in dc.TeacherBasicInformation
where s.TeacherNum == num
select s).FirstOrDefault();
stu.TeacherCellPhone = newphone;
dc.SubmitChanges();
}
catch
{ }
}
BLL
/// <summary>
/// 根据工号修改手机号
/// </summary>
/// <param name="num">工号</param>
/// <param name="newphone">新的手机号</param>
public static void ModifyCellPhoneByNum(string num, string newphone)
{
new TeacherDAL().ModifyCellPhoneByNum(num, newphone);
}
web
/// <summary>
/// 辑编中的更新
/// </summary>
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
if (((TextBox)GridView1.Rows[e.RowIndex].Cells[2].Controls[0]).Text.Trim() == "")
{
PageExtension.Alert(this, "新的手机号不能为空!");
}
else
{
TeacherBLL.ModifyCellPhoneByNum(GridView1.DataKeys[e.RowIndex].Value.ToString(),
((TextBox)GridView1.Rows[e.RowIndex].Cells[2].Controls[0]).Text.Trim());
this.GridView1.EditIndex = -1;
Bind();
}
}
文章结束给大家分享下程序员的一些笑话语录:
据说有一位软件工程师,一位硬件工程师和一位项目经理同坐车参加研讨会。不幸在从盘山公路下山时坏在半路上了。于是两位工程师和一位经理就如何修车的问题展开了讨论。
硬件工程师说:“我可以用随身携带的瑞士军刀把车坏的部分拆下来,找出原因,排除故障。”
项目经理说:“根据经营管理学,应该召开会议,根据问题现状写出需求报告,制订计划,编写日程安排,逐步逼近,alpha测试,beta1测试和beta2测试解决问题。”
软件工程说:“咱们还是应该把车推回山顶再开下来,看看问题是否重复发生。”