473,757 Members | 8,356 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Return pkID of last saved record - ASPUpload & @@Identity

We're using ASPUpload as a tool to upload files to our server and save
the details to SQLServer. However, I have an application where I need
to return the pkID of the just saved file. I'm assuming that I could
use the @@Identity command but cannot get this to function.

Has anyone used this command with ASPUpload with an success, or any
other methods that could be used?

Thanks.

Nov 25 '05 #1
8 2721
BigJohnson (cr***********@ westleigh.co.uk ) writes:
We're using ASPUpload as a tool to upload files to our server and save
the details to SQLServer. However, I have an application where I need
to return the pkID of the just saved file. I'm assuming that I could
use the @@Identity command but cannot get this to function.

Has anyone used this command with ASPUpload with an success, or any
other methods that could be used?


Since I've never heard of ASPUpload before, and I don't know ASP, I would
suggest that you either post your question to an ASP forum, or post the
relvant code parts - both ASP and SQL Server here.
--
Erland Sommarskog, SQL Server MVP, es****@sommarsk og.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pro...ads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinf...ons/books.mspx
Nov 26 '05 #2
Hey BigJ

If you know the table name then you can retreive the last identity
value with the function: IDENT_CURRENT(' <table name>'). This works
accross all sessions and scopes. The problem with @@IDENTITY var is
that it is global only to the session where the insert occured. This
may not be the same session where you are quering the @@IDENTITY. If
this doesnt work for you, please post more info about how the details
are inserted into SQL server. thanks

best regards.

Nov 27 '05 #3
What you are asking for sounds like a kludge caused by a bad design.

Wouldn't life be much easier if you used a design with real Relational
keys instead of a proprietary exposed physical locator like IDENTITY
to mimic a sequential file structure?

Nov 27 '05 #4
The IDENTITY property is not a physical locator, its simply a means to
generate an automatic incrementing number - check the product spec for more
information.

Other methods of creating incrementing numbers involve using the MAX on the
id column which gives a heavy performance degradation because of locking
over using the IDENTITY property.

Check the current ANSI standard and you will see an implementation around
this.

Many people use an IDENTITY property to populate a surrogate key instead of
bloating tables copying your natural key around.

In this posters case, i've used ASPUpload myself, they are saving a file to
the file system and want to record a locator to the file, often i give
uploaded files FL001.PDF for instance as you can't get at the original file
name, also, even if you could its from mulitple users who may well use the
same filename so the natural key as it would be (filename) is useless,
unless you want to force people to have different file names adding
complexity and spoiling the UI experience.

--
Tony Rogerson
SQL Server MVP
http://sqlserverfaq.com - free video tutorials
"--CELKO--" <jc*******@eart hlink.net> wrote in message
news:11******** **************@ g44g2000cwa.goo glegroups.com.. .
What you are asking for sounds like a kludge caused by a bad design.

Wouldn't life be much easier if you used a design with real Relational
keys instead of a proprietary exposed physical locator like IDENTITY
to mimic a sequential file structure?

Nov 27 '05 #5
Hi,

Use SCOPE_IDENTITY( ) to get the last inserted IDENTITY value for that
statement...

insert blha......

select pkID = SCOPE_IDENTITY( )

--
Tony Rogerson
SQL Server MVP
http://sqlserverfaq.com - free video tutorials
"BigJohnson " <cr***********@ westleigh.co.uk > wrote in message
news:11******** **************@ g49g2000cwa.goo glegroups.com.. .
We're using ASPUpload as a tool to upload files to our server and save
the details to SQLServer. However, I have an application where I need
to return the pkID of the just saved file. I'm assuming that I could
use the @@Identity command but cannot get this to function.

Has anyone used this command with ASPUpload with an success, or any
other methods that could be used?

Thanks.

Nov 27 '05 #6
After calling the Upload.Save method, loop through the files, saving
them one at a time. As you save each one, retrieve the @@identity
property inside the stored proc you are using to insert the new file
entry. As Celko suggests, You could also use the path and filename as a
key if you want, since ASPUpload takes care of renaming files if they
have the same name. Just using an identity column is a heck of alot
easier though when you have things you want to relate to those files.

Tony Rogerson wrote:
Hi,

Use SCOPE_IDENTITY( ) to get the last inserted IDENTITY value for that
statement...

insert blha......

select pkID = SCOPE_IDENTITY( )

--
Tony Rogerson
SQL Server MVP
http://sqlserverfaq.com - free video tutorials
"BigJohnson " <cr***********@ westleigh.co.uk > wrote in message
news:11******** **************@ g49g2000cwa.goo glegroups.com.. .
We're using ASPUpload as a tool to upload files to our server and save
the details to SQLServer. However, I have an application where I need
to return the pkID of the just saved file. I'm assuming that I could
use the @@Identity command but cannot get this to function.

Has anyone used this command with ASPUpload with an success, or any
other methods that could be used?

Thanks.


Nov 27 '05 #7
You need to use scope_identity( ), @@identity is affected by triggers etc...

Tony.

