Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How to retrieve the new primary key?
Message
General information
Forum:
ASP.NET
Category:
The Mere Mortals .NET Framework
Miscellaneous
Thread ID:
00809477
Message ID:
00810489
Views:
16
Stephen,

The default values are not used by ADO.NET to store the values before performing the update. That is handled by the SQL Server. When you set the flag in MMF to retrieve the primary key, it appends a select statement to the insert. Are you building you own insert statement or are you having MMF use the commandbuilder? If using the commandbuilder, you will want to set the default values of the fields or set AllowNulls to true.

>Cathi
>
>My primary is Integer and Identity is true. The error is not on the primary key, it's on an integer field called "irecversion". "irecversion" field store the version of the record and defaulted to 0 (set on SQL Server) when created. Here is what I found:
>
>Case 1
>RetrieveAutoIncrementPK = false
>irecversion NOT NULL
>Insert success
>
>Case 2
>RetrieveAutoIncrementPK = true
>irecversion NOT NULL
>Insert fail
>
>Case 3
>RetrieveAutoIncrementPK = true
>irecversion ALLOW NULL
>Insert success
>
>Stephen
>
>
>>You can only use the RetrieveAutoIncrementPK flag if the field is of type Integer and Identity is set to Yes. You can't set a default value for this kind of field.
>
>>>I found the answer to my question but I may have found a bug in the framework. The RetrieveAutoIncrementPK flag seems to be the answer to my question. However, when I set this flag to true, I am getting a NULL error.
>>
>>
>>>Cannot insert the value NULL into column 'irecversion',
>>>table 'aav3.dbo.AAName'; column does not allow nulls. INSERT fails.
>>
>>
>>>The field irecversion already have a default value of 0 set in the SQL Server. I should never get this particular error useless the INSERT command is actually sending NULL as the value of irecversion. BTW, when I set
>>>RetrieveAutoIncrementPK back to false, the insert works correctly.
-----------------------------------------

Cathi Gero, CPA
Prenia Software & Consulting Services
Microsoft C# / .NET MVP
Mere Mortals for .NET MVP
cgero@prenia.com
www.prenia.com
Weblog: blogs.prenia.com/cathi
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform