Last post May 12, 2005 09:24 PM by kennymxp
May 12, 2005 01:47 AM|kennymxp|LINK
In custom DNN module, when we do objectController.Add(a new objectInfo), how can I know that id of that objectInfo (after it's added)? Thank you.
The above question is to solve the following problem: I have a Products table and a ProductDetails table, where the 2nd one is the child of the first one. When I add a new product to Products table, I need the id of that newly added product to add details
with the same productID in ProductDetail. If you know any other way to solve this problem, please feel free to tell me also. Thank you.
May 12, 2005 07:16 AM|walkerstewart|LINK
There are a couple of steps required to achive this.
1. At the end of the Stored Procedure used to add the item to the database, you need to add the following.
This will return the ID of the last item added.
2. In your SqlDataProvider and DataProvider, you need to convert the information returned into an integer.
e.g. CType(Database Acess, integer)
For an example on how to do this, check out the Add Procedure for the Announcements, Contacts, or basically any other DNN module which adds information to the database.
Hope this Helps,
May 12, 2005 12:47 PM|Nocturnal|LINK
May 12, 2005 12:59 PM|cathal|LINK
just one small note, you're better using SELECT SCOPE_IDENTITY(), from SQL books on line:
"SCOPE_IDENTITY and @@IDENTITY will return last identity values generated in any table in the current session. However, SCOPE_IDENTITY returns values inserted only within the current scope; @@IDENTITY is not limited to a specific scope."
May 12, 2005 09:24 PM|kennymxp|LINK