ObjectDataSource

  • Thread starter Thread starter shapper
  • Start date Start date
S

shapper

Hello,

I have an ObjectDataSource with Save defined as insert method.

I need return the ID of the inserted record so I can use it in my
ObjectDataSource after the item has been inserted.

How can I do this?

This is my code:

<DataObjectMethodAttribute(DataObjectMethodType.Insert, True)> _
Public Shared Sub Insert(ByVal name As String)

Dim database As New CodeDataContext
Dim tag As New Tag
tag.Name = name
tag.TagID = Guid.NewGuid()
database.Tags.InsertOnSubmit(tag)
database.SubmitChanges()

End Sub ' Insert

This is how I am defining my insert parameter

odsTags.InsertParameters.Add(New Parameter("Name",
TypeCode.String))

Thanks,

Miguel
 
Hello shapper,


U can use "select @@identity" to get the if of the latest insert row to
sql table

---
WBR,
Michael Nemtsev [.NET/C# MVP] :: blog: http://spaces.live.com/laflour

"The greatest danger for most of us is not that our aim is too high and we
miss it, but that it is too low and we reach it" (c) Michelangelo


s> Hello,
s>
s> I have an ObjectDataSource with Save defined as insert method.
s>
s> I need return the ID of the inserted record so I can use it in my
s> ObjectDataSource after the item has been inserted.
s>
s> How can I do this?
s>
s> This is my code:
s>
s> <DataObjectMethodAttribute(DataObjectMethodType.Insert, True)> _
s> Public Shared Sub Insert(ByVal name As String)
s> Dim database As New CodeDataContext
s> Dim tag As New Tag
s> tag.Name = name
s> tag.TagID = Guid.NewGuid()
s> database.Tags.InsertOnSubmit(tag)
s> database.SubmitChanges()
s> End Sub ' Insert
s>
s> This is how I am defining my insert parameter
s>
s> odsTags.InsertParameters.Add(New Parameter("Name",
s> TypeCode.String))
s>
s> Thanks,
s>
s> Miguel
s>
 
Back
Top