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

  • Thread starter Thread starter Frankie
  • Start date Start date
F

Frankie

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!
 
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

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!
 
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.
 
Hi,

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


cheers,
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top