Entity Framework in WPF

Posted by .Netlearner under WPF on 6/11/2013 | Points: 10 | Views : 1329 | Status : [Member] | Replies : 0
Hi all,
i have created s sample table tbluser with id,name , gender, age as its fields. ID is the primary key and its auto increment is set to true.I have added entitydatamodel for the tbluser in wpf application and the data is displaying perfectly. i want to edit and delete and insert data to the tbluser using entity datamodel. i added data am not sure how to update data and delete data

i tried the following code for delete,

 if (user == null)
MessageBox.Show("Cannot delete the blank Entry");
MessageBox.Show("Record Deleted..");

But it throws error that The object cannot be deleted because it was not found in the ObjectStateManager.
I have writern following code to update data
  if (isUpdateMode) //The Row is  edited
tbltest2 TempUser = (from usr in context.tbltest2
where usr.Id == user.Id
select usr).First();

FrameworkElement element_1 = grid.Columns[1].GetCellContent(e.Row);
if (element_1.GetType() == typeof(TextBox))
var xxName = ((TextBox)element_1).Text;
user.Name = xxName;
FrameworkElement element_2 = grid.Columns[2].GetCellContent(e.Row);
if (element_2.GetType() == typeof(TextBox))
var yyGender = ((TextBox)element_2).Text;
user.Gender =yyGender;
FrameworkElement element_3 = grid.Columns[3].GetCellContent(e.Row);
if (element_3.GetType() == typeof(TextBox))
var yyage = ((TextBox)element_3).Text;
user.Age = Convert.ToInt16(yyage);



but instead of update its adding new record. Kindly please guide me.How to check the duplicate rows while inserting ? How to update ? how to delete?


(No response found.)

Login to post response