Hello,
How to fix the insertion problem in SQL EXPRESS
Database with CRUD operation with AUTO INCREMENT column, (Update and delete
operations) works fine.
I tried in the view to assign a value to AUTO INCREMENT Column (“Numero”), the <param> is not null but I get SQL error : SqlException : Cannot insert explicit value for identity column in table '' when IDENTITY_INSERT is set to OFF.
Thanks.
Below some information about this problem.
In the Controller :
public ActionResult InsertRemind([FromBody]CRUDModel<RappelsData> param)
{
db.RappelsDatas.Add(param.Value);
....
Param is null
In the Class Model :
public class RappelsData
{
[Key, DatabaseGenerated(DatabaseGeneratedOption.Identity)]
public int Numero { get; set; }....
//....
In the view
<ej-grid id="FlatGrid" is-responsive="true" allow-paging="true" action-complete="complete" action-begin="onBegin" record-double-click="onRecordDblClick" allow-text-wrap="true">
<e-datamanager json="(IEnumerable<object>)ViewBag.datasource" update-url="/Reminders/UpdateRemind" remove-url="/Reminders/DeleteRemind" insert-url="/Reminders/InsertRemind" adaptor="remoteSaveAdaptor" />
<e-edit-settings allow-adding="true" allow-deleting="true" allow-editing="true" show-delete-confirm-dialog="true" edit-mode="InlineFormTemplate" inline-form-template-id="#template" />
<e-toolbar-settings show-toolbar="true" toolbar-items="@(new List<string>() {"add","edit","delete","update","cancel" })"></e-toolbar-settings>
<e-columns>
<e-column field="Numero" header-text="No" is-primary-key="true" is-identity="true" allow-editing="false" text-align="Left" width="40"></e-column>
//....
</e-columns>
</ej-grid>
SQL Definition Table
CREATE TABLE [dbo].[RappelsData] (
[Numero] INT IDENTITY (1, 1) NOT NULL,
.....
PRIMARY KEY CLUSTERED ([Numero] ASC)
//....