Re: ExecuteScalar return decimal instead of int? by Miha
Miha
Fri Mar 05 02:43:29 CST 2004
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" <ron_a1@hotmail.com> wrote in message
news:eGSMeOfAEHA.916@tk2msftngp13.phx.gbl...
> 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 [MVP C#]" <miha at rthand com> wrote in message
> news:eDXmGdcAEHA.3348@TK2MSFTNGP11.phx.gbl...
> > or Convert.ToInt32(..)
> >
> > --
> > Miha Markic [MVP C#] - RightHand .NET consulting & software development
> > miha at rthand com
> > www.rthand.com
> >
> > "RA" <ron_a1@hotmail.com> wrote in message
> > news:%23lf%23YsXAEHA.640@TK2MSFTNGP09.phx.gbl...
> > > 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
> > >
> > >
> >
> >
>
>