Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / February 2008

Tip: Looking for answers? Try searching our database.

Best way to do this

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Tem - 13 Feb 2008 07:52 GMT
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
Tibor Karaszi - 13 Feb 2008 07:59 GMT
> 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
Uri Dimant - 13 Feb 2008 08:03 GMT
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

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.