private void btnSave_Click(object sender, EventArgs e) { // save changes to the data field to the currently selected pkid record int param = GetSelectedPKID(); if (param > 0) { using (TestEFDeployEntities ctx = new TestEFDeployEntities(this.connstr)) { TestTable savethis = (from rows in ctx.TestTables where rows.pkid == param select rows).FirstOrDefault(); savethis.DataValue = txtData.Text; ctx.SaveChanges(); } } }
private void btnNew_Click(object sender, EventArgs e) { //create new testtable object //save it, letting the identity 1, 1 get set //reload listbox, go to appropriate index //focus one data textbox int myid = 0; TestTable newtt = new TestTable(); //create the new record, get the pkid using (TestEFDeployEntities db = new TestEFDeployEntities(connstr)) { db.TestTables.Add(newtt); db.SaveChanges(); myid = newtt.pkid; } //reload the listbox LoadListbox(); }