• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 638
  • Last Modified:

How to get newid of inserted record using LinqDataSource?

With SqlDataSource, you could obtain the ID of the record that was just inserted, using code similar to this (originally obtained from 4guysfromrolla.com)

  Protected Sub SqlDataSource1_Inserting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.SqlDataSourceCommandEventArgs) Handles SqlDataSource1.Inserting
    Dim Param As IDbDataParameter = CType(e.Command.Parameters.Item("@newid"), IDbDataParameter)
    Param.Size = 4
  End Sub

  Protected Sub SqlDataSource1_Inserted(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.SqlDataSourceStatusEventArgs) Handles SqlDataSource1.Inserted
    Dim newid As Object = e.Command.Parameters("@newid").Value
  End Sub

How do we do the same thing with LinqDataSource?
1 Solution
cdakzAuthor Commented:

http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.linqdatasource.inserted.aspx did the trick! I did quite a bit of web searching on this, but apparently wasn't using the right search terms.

Featured Post

The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now