Click here to Skip to main content
14,425,979 members
Rate this:
Please Sign up or sign in to vote.
See more:
i tried this code to store max id in maxid var but it didnt get id in maxid

What I have tried:

int maxId;
SqlCommand dataCommand = new SqlCommand("Select max(Id) from Quant_Parent", con);
maxId = Convert.ToInt32(dataCommand.ExecuteScalar());
Updated 24-Aug-16 0:04am
Karthik_Mahalingam 24-Aug-16 5:01am
does the table 'Quant_Parent' has primary key ID ?

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 1

Don;t use MAX(ID): use @@IDENTITY instead - it returns the last IDENTITY value produced on a connection.

Which means it returns the last value you created, rather than the guy at the next desk!

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