KeyNotFoundException: The given key was not present

This public forum is for user-to-user discussions of ASP.NET Maker. Note that this is not support forum.
Post Reply
ConstanceLake
User
Posts: 37

KeyNotFoundException: The given key was not present

Post 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


motfs
User
Posts: 258

Post 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.


ConstanceLake
User
Posts: 37

Post 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


motfs
User
Posts: 258

Post 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.


Post Reply