标签:style blog io color os sp 数据 div on
1. 新增
public bool DataAdd(USER model) { bool isSuccess = false; try { using (DataBaseEntities db = new DataBaseEntities()) { db.USER.AddObject(model); isSuccess = db.SaveChanges() > 0; } } catch (Exception ex) { Console.WriteLine("异常信息:"+ex.Message); } return isSuccess; }
2. 删除
public bool DataDelete(USER model) { bool isSuccess = false; try { using (DataBaseEntities db = new DataBaseEntities()) { db.USER.DeleteObject(model); isSuccess = db.SaveChanges() > 0; } } catch (Exception ex) { Console.WriteLine("异常信息:" + ex.Message); } return isSuccess; }
3. 修改
public bool DataEditor(USER model) { bool isSuccess = false; try { using (DataBaseEntities db = new DataBaseEntities()) {
//只有在 DataBaseEntities 对象没有被释放时,才能实时更新对应的数据 USER user = db.USER.First(p => p.ID == model.ID); user.NAME = model.NAME; isSuccess = db.SaveChanges() > 0; } } catch (Exception ex) { Console.WriteLine("异常信息:" + ex.Message); } return isSuccess; }
4. 查询
public List<USER> DataSelect() { List<USER> list = new List<USER>(); try { using (DataBaseEntities db = new DataBaseEntities()) { list = db.USER.ToList(); } } catch (Exception ex) { Console.WriteLine("异常信息:" + ex.Message); } return list; }
标签:style blog io color os sp 数据 div on
原文地址:http://www.cnblogs.com/me-code/p/4104128.html