ExecuteScalar return decimal instead of int?

R

RA

Hi

When I use the ExecuteScalar and the sql looks like this "Insert ...; Select
SCOPE_IDENTITY()" I get the return value as decimal - how can I cast it so
it will return an integer? I use .net c#


Thanks
 
R

RA

But is there a way in the sql statement forcing it to return integer? The
identity value in the db is defined as int.
Maybe "select SCOPE_IDENTITY () as integer" ? I am not sure about the
syntex. By the way is this the best way to get the new added row identity
column to the database?

Thanks

Miha Markic said:
or Convert.ToInt32(..)

--
Miha Markic [MVP C#] - RightHand .NET consulting & software development
miha at rthand com
www.rthand.com

RA said:
Hi

When I use the ExecuteScalar and the sql looks like this "Insert ...; Select
SCOPE_IDENTITY()" I get the return value as decimal - how can I cast it so
it will return an integer? I use .net c#


Thanks
 
M

Miha Markic [MVP C#]

Hi,

Well, yes, it doesn't really matter where you do the conversion.
select cast(scope_identity() as int) will do it on the server (note that
identity can go over int).

And yes, this is the best and correct way to retrieve the last inserted
identity field in the current transaction.


--
Miha Markic [MVP C#] - RightHand .NET consulting & software development
miha at rthand com
www.rthand.com



RA said:
But is there a way in the sql statement forcing it to return integer? The
identity value in the db is defined as int.
Maybe "select SCOPE_IDENTITY () as integer" ? I am not sure about the
syntex. By the way is this the best way to get the new added row identity
column to the database?

Thanks

Miha Markic said:
or Convert.ToInt32(..)

--
Miha Markic [MVP C#] - RightHand .NET consulting & software development
miha at rthand com
www.rthand.com

RA said:
Hi

When I use the ExecuteScalar and the sql looks like this "Insert ...; Select
SCOPE_IDENTITY()" I get the return value as decimal - how can I cast
it
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top