473,386 Members | 1,733 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

ExecuteScalar() Inadequate - so what's next best?

What would be an efficient way to retrieve two values from a stored
procedure via ADO.NET? I understand ADO.NET's ExecuteScalar() method
returns one value.

I need two values returned, and didn't want to .Fill() a DataTable just to
get two values (I am wanting fewer lines of code and something more
efficient than that if possible).

Any suggestions?

Thanks!
Nov 17 '05 #1
3 1942
Use output parameters. A sample can be found here (look for 'Fetching Output
Parameters' section):
http://www.developer.com/db/article.php/10920_3438221_3

"Frankie" <A@B.COM> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
What would be an efficient way to retrieve two values from a stored
procedure via ADO.NET? I understand ADO.NET's ExecuteScalar() method
returns one value.

I need two values returned, and didn't want to .Fill() a DataTable just to
get two values (I am wanting fewer lines of code and something more
efficient than that if possible).

Any suggestions?

Thanks!

Nov 17 '05 #2
Frankie,

If the values are not returned through output parameters, then you could
use a DataReader instead. This is much lighter weight, and you can access
the values (you iterate through the reader for each row in the result set
returned) through the GetInt32, GetBoolean, etc, etc methods.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Frankie" <A@B.COM> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
What would be an efficient way to retrieve two values from a stored
procedure via ADO.NET? I understand ADO.NET's ExecuteScalar() method
returns one value.

I need two values returned, and didn't want to .Fill() a DataTable just to
get two values (I am wanting fewer lines of code and something more
efficient than that if possible).

Any suggestions?

Thanks!

Nov 17 '05 #3
Hi,

You can use output parameters. Just use the correct overloaded constructor
to set the Direction property.
cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"Frankie" <A@B.COM> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
What would be an efficient way to retrieve two values from a stored
procedure via ADO.NET? I understand ADO.NET's ExecuteScalar() method
returns one value.

I need two values returned, and didn't want to .Fill() a DataTable just to
get two values (I am wanting fewer lines of code and something more
efficient than that if possible).

Any suggestions?

Thanks!

Nov 17 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: WeiminZhang | last post by:
When I use the OleDb to connect a Oracle db, and use the ExecutScalar() method to get the count of a table, the return value can't be cast to a data type, say int, while this works fine for a SQL...
2
by: Dinesh | last post by:
Hi, I have one stored procedure in SQL server in which i have written one insert statement. Now in my cs file i pass the parameters require to execute that stored procedure and finaly by mistaken...
2
by: Mike Krajewski | last post by:
We are having an intermittent problem using an ExecuteScalar command on a asp.NET page accessing SQL Server. 2 characters of the sql statement get intermittently altered. The code looks as...
5
by: bienwell | last post by:
Hi all, I have a problem with using myCommand.ExecuteScalar(). My question is : If the Web setup is incorrect, does it make command ExecuteScalar() work improperly ?? In my program, I was...
3
by: charliewest | last post by:
Hi - I need to detect when the ExecuteScalar() method of the cmd object returns NULL. I have tried the below code, however, it always returns false (this is to say, that ExecuteScalar never...
0
by: Stephen Plotnick | last post by:
I think I have a speed issue I'd like to resolve. I have a DataGrid that on every line I need to get four records from a data base as I scroll thorugh the records. THanks to Steve I can get...
8
by: Earl | last post by:
What's the best way to check for null on an ExecuteScalar? The following would fire the command twice: if (cmd.ExecuteScalar() != null) { intContactID = Convert.ToInt32(cmd.ExecuteScalar()); }
4
by: Morten Snedker | last post by:
On a web-form the user enters basic data (company name, phone, areacode etc). Many we have already registrered and some not. For those we have we wish to make the enter of data easier by looking...
2
by: Tony Johansson | last post by:
Hello! If you do an update in the database you will use ExecuteNonQuery but the database update will work just as good if you instead use ExecuteReader or executeScalar. So my question is how...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.