--
Tony Rogerson
SQL Server MVP
http://sqlserverfaq.com - free video tutorials
"pb648174" <go****@webpaul .net> wrote in message
news:11******** **************@ g47g2000cwa.goo glegroups.com.. .
After calling the Upload.Save method, loop through the files, saving
them one at a time. As you save each one, retrieve the @@identity
property inside the stored proc you are using to insert the new file
entry. As Celko suggests, You could also use the path and filename as a
key if you want, since ASPUpload takes care of renaming files if they
have the same name. Just using an identity column is a heck of alot
easier though when you have things you want to relate to those files.

Tony Rogerson wrote:
Hi,

Use SCOPE_IDENTITY( ) to get the last inserted IDENTITY value for that
statement...

insert blha......

select pkID = SCOPE_IDENTITY( )

--
Tony Rogerson
SQL Server MVP
http://sqlserverfaq.com - free video tutorials
"BigJohnson " <cr***********@ westleigh.co.uk > wrote in message
news:11******** **************@ g49g2000cwa.goo glegroups.com.. .
> We're using ASPUpload as a tool to upload files to our server and save
> the details to SQLServer. However, I have an application where I need
> to return the pkID of the just saved file. I'm assuming that I could
> use the @@Identity command but cannot get this to function.
>
> Has anyone used this command with ASPUpload with an success, or any
> other methods that could be used?
>
> Thanks.
>

Nov 27 '05 #8
like I said earlier, if you know the name of the table where you are
inserting the file details, then the surest way to query the identity
value is with IDENT_CURRENT(' <table name>'). The problem with
@@Identity var is that it is global to the session (i.e. connection)
which is why it is affected by triggers. Also, if the insert happens
in a rolled back transaction, the @@identity is NOT reset so it is
possible to have an invalid @@identity value. This may or may not be a
problem for you. Now, the problem with the scope_identity( ) is this
returns the IDENTITY value that is local to the scope of the insert.
This means you would have to query the IDENTITY value of the last
insert in the same code that the insert occurred (same session, same
local code scope(i.e. job)). I myself use scope_identity( ) but for
you, you may not be looking to query the IDENTITY in the same session.
For instance, your inserts might happen in one connection to the db and
you might instantiate a separate connection and query the IDENTITY
column. In that case, scope_identity( ) returns NULL. You would know
better these details so please post code or more info if this doesn't
help. Thanks.

Nov 29 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1575
by: Newbillian | last post by:
After converting Access 97 databases to 2003 this error msg shows up after a line about not being able to save the record because a related record is needed in another table. The complete msg is: The macro "." (or its macro group) doesn't exist, or the macro is new but hasn't been saved. Note that when you enter the macrogroupname.macroname syntax in an argument, you must specify the name the macro's macro group was last saved under. The...
4
2439
by: kieran | last post by:
Hi, I import data every evening through a scheduled task from a text file. Once the data is imported, an email is sent to a user saying how much data etc.. was in the file. In case the file has not been updated each day, i would like to include in the email the date and time the file was last updated. Is there some way to get this using vb.net from a text file i.e. to tell when the file was last saved.
1
3841
by: aferoce | last post by:
Hello! I'm new to SQL and i've searched everywhere for the answer to this question but I can't seem to find the anwer anywhere. My question is..... If there are multiple rows for a specific filed, is there a way in SQL to only return the last row based on that specific field. For example, I wrote a query that returns a list of patients who have a specific lab type. If a patient has had several labs taken, they show up in the result set...
4
1813
by: SoulSeeker | last post by:
Hello. How I can start my M$ access form with last edited record? What I must put in "on load" field? Tnx. for advice.
4
1805
ollyb303
by: ollyb303 | last post by:
Hi, I have a problem I need some help with. In my Access 2000 database (used for logging complaints to my company), I'm using the following code to send an email to our finance dept when a refund is requested: Private Sub Save_Record_Click() On Error GoTo Err_Save_Record_Click Dim strTo As String
13
4431
rajiv07
by: rajiv07 | last post by:
Hi to all, I want to know how to select a last inserted record which is the primary key is not an integer. my table ramstr(Primary)----name--service XTC01-------Rajiv---service XTC02------kumar--Service
11
3219
by: andrewdb | last post by:
I have been working with a database that was already created by somebody else, who now no longer works here, so I cant ask any questions. None the less, there is a table 'Ascertainment' which prior to my changes new record was saved in the Table, but when you bring up the form it was blank, the input for new record consisted of Text Boxes. I wanted to validate the data, and changed the text boxes to combo boxes, now new record does not...
4
2510
semanticnotion
by: semanticnotion | last post by:
Hi guys how can i retrieve the last inserted record from datebase. my primary key is not auto_increment its type is bigint because i want to insert SSN no as a primary key. when i retrive the data using select query it retrieve the first record store in database but i want to display the last inserted record because i want then to print that record. so any idea plz help me my queries are $query="INSERT INTO form1...
1
1501
by: Bigdaddrock | last post by:
I have a field called DateLastRevised in a Table. I would like that field to be updated to reflect the date and time that the record was last revised. I have a form that edits these records and after using that form to edit a particular record, I would like the ability to open another form which would access that same record via a query, based on the table, in which the DateLastRevised field is used to order the records. I could then direct...
0
10072
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9906
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9885
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8737
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6562
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5172
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3829
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3399
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2698
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.