Solved

return integer from sql result

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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
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…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
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…

786 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