Products

Solutions

Resources

Partners

Community

Blog

About

QA

Ideas Test

New Community Website

Ordinarily, you'd be at the right spot, but we've recently launched a brand new community website... For the community, by the community.

Yay... Take Me to the Community!

Welcome to the DNN Community Forums, your preferred source of online community support for all things related to DNN.
In order to participate you must be a registered DNNizen

HomeHomeArchived Discus...Archived Discus...Developing Under Previous Versions of .NETDeveloping Under Previous Versions of .NETASP.Net 2.0ASP.Net 2.0ObjectDataSource Return Last Inserted ID ObjectDataSource Return Last Inserted ID
Previous
 
Next
New Post
2/26/2008 9:12 PM
 

Using Michaels instructions for Super Fast DAL+, my insert works perfect. I would like to be able to grab the ID of the last inserted record and can't get it to work. I've tried SELECT SCOPE-IDENTITY, SELECT @@IDENTITY. I've read on the internet that the ExecuteNonQuery does not return as expected. Is there a way to get the last ID using this coding?

Thanks

 
New Post
2/26/2008 9:26 PM
 

see this page:

http://www.adefwebserver.com/DotNetNukeHELP/Misc/code/DynamicForms_DynamicForms_DAL.vb.htm

     Public Shared Function AddNewRecord(ByVal PortalID As Integer) As Integer
            Dim i As Integer = 0
            Dim mySqlString As New StringBuilder()
 
            mySqlString.Append("INSERT INTO {databaseOwner}{objectQualifier}DynamicForms_Records ")
            mySqlString.Append("(PortalID, RecordName) ")
            mySqlString.Append(" VALUES (@PortalID,'');Select SCOPE_IDENTITY() as myIdentity ")
 
            Dim parmPortalID As SqlParameter = New SqlParameter("@PortalID", SqlDbType.Int, 4)
            parmPortalID.Value = PortalID
 
            Using dr As IDataReader = CType(DataProvider.Instance().ExecuteSQL(mySqlString.ToString(), parmPortalID), IDataReader)
                While dr.Read
                    i = Convert.ToInt32(dr.Item("myIdentity"))
                End While
            End Using
 
            Return i
        End Function



Michael Washington
http://ADefWebserver.com
www.ADefHelpDesk.com
A Free Open Source DotNetNuke Help Desk Module
 
New Post
2/26/2008 9:29 PM
 

However unless you're creating modules for sale and you don't want to have to tell people to change their web.config, you want to use Linq. It's a lot less code and it's wyyy faster. However it has a learning curve so you will want to start learning it now.

Creating a DotNetNuke Module using LINQ to SQL (VB and C#) (Start here!)



Michael Washington
http://ADefWebserver.com
www.ADefHelpDesk.com
A Free Open Source DotNetNuke Help Desk Module
 
New Post
2/27/2008 11:53 AM
 

Thanks for the info Michael.

I'll be getting into the Linq arena soon. For now I created a stored procedure that fires in the objectdatasource_Item_Inserted event. It grabs the MAX(ID) WHERE UserID = @MemberID. It works and once I get the Linq stuff going I'll take another look at it.

Thanks again!

 
Previous
 
Next
HomeHomeArchived Discus...Archived Discus...Developing Under Previous Versions of .NETDeveloping Under Previous Versions of .NETASP.Net 2.0ASP.Net 2.0ObjectDataSource Return Last Inserted ID ObjectDataSource Return Last Inserted ID


These Forums are dedicated to discussion of DNN Platform and Evoq Solutions.

For the benefit of the community and to protect the integrity of the ecosystem, please observe the following posting guidelines:

  1. No Advertising. This includes promotion of commercial and non-commercial products or services which are not directly related to DNN.
  2. No vendor trolling / poaching. If someone posts about a vendor issue, allow the vendor or other customers to respond. Any post that looks like trolling / poaching will be removed.
  3. Discussion or promotion of DNN Platform product releases under a different brand name are strictly prohibited.
  4. No Flaming or Trolling.
  5. No Profanity, Racism, or Prejudice.
  6. Site Moderators have the final word on approving / removing a thread or post or comment.
  7. English language posting only, please.
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out