# 创建linq to sql类 private void search_Click(object sender, EventArgs e) { linqtosqlDataContext linq = new linqtosqlDataContext(connStr); var result = from stu in linq.Students select stu.StuName; listBox1.DataSource = result; } private void insert_Click(object sender, EventArgs e) { linqtosqlDataContext linq = new linqtosqlDataContext(connStr); Student stu = new Student(); stu.StuName = "kyle"; linq.Students.InsertOnSubmit(stu); linq.SubmitChanges(); } private void delete_Click(object sender, EventArgs e) { linqtosqlDataContext linq = new linqtosqlDataContext(connStr); var result = from stu in linq.Students where stu.StuName == "kyle" select stu; linq.Students.DeleteAllOnSubmit(result); linq.SubmitChanges(); } private void update_Click(object sender, EventArgs e) { linqtosqlDataContext linq = new linqtosqlDataContext(connStr); var result = from stu in linq.Students where stu.StuName == "kyle" select stu; foreach(var s in result) { s.StuName = "bob"; linq.SubmitChanges(); } } private void search2_Click(object sender, EventArgs e) { linqtosqlDataContext linq = new linqtosqlDataContext(connStr); var result = from stu in linq.Students from coz in linq.Stu_Coz where stu.StuId == czo.SId select stu; }
使用LINQ进行CRUD
猜你喜欢
转载自www.cnblogs.com/jizhiqiliao/p/9807790.html
今日推荐
周排行