Solved

return integer from sql result

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

Independent Software Vendors: 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

Today is the age of broadband.  More and more people are going this route determined to experience the web and it’s multitude of services as quickly and painlessly as possible. Coupled with the move to broadband, people are experiencing the web via …
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…

632 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