Click here to Skip to main content
15,885,546 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi My project is to upload image to server
And save the path on database
The problem is how to add id to image name
And this id is identity
I try to add current id from table database
But how can i do that
Just any idea?
String x = ~/myfile/id_image.jpg
This path will saved in database
So the (id) is current row id in DB
Posted
Comments
Shweta N Mishra 17-Dec-14 9:11am    
select @@identity in you SP where you are inserting the data
Sibasisjena 17-Dec-14 9:13am    
Please post your script/ procedure.
Plesae have a look on the below link
http://stackoverflow.com/questions/42648/best-way-to-get-identity-of-inserted-row

I would suggest "SCOPE_IDENTITY"
ZurdoDev 17-Dec-14 9:27am    
As mentioned, use SCOPE_IDENTITY to get the last id and then add it. Where are you stuck?

If you're using ASP.NET, you can use this code to get the last insert ID, Database.GetLastInsertId()[^]. However, a turn around is to select the last record and get the ID column of that. Something like this,

C#
// open connection
var db = Database.Open("databaseName");
// make the query, to select the TOP 1, DESC to start it from end
var selectQuery = "SELECT TOP 1 * FROM table_name DESC";
// get that column
var column = db.Query(selectQuery);


.. now this column object will contain all of the values for that column, so you can just call the property to get the ID of this record.
 
Share this answer
 
curr_ident('Table Name') will give you the highest identity value
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900