Best way to do this

T

Tem

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
 
T

Tibor Karaszi

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.
 
T

Tem

If I do

insert.....; select identity_scope();

how do I read the value from the 2nd sql statement with asp.net?
 
U

Uri Dimant

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()
 
T

Tibor Karaszi

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,812
Latest member
GracielaWa

Latest Threads

Top