Solved

return integer from sql result

Posted on 2004-09-08
3
245 Views
Last Modified: 2008-03-03

Hello, new to .Net (using c#). I know how to return a dataset and display it in a number of different ways, but I have a stored procedure that returns only an integer and I don't know how to just return that one integer from my method without returning the dataset and looking at that specific row/column in the table, which would be 0,0. Isn't there a simpler way, so that if my stored procedure will always only return one row and one column, my integer, that I can just return that value?

thanks in advance!
0
Comment
Question by:animated405
3 Comments
 
LVL 10

Accepted Solution

by:
123654789987 earned 200 total points
ID: 12013182
SqlConnection nwindConn = new SqlConnection("Data Source=localhost;Integrated Security=SSPI;" +
                              "Initial Catalog=northwind");
                        SqlCommand  command = new SqlCommand("InsertProc",      nwindConn);
                        nwindConn.Open();

                        Int32 count = (int32) command.ExecuteScalar();

Here "InsertProc" is the name of the strored proc. ExecuteScalar method is used to return a single value
0
 
LVL 15

Assisted Solution

by:Thogek
Thogek earned 50 total points
ID: 12013441
More info about the SqlCommand.ExecuteScalar method (how it works, examples, etc.) is at http://msdn.microsoft.com/library/en-us/cpref/html/frlrfSystemDataSqlClientSqlCommandClassExecuteScalarTopic.asp
0
 

Author Comment

by:animated405
ID: 12019705

Thanks very much!!
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

One of the pain points with developing AJAX, JavaScript, JQuery, and other client-side behaviors is that JavaScript doesn’t allow for cross domain request for pulling content. For example, JavaScript code on www.johnchapman.name could not pull conte…
Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now