Solved

return integer from sql result

Posted on 2004-09-08
3
252 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 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

I have developed many web applications with asp & asp.net and to add and use a dropdownlist was always a very simple task, but with the new asp.net, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

740 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