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

Posts: 127
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
 
When You Register, These Ads Go Away!
     
Old 01-07-2006, 07:09 PM
Minaki's Avatar
Cheerleader

Posts: 1,626
Location: Guildford, UK
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!"
Inoxia Pyrotechnics Supplies | Surrey Angels Cheerleading Squad
Minaki is offline
Reply With Quote
View Public Profile Visit Minaki's homepage!
 
Old 01-07-2006, 11:50 PM
Super Talker

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

Posts: 1
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, 12:24 PM Re: executeScalar() vs executeNonQuery()
Learning Newbie's Avatar
Moderator

Latest Blog Post:
Dick Cheney as a Web Comic
Posts: 4,622
Name: John Alexander
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"
__________________
4 ways to improve the lives of the "bottom billion"

"HEY YOU KIDS GET OFF MY LAWN!" -John McCain
Learning Newbie is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to executeScalar() vs executeNonQuery()
 

Thread Tools

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

vB 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.14019 seconds with 13 queries