Randy, If you followed the standard DNN coding model what you want to do should be no problem. I will illustrate below some sample code. First, the very last thing that should be in your stored procedure after the insert should be the statement "select SCOPE_IDENTITY()". This will return to the caller the id of the record inserted.
/*
Your SQL Stored Procedure...
*/
ALTER PROCEDURE [dbo].[AddName]
@PortalID int,
@ModuleID int,
@FirstName nvarchar(64),
@LastName nvarchar(64),
AS
INSERT INTO Names (
[PortalID],
[ModuleID],
[FirstName],
[LastName]
) VALUES (
@PortalID,
@ModuleID,
@FirstName,
@LastName
)
select SCOPE_IDENTITY()
Next, all the methods in your abstract data provider class and concrete data provider class should be written as functions that return an integer which is the SCOPE IDENTITY that the stored procedure returns.
/*
Your modules concrete SQLDataProvider Class (SQLDataProvider.vb)...
*/
Public Overrides Function AddName(ByVal portalID As Integer, ByVal moduleID As Integer, ByVal firstName As String, ByVal lastName As String) As Integer
Return CType(SqlHelper.ExecuteScalar(ConnectionString, GetFullyQualifiedName("AddName"), portalID, moduleID, firstName, lastName), Integer)
End Function
/*
Your modules abstract DataProvider Class (DataProvider.vb)...
*/
Public MustOverride Function AddName(ByVal portalID As Integer, ByVal moduleID As Integer, ByVal firstName As String, ByVal lastName As String) As Integer
/*
Your modules Controller Class (NamesController.vb)...
*/
Public Function AddName(ByVal objInfo As AgentInfo) As Integer
Return CType(DataProvider.Instance().AddAgent(objInfo.PortalID, objInfo.ModuleID, objInfo.FirstName, objInfo.LastName), Integer)
End Function
The only place that you need to make the change is in the code behind of your module's edit control (EditNames.ascx.vb). Typically , the event handler of the Update button simply calls the Controller's "Add" method not setting anything to the return value. You would change that as indicated below.
/*
Your modules Code Behind File (EditForm.ascx.vb)
*/
'-- Add or Update the record (not capturing the record id).
If RecordID = -1 Then
objController.AddName(objInfo)
Else
objController.UpdateName(objInfo)
End If
'-- Redirect back to the caller.
Response.Redirect(NavigateURL())
Modify your code to set an integer variable equal to the results of the call to the Add function. On a successful insert the value will contain the record ID of the new record. I believe that in the case of an error the returned value will be a negetive integer representing the error code.
'-- Add or Update the record.
Dim intNewRecordId As Integer
If RecordID = -1 Then
intNewRecordId = objController.AddName(objInfo)
Else
objController.UpdateName(objInfo)
End If
'-- Redirect back to the caller.
Response.Redirect(NavigateURL())
That should do it!! Now that you've got the record id of the new record you can do whatever you need to with it. With all the above code, only the stuff highlighted in blue is actually the change to the standard DNN coding methods.
I hope this helps,
Chuck R.