473,414 Members | 1,738 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,414 software developers and data experts.

Getting back a return value from a SQL Count query

I am trying to write a SQL query that will return a record count to my C#
application. I wrote the following query:

ALTER PROCEDURE up_justification_duplicate
AS
SELECT COUNT(*)
FROM tblJustifications

RETURN COUNT(*)
The table has four records in it. Running the query in the IDE gets me the
following results:

Running dbo."up_justification_duplicate".
-----------
4
No more results.
(1 row(s) returned)
@RETURN_VALUE = 1
Finished running dbo."up_justification_duplicate".

I have tried to extract the count in my application but all I know how to do
is read the return value (always a 1) with a statement like "x =
da.SelectCommand.Parameters[0].Value.ToString();".
How do I get back the correct count, in this case 4?

Any help is greatly appreciated.
Nov 16 '05 #1
1 15625
Greg,

The way you have it, the count is being returned in a result set. What
you want to do is execute the command getting the scalar. Call
ExecuteScalar on the SqlCommand you are using to access the database. If
you want to set the count to the return value, then you need to change your
stored procedure to return a value like this:

alter PROCEDURE up_justification_duplicate
AS
return select COUNT(*) from asset

Then you should be able to access the return value through the
parameters.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Greg Smith" <gj*@umn.edu> wrote in message
news:ev**************@TK2MSFTNGP10.phx.gbl...
I am trying to write a SQL query that will return a record count to my C#
application. I wrote the following query:

ALTER PROCEDURE up_justification_duplicate
AS
SELECT COUNT(*)
FROM tblJustifications

RETURN COUNT(*)
The table has four records in it. Running the query in the IDE gets me the following results:

Running dbo."up_justification_duplicate".
-----------
4
No more results.
(1 row(s) returned)
@RETURN_VALUE = 1
Finished running dbo."up_justification_duplicate".

I have tried to extract the count in my application but all I know how to do is read the return value (always a 1) with a statement like "x =
da.SelectCommand.Parameters[0].Value.ToString();".
How do I get back the correct count, in this case 4?

Any help is greatly appreciated.

Nov 16 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Richard G | last post by:
I'm a database guy, so go easy on me here. :) How can I get the rowcount of the affected rows of a SQL statement from a stored procedure call? I know that "set nocount on" does not return the...
4
by: Mike Dinnis | last post by:
Hi, I've been working through a number of turorials to try to learn more about retrieving data from a SQL database. I think i've mastered techniques where i create a sql string in the page and...
3
by: Beryl Small | last post by:
Hi, I have a third party software that needs to send information to an .aspx page for processing to communicate with an SQL database. The software sends the information something like this: ...
6
by: Max | last post by:
Anyone know why I'm always getting 0 returned? My stored procedure returns -1. Dim iErrorCode As Int32 iErrorCode = Convert.ToInt32(SqlHelper.ExecuteScalar(AppVars.strConn, _ "gpUpdateMember",...
1
by: Gunjan Garg | last post by:
Hello All, I am working to create a generic datagrid which accepts a datasource(ListData - This is our own datatype) and depending on the calling program customizes itself for sorting,...
59
by: Rico | last post by:
Hello, I have an application that I'm converting to Access 2003 and SQL Server 2005 Express. The application uses extensive use of DAO and the SEEK method on indexes. I'm having an issue when...
2
by: rafficabdullah | last post by:
I need to get input from user and search in the database in shell scrpit I have given the code below how to pass the value of varialbe Count to that query . I have bolded the variable since idont...
22
by: Rickster66 | last post by:
As Instructed this is a new thread regarding my original post: "Select Only 10 Columns Going Back" I'm sorry for the late response. I've been gathering up information and carefully with as much...
1
by: raghuvendra | last post by:
Hi I have a jsp page with 4 columns: namely Category name , Category order, Input field and a submit button. All these are aligned in a row. And Each Category Name has its corresponding Category...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.