We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on : Nov 16th 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Cannot save new row to database via Entity Framework

Thread ID:

Created:

Updated:

Platform:

Replies:

123593 Apr 1,2016 05:30 PM UTC Apr 5,2016 02:54 AM UTC WPF 1
loading
Tags: SfDataGrid
john mullally
Asked On April 1, 2016 05:30 PM UTC

I am using VS 2013 .Net Framework 4.5.1 and a recent update to Syncfusion.

I am using the SfDataGrid with AddNewRowPosition and a Save button.  My configuration, which is as simple as I can make it, allows me to edit and save existing rows in the Northwind Category table.  
Although I can add rows to the grid, the new rows are not being saved.



Attachment: WpfApplication15_a0a3b110.zip

Jayapradha S [Syncfusion]
Replied On April 5, 2016 02:54 AM UTC

Hi John,

Thank you for contacting Syncfusion Support.

You can add  a new record in AddNewRow and you can update the database using  RowValidatingEvent like below,

this.SfDataGrid1.RowValidating += SfDataGrid1_RowValidating;

void SfDataGrid1_RowValidating(object sender, Syncfusion.UI.Xaml.Grid.RowValidatingEventArgs args)

        {

            Category newRecord = args.RowData as Category;

            Category category = new Category();

            category.Description = newRecord.Description;

            using(Entities entity=new Entities())

            {

                entity.Categories.Add(category);

                entity.SaveChanges();

            }
        }


Please refer the below reference links to add a new record using DBContext,

Reference Links: http://www.entityframeworktutorial.net/EntityFramework4.3/add-entity-using-dbcontext.aspx
http://www.entityframeworktutorial.net/EntityFramework4.3/add-entity-using-dbcontext.aspx
 
We are unable to run your attached sample. Since in that attachment, db is missing. If you are facing any problem with above code snippet, then you please share your sample with db.

Regards,
Jayapradha






CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

;