MSDOTnet.org Forum Index
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

ObjectDataSource

 
Post new topic   Reply to topic    MSDOTnet.org Forum Index -> ASPNet
Author Message
shapper



Joined: 08 Aug 2007
Posts: 4

PostPosted: Wed Feb 27, 2008 9:11 pm    Post subject: ObjectDataSource Reply with quote

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:

_
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

Archived from group: microsoft>public>dotnet>framework>aspnet
Back to top
View user's profile Send private message
Michael Nemtsev [MVP]



Joined: 04 Nov 2007
Posts: 24

PostPosted: Thu Feb 28, 2008 6:06 am    Post subject: Re: ObjectDataSource Reply with quote

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> _
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 to top
View user's profile Send private message
Display posts from previous:   
Related Topics:
ObjectDataSource and sp_setapprole I have an to link my GridView and SQL 2005 database through a strong type DataSet. My initial connection is through Kerberos, hopping the logged on user's Windows credentials, but I would like to then set an application role. Does anybody

objectdatasource in mobile forms How do we use in mobile forms?

session, objectdatasource and formview issue I have an object. Theres a get, update, insert (etc) method for this The Get rturns an IList which I bind to a formview via In the get method I store the object in session once I have it, naming it object+id. I first check to see if the

How to retrive a reference to actual obj in ObjectDataSource Hi, I have lots of data layer objects and want to use them in an object to bind it's results to a GridView. The problem is that all these data layer objects are (let's say) that is, the connection they use is assigned b

Passing a Public Key What are the meanings of the properties in DQ and all that. Can't seem to find any documentation about it. Thanks.
Post new topic   Reply to topic    MSDOTnet.org Forum Index -> ASPNet All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group