Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / ADO.NET / March 2004

Tip: Looking for answers? Try searching our database.

ExecuteScalar return decimal instead of int?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
RA - 03 Mar 2004 23:59 GMT
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
Wolly - 04 Mar 2004 08:46 GMT
int value = int.Parse( cmd.ExecuteScalar(...) )

bye
Miha Markic [MVP C#] - 04 Mar 2004 09:01 GMT
or Convert.ToInt32(..)

Signature

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

> Hi
>
[quoted text clipped - 3 lines]
>
> Thanks
RA - 04 Mar 2004 14:18 GMT
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

> or Convert.ToInt32(..)
>
[quoted text clipped - 11 lines]
> >
> > Thanks
Miha Markic [MVP C#] - 05 Mar 2004 08:43 GMT
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.

Signature

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

> But is there a way in the sql statement forcing it to return integer? The
> identity value in the db is defined as int.
[quoted text clipped - 20 lines]
> > >
> > > Thanks

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.