When a user submits a photo on my site, a confirmation page is shown.
Your photo has been submitted.
I want to generate a link to the photo he just posted on the confirmation
page.
what's the best way to do this?
right now there are two queries on the page
- insert photo
- select where user=@user order by date desc
they seem redundant
does sql return the value/id of the newly created row somewhere?
Tem
> does sql return the value/id of the newly created row somewhere?
Do the table have an identity column and you by "value/id" mean the generated value for this column?
If so, then check out the SCOPE_IDENTITY() function.

Signature
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://sqlblog.com/blogs/tibor_karaszi
> When a user submits a photo on my site, a confirmation page is shown.
> Your photo has been submitted.
[quoted text clipped - 12 lines]
>
> Tem
Tem - 13 Feb 2008 08:23 GMT
yes it does.
how would I access it with asp.net?
>> does sql return the value/id of the newly created row somewhere?
>
[quoted text clipped - 19 lines]
>>
>> Tem
Tem - 13 Feb 2008 08:28 GMT
If I do
insert.....; select identity_scope();
how do I read the value from the 2nd sql statement with asp.net?
> yes it does.
>
[quoted text clipped - 23 lines]
>>>
>>> Tem
Tibor Karaszi - 13 Feb 2008 09:48 GMT
It depends on how you use ASP.NET and ADO.NET to communicate with SQL Server. If you follow best
practices and use stored procedures, then use an output parameter for your procedure for this. Else,
just do below after the INSERT and read the returned value as a resultset.

Signature
Tibor Karaszi, SQL Server MVP
http://www.karaszi.com/sqlserver/default.asp
http://sqlblog.com/blogs/tibor_karaszi
> yes it does.
>
[quoted text clipped - 21 lines]
>>>
>>> Tem
Tem
Lookup SCOPE_IDENTITY() in the BOL
> When a user submits a photo on my site, a confirmation page is shown.
> Your photo has been submitted.
[quoted text clipped - 13 lines]
>
> Tem
Tem - 13 Feb 2008 08:22 GMT
whats bol?
> Tem
> Lookup SCOPE_IDENTITY() in the BOL
[quoted text clipped - 16 lines]
>>
>> Tem
Uri Dimant - 13 Feb 2008 09:12 GMT
BOL -Books OnLine feature that shipps with SQL Server
create table #t(c int not null identity(1,1))
insert into #t default values
select scope_identity()
> whats bol?
>
[quoted text clipped - 18 lines]
>>>
>>> Tem