Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

return integer from sql result

Posted on 2004-09-08
3
Medium Priority
?
259 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 10

Accepted Solution

by:
123654789987 earned 800 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 200 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Suggested Courses

715 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