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

Autoincrement column not updating on insert

Thread ID:

Created:

Updated:

Platform:

Replies:

118664 Mar 30,2015 08:41 PM UTC Apr 2,2015 06:06 AM UTC ASP.NET MVC 3
loading
Tags: Grid
Holger Schade
Asked On March 30, 2015 08:41 PM UTC

Hello,

I am struggeling to use the MVC Grid when I try to insert a row with an Autoincrement Column. The Grid works o.k. when updating and deleting a row. However, when I insert a new row, the Autoincrement Column remains empty in the Grid. The autoincrement column is marked with the isIdentity and the isPrimaryKey attributes:

            col.Field("ID").HeaderText("ID").IsPrimaryKey(true).IsIdentity(true).TextAlign(TextAlign.Right).Width(30).Add();

I use a remoteSaveAdaptor to do the updates:


        .Datasource(ds => ds.Json((IList<Fehlzeiten.Models.SystemUser>)ViewBag.datasource).Adaptor(AdaptorType.RemoteSaveAdaptor).InsertURL("DialogInsert").UpdateURL("DialogUpdate").RemoveURL("DialogDelete"))

 and when Inserting the Row  I use a Controller Method to update the database. The controller method is very simple:


         public ActionResult DialogInsert(Fehlzeiten.Models.SystemUser value)
        {
            int val = value.Insert();  // val contains the Autoincrement ID of the newly created Row 
            var data = value.GetList();  // This returns an IList<object>
            return Json(data, JsonRequestBehavior.AllowGet);
        }

The variable data in the controller method "DialogInsert" contains all rows from the database including the newly created row. How can I refresh the DataSource of the grid, so that the new Row will be completely shown in the grid - including the Autoincrement value?


Is there somewhere a sample how this is done?



Ajith R [Syncfusion]
Replied On March 31, 2015 06:14 PM UTC

Hi Holger,

Thanks for using Syncfusion products.

Query : How can I refresh the DataSource of the grid, so that the new Row will be completely shown in the grid - including the Autoincrement value?

We are sorry to let you know that we are unable to reproduce your reported issue. We suspect that you have not set the IDENTITY to the corresponding data field in your database which is the cause of the issue. We have to compute the set of modified inserted objects in the database by using SubmitChanges function for the auto increment value. Please refer the below code snippet for further details.

[Northwind.designer.cs]

[global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_OrderID", AutoSync=AutoSync.OnInsert, DbType="Int NOT NULL IDENTITY", IsPrimaryKey=true, IsDbGenerated=true)]

public int OrderID

{

---------

---------

}

[controller]

public ActionResult DialogInsert(OrdersView value)

{

var ds = new NorthwindDataContext();

ds.OrdersViews.InsertOnSubmit(value);

ds.SubmitChanges();

var jsonData = OrderRepository.GetEditable(value);

return Json(jsonData, JsonRequestBehavior.AllowGet);

}

For your convenience we have created a simple sample and the same can be downloaded from the below link.

Sample Link: http://www.syncfusion.com/downloads/support/forum/118664/IdentityRemoteUrlGrid-161444319.zip

Please let us know if you have any concerns.


Regards,

Ajith R


Holger Schade
Replied On April 1, 2015 02:56 PM UTC

Hello Ajith,

I checked your sample and it works. However you are using an Entity Framework Datamodel or Linq to SQL with the respective attributes. For some reasons this is not possible for me, as I accessing the database by pure ADO.NET. 

Anyhow I now used a workaround by reloading the Grid with the ClientSideEvent EndAdd. So I modified the grid

        .ClientSideEvents(ev => ev.EndAdd("endAddFunc"))

and added the following script:

    <script type="text/javascript">
           function endAddFunc() {
                $("#Editing").ejGrid("refreshContent");
           }
     </script>

which works perfectly well. Thanks for your effort.
 

Ajith R [Syncfusion]
Replied On April 2, 2015 06:06 AM UTC

Hi Holger,

Thanks for your update.

We are happy to hear that your requirement has been achieved in your end.

Please get back to us if you have any other concerns.

Regards,
Ajith R

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

;