数据的增,改
private static void addQuery() { var db = new MYDBDataContext(); int count = db.Player.Where(c => c.name == "Aonaufly").Count(); if (count == 0) { var newPalyer = new Player { name = "Aonaufly", mylevel = 1 }; db.Player.InsertOnSubmit(newPalyer); db.SubmitChanges(); }}private static void modifyQuery() { var db = new MYDBDataContext(); int count = db.Player.Where(c => c.name == "Aonaufly").Count(); if (count == 1) { var existingPlayer = db.Player.First(); existingPlayer.mylevel = 7; db.SubmitChanges(); }}
注意 db.Player.First() 是查询Player表中的第一条数据,没有 name = "Aonaufly"的限制.