Click here to Skip to main content
15,912,069 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I want to make a master detail entry form in WPF by using entity framework. Now my question is how to insert multiple rows from DataGrid to Sql Database when user press save button. And I want to bind datagrid with database by using entity framework.

What I have tried:

I want to make a master detail entry form in WPF by using entity framework. Now my question is how to insert multiple rows from DataGrid to Sql Database when user press save button. And I want to bind datagrid with database by using entity framework.
Posted
Updated 20-Apr-18 1:46am

1 solution

Well,I have worked a little with Entity Framework and I can tell you that is not so different from working with normal sql queries.First thing that you have to do is to declare the name of the db entity that you are using:
e.g-
using(DBDemoEntites db=new DBDemoEntites())
{
}

then you have to instantiate the table(tables) that you want to insert the values into.For e.g if you want to insert the data into table Fruits:
Fruits d=new Fruits();

then with the reference from the table you start passing values from the datagrid in the view into the database like this:
d.firstValue=firstValue;
d.secondValue=secondValue;

etc.
After you do this, you save all the values into the table like this:
db.Fruits.Add(d);

Finally you save everything into the database:
db.SaveChanges();


This is how I save values into the db with Entity Framework.Try this and see if it helps.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900