linq to sql修改数据库
/// <summary>/// 修改记录
/// </summary>
/// <param name="item"></param>
/// <returns></returns>
public bool Update(Employee item)
{
using (DataClassesDataContext db = new DataClassesDataContext())
{
try
{
//取出记录
var item_ = db.Employee.SingleOrDefault<Employee>(i => i.emp_id == item.emp_id);//
if (item_ != null)
{
//foreach (PropertyInfo pi in item.GetType().GetProperties())
//{
// if (pi.Name == "emp_id")
// {
// continue;//主码不替换
// }
// foreach (PropertyInfo pi_ in item_.GetType().GetProperties())
// {
// if (pi_.Name == pi.Name)
// {
// string value=pi.GetValue(item).ToString();
// if (value != null)
// {
// //?????????????????????求教这里如何实现下面的枚举赋值
// }
// break;
// }
// }
//}
if (item.empro_id != null)
{
item_.empro_id = item.empro_id;
}
if (item.emp_password != null)
{
item_.emp_password = item.emp_password;
}
if (item.emp_name != null)
{
item_.emp_name = item.emp_name;
}
if (item.emp_sex != null)
{
item_.emp_sex = item.emp_sex;
}
if (item.emp_headportraitPath != null)
{
item_.emp_headportraitPath = item.emp_headportraitPath;
}
if (item.emp_phone != null)
{
item_.emp_phone = item.emp_phone;
}
if (item.emp_address != null)
{
item_.emp_address = item.emp_address;
}
if (item.emp_email != null)
{
item_.emp_email = item.emp_email;
}
if (item.emp_idcard != null)
{
item_.emp_idcard = item.emp_idcard;
}
if (item.emp_addTime != null)
{
item_.emp_addTime = item.emp_addTime;
}
if (item.emp_updateTime != null)
{
item_.emp_updateTime = item.emp_updateTime;
}
if (item.emp_lastTimeLogin != null)
{
item_.emp_lastTimeLogin = item.emp_lastTimeLogin;
}
if (item.emp_thisTimeLogin != null)
{
item_.emp_thisTimeLogin = item.emp_thisTimeLogin;
}
db.SubmitChanges();
}
return true;
}
catch
{
return false;
}
}
} linq to sql --------------------编程问答-------------------- pi_.SetValue() --------------------编程问答-------------------- 之前我也试过SetValue()没那么简单的,参数很复杂 --------------------编程问答--------------------
和参数复杂没有关系。
补充:.NET技术 , ASP.NET