Click here to Skip to main content
14,424,458 members
Rate this:
Please Sign up or sign in to vote.
See more:
hi all,

i need to get the last inseted id in my table. how to do it. pls help
Posted
Rate this:
Please Sign up or sign in to vote.

Solution 1

write query
select top 1 id from table_name order by id desc
   
v2
Rate this:
Please Sign up or sign in to vote.

Solution 3

hi ...
i cant not done ....
con.Open();
            str = "select Num from Pic";
            com = new OleDbCommand(str, con);
            OleDbDataReader reader = com.ExecuteReader();
            reader.Read();
            label1.Text = reader["Num"].ToString() + "  Num";

this show num 1 ...
how change to get last num ....
please help !
   
Rate this:
Please Sign up or sign in to vote.

Solution 4

You have already got answer of your problem but following link would be helpful for you in future to get clear idea about how can get last inserted id.

Interview Question: What are the Differences between @@IDENTITY, SCOPE_IDENTITY() and IDENT_CURRENT()[^]
   
Rate this:
Please Sign up or sign in to vote.

Solution 2

try the below codes:

SELECT MAX(id) FROM [tablename]

OR
SELECT TOP 1 id FROM [tablename] ORDER BY id DESC

OR
--INSERT STATEMENT HERE
SELECT @@IDENTITY


Regards,
Eduard
   

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




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100