<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://forums.asp.net/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Web Forms</title><link>http://forums.asp.net/18.aspx</link><description>All about building ASP.NET Pages - server controls, events, validation, etc.</description><dc:language>en</dc:language><generator>CommunityServer 2007 SP1 (Build: 20510.895)</generator><item><title>Re: Returns the primary key of the inserted row.</title><link>http://forums.asp.net/thread/2359879.aspx</link><pubDate>Thu, 15 May 2008 13:02:14 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:2359879</guid><dc:creator>smcirish</dc:creator><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/2359879.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=18&amp;PostID=2359879</wfw:commentRss><description>&lt;p&gt;&lt;a href="http://www.mikesdotnetting.com/Article.aspx?ArticleID=54"&gt;http://www.mikesdotnetting.com/Article.aspx?ArticleID=54&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Here is an example of Scope_Identity&amp;nbsp; with Stored Procedures.&lt;/p&gt;
&lt;p&gt;-smc&lt;/p&gt;</description></item><item><title>Re: Returns the primary key of the inserted row.</title><link>http://forums.asp.net/thread/1164239.aspx</link><pubDate>Tue, 10 Jan 2006 17:34:43 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:1164239</guid><dc:creator>bmains</dc:creator><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/1164239.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=18&amp;PostID=1164239</wfw:commentRss><description>Oh OK, sorry, I didn't know you were using a SqlDataSource; I'm not sure of the best way to do this with a Data Source control, but maybe by adding another parameter as an output parameter to the stored procedure, then add this to your insertparameters collection, and check that parameters defaultvalue property (sqlds.InsertParameters["RETURN_VALUE"].DefaultValue).</description></item><item><title>Re: Returns the primary key of the inserted row.</title><link>http://forums.asp.net/thread/1164116.aspx</link><pubDate>Tue, 10 Jan 2006 16:06:32 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:1164116</guid><dc:creator>Patheon</dc:creator><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/1164116.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=18&amp;PostID=1164116</wfw:commentRss><description>&lt;p&gt;&lt;img src="/emoticons/emotion-2.gif" alt="Big Smile [:D]" /&gt; Thanks Brian.... I've now got it to work.... I can retrieve the Instance ID of the newly created row. Now I have a new problem... The record is being inserted Twice.&amp;nbsp; I'm using a SqlDataSource with the commandfield Insert Button, I've placed the code you gave me in the &lt;font color=#0000ff size=2&gt;
&lt;p&gt;Protected&lt;font size=2&gt; &lt;/font&gt;&lt;font color=#0000ff size=2&gt;Sub&lt;/font&gt;&lt;font size=2&gt; SqlDataSource1_Inserted 
&lt;p&gt;the code you gave me, the ExecuteScalar() does it cause the stored procedure to be fired again? If so, then where and how can I avoid this situation?&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;/font&gt;&lt;/p&gt;&lt;/font&gt;&lt;/p&gt;</description></item><item><title>Re: Returns the primary key of the inserted row.</title><link>http://forums.asp.net/thread/1163948.aspx</link><pubDate>Tue, 10 Jan 2006 12:58:29 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:1163948</guid><dc:creator>bmains</dc:creator><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/1163948.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=18&amp;PostID=1163948</wfw:commentRss><description>&lt;p&gt;Stored procedure has to:&lt;/p&gt;
&lt;p&gt;insert into table (..) values (..)&lt;br /&gt;select @@identity&lt;/p&gt;
&lt;p&gt;Then in your code, setup the command, then do:&lt;/p&gt;
&lt;p&gt;Dim objValue As Object = objCommand.ExecuteScalar()&lt;br /&gt;if (IsNumeric(objValue)) then&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;Dim intID as Integer = ctype(objValue, Integer)&lt;br /&gt;end if&lt;/p&gt;</description></item><item><title>Re: Returns the primary key of the inserted row.</title><link>http://forums.asp.net/thread/1163224.aspx</link><pubDate>Mon, 09 Jan 2006 18:28:21 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:1163224</guid><dc:creator>Patheon</dc:creator><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/1163224.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=18&amp;PostID=1163224</wfw:commentRss><description>Hi Brian, Thanks for the reply. I have created a Stored procedure to insert the record... and it inserts fine. Could you give me an example of what you mean? Thanks in advance.</description></item><item><title>Re: Returns the primary key of the inserted row.</title><link>http://forums.asp.net/thread/1163164.aspx</link><pubDate>Mon, 09 Jan 2006 17:45:59 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:1163164</guid><dc:creator>bmains</dc:creator><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/1163164.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=18&amp;PostID=1163164</wfw:commentRss><description>&lt;p&gt;Hey,&lt;/p&gt;
&lt;p&gt;Your stored procedure has to do the insert, then select the ID value, then in your code, when you execute through a Command, use the ExecuteScalar() method of execution, which returns the first value of a single field&amp;nbsp;select statement.&lt;/p&gt;</description></item><item><title>Returns the primary key of the inserted row.</title><link>http://forums.asp.net/thread/1163126.aspx</link><pubDate>Mon, 09 Jan 2006 17:15:03 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:1163126</guid><dc:creator>Patheon</dc:creator><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/1163126.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=18&amp;PostID=1163126</wfw:commentRss><description>&lt;span&gt;Does anyone have a working example in Visual Web Developer 2005 of&amp;nbsp; using a stored procedure to insert a record and return the primary key of the inserted row? &lt;br /&gt;&lt;/span&gt;</description></item></channel></rss>