protected void btnAdd_Click(object sender, EventArgs e) { GoodsTypeDataContext lq = new GoodsTypeDataContext(); //实例化LINQ类 GoodsType gt = new GoodsType(); //创建一个新对象 gt.tName = TextBox1.Text; lq.GoodsType.InsertOnSubmit(gt); //执行插入数据操作 lq.SubmitChanges(); //提交数据库 LoadData(); }
protected void btnDelete_Click(object sender, EventArgs e) { GoodsTypeDataContext lq = new GoodsTypeDataContext(); //实例化LINQ类 var types = from gt in lq.GoodsType where gt.tName == TextBox4.Text select gt; foreach (GoodsType type in types) { lq.GoodsType.DeleteOnSubmit(type); } lq.SubmitChanges(); LoadData(); }
protected void btnUpdate_Click(object sender, EventArgs e) { GoodsTypeDataContext lq = new GoodsTypeDataContext(); //实例化LINQ类 var types = from gt in lq.GoodsType where gt.tName == TextBox2.Text select gt; foreach (var type in types) //遍历集合 { type.tName = TextBox3.Text; } lq.SubmitChanges(); LoadData(); }