Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

.NET Forum


You are currently viewing our .NET Forum as a guest. Please register to participate.
Login



Reply
executeScalar() vs executeNonQuery()
Old 01-07-2006, 03:41 PM executeScalar() vs executeNonQuery()
Super Talker

Posts: 148
Trades: 0
I am just wondering if i want to return one varchar value should i use executeScalar() or executeNonQuery()? Thanks
shaoen01 is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 01-07-2006, 08:09 PM
Minaki's Avatar
Defies a Status

Posts: 1,626
Location: Guildford, UK
Trades: 0
Use ExecteScalar. ExecuteScalar is used when you just want one single value from one single row, as in:
SELECT Name FROM Users WHERE UniqueId = 42

ExecuteNonQuery is used for SQL statements that don't return any data (For example, INSERT, UPDATE, DELETE)
__________________
Minaki Serinde MCP
"Wow, Linux is nearly on-par with Windows ME!"

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
Minaki is offline
Reply With Quote
View Public Profile Visit Minaki's homepage!
 
Old 01-08-2006, 12:50 AM
Super Talker

Posts: 148
Trades: 0
Oh okay ... thanks.
shaoen01 is offline
Reply With Quote
View Public Profile
 
Old 07-03-2007, 11:04 AM Re: executeScalar() vs executeNonQuery()
Junior Talker

Posts: 1
Trades: 0
Thanks for the good advise.

This helped me with a problem with following error :
"Object reference not set to an instance of an object"

Chears Jan
janborup is offline
Reply With Quote
View Public Profile
 
Old 07-03-2007, 01:24 PM Re: executeScalar() vs executeNonQuery()
Learning Newbie's Avatar
Defies a Status

Latest Blog Post:
Astounding Republican Paranoia
Posts: 5,662
Name: John Alexander
Trades: 0
You can use scalar for a delete or update, but obviously you won't get anything back, and that slows your app down a little bit. You can even use the full blown one that expects a table result set. You just don't want to. Things are flexible, though.

Minikay is right - hope I spelled that right!

ExecuteNonQuery = "Delete From SomeTable"
ExecuteScalar = "Select @@Identity"
Fill = "Select * From SomeTable"
__________________

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE
Learning Newbie is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to executeScalar() vs executeNonQuery()
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.14761 seconds with 12 queries