Page 1 of 1

KeyNotFoundException: The given key was not present

Posted: Thu May 31, 2018 6:00 pm
by ConstanceLake

Hi all, just started to evaluate ASP.NET Maker, but struggling with a fundamental problem. Would like to build a table maintenance dialogue like "trademarks" of demo2018: Add new rows, without adding ID, ID needs to be updated automatically. We built exactly what has been configured for table "trademarks" of demo2018. Always get the error "KeyNotFoundException: The given key was not present in the dictionary". I assume a code snippet is missing which updates the primary key automatically with referential integrity.

Sorry may be for the stupid question.

Best regards, Thomas


Re: KeyNotFoundException: The given key was not present in t

Posted: Fri Jun 01, 2018 11:55 am
by motfs

Add new rows, without adding ID, ID needs to be updated automatically.

Make sure you setup your key field as AutoIncrement field in your database. Then sync your project with your database. The autoinc primary key will be excluded from the Add page and hence no KeyNotFoundException. If your primary is not autoinc, you must provide a valid value when you insert record or key not found.


Re: KeyNotFoundException: The given key was not present in t

Posted: Fri Jun 01, 2018 11:15 pm
by ConstanceLake

Hi motfs,

thanks for your response. Yes, this option is working fine. But is there also a solution inside ASP.NET Maker to do this job? Don't want to change the PK settings in my whole data model. I'm looking for a code snippet to update the PK by adding data, also for joined tables. Furthermore don't know where to include this code in ASP.NET Maker because I have just started with evaluation of this tool.

Best regards, Thomas


Re: KeyNotFoundException: The given key was not present in t

Posted: Sat Jun 02, 2018 9:23 am
by motfs

motfs wrote:
If your primary is not autoinc, you must provide a valid value when you insert record or key not found.

You can use the Row_Inserting server event to update the key field. Read Server Events and Client Scripts -> Server Events -> Row_Inserting in help file for more detail.