private void btnAdd_Click(object sender, EventArgs e) { LinqDB data = new LinqDB(); for (int i = 1; i < 5; i++) { Category cat = new Category() { Category1 = "分类" + i }; data.Category.InsertOnSubmit(cat); } for (int i = 0; i < 100; i++) { Articles art = new Articles() { txtTitle = "title" + DateTime.Now.Second, txtContent = "内容" + DateTime.Now.Second, CategoryId = i % 3 }; data.Articles.InsertOnSubmit(art); } data.SubmitChanges(); dgv1.DataSource = data.Articles; }
private void btnDelete_Click(object sender, EventArgs e) { LinqDB data = new LinqDB(); int nowId = int.Parse(dgv1.CurrentRow.Cells[0].Value.ToString()); Articles art = data.Articles.First(a => a.Id == nowId); data.Articles.DeleteOnSubmit(art); data.SubmitChanges(); dgv1.DataSource = data.Articles; }
private void btnUpdate_Click(object sender, EventArgs e) { LinqDB data = new LinqDB(); int nowId = int.Parse(dgv1.CurrentRow.Cells[0].Value.ToString()); //int nowId = (dataGridView1.CurrentRow.DataBoundItem as Articles).Id; Articles art = data.Articles.First(a => a.Id == nowId); art.txtTitle = "改变后的东西" + DateTime.Now.ToString(); data.SubmitChanges(); dgv1.DataSource = data.Articles; }