private void button1_Click(object sender, EventArgs e) { using (pclientEntities db = new pclientEntities()) { if (id == null) { pclient = new client(); } pclient.first_name = textBox1.Text; pclient.second_name = textBox2.Text; pclient.last_name = textBox3.Text; pclient.second_last_name = textBox4.Text; pclient.address = textBox5.Text; if (id == null) { db.client.Add(pclient); } else { db.Entry(pclient).State = System.Data.Entity.EntityState.Modified; } db.SaveChanges(); Close(); } }
public void GetList() { using (pclientEntities db = new pclientEntities()) { var listClient = from n in db.client select n; dataGridView1.DataSource = listClient.ToList(); } }
private void Data_Load() { using (pclientEntities db = new pclientEntities()) { pclient = db.client.Find(id); textBox1.Text = pclient.first_name; textBox2.Text = pclient.second_name; textBox3.Text = pclient.last_name; textBox4.Text = pclient.second_last_name; textBox5.Text = pclient.address; } }
private void button3_Click(object sender, EventArgs e) { int?id = GetId(); if (id != null) { using (pclientEntities db = new pclientEntities()) { client pclient = db.client.Find(id); db.client.Remove(pclient); db.SaveChanges(); } GetList(); } }