473,320 Members | 1,950 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,320 software developers and data experts.

returning data from a stored procedure

If you have a stored procedure that may return one row or many rows, but
you only actually want the first row, should you use a datareader or
dataset, or will just reading the output parameters give you the first
row?

CREATE PROCEDURE CCFindData
(
@sessionid bigint output,
@purchaseid bigint output
)

AS
select @sessionid = sessionid, @purchaseid = purchaseid
from attemptedpurchase
where status = 0
GO
DResult drFindData;
lngCurrentSession = 0;
lngCurrentID = 0;

SqlConnection objConnection = GetConnection(strConnectMcCallumTest);
SqlCommand objCommand = new SqlCommand("CCFindData", objConnection);

objCommand.CommandType = CommandType.StoredProcedure;

SqlParameter prmSessionID = new SqlParameter("@SessionID",
SqlDbType.BigInt, 8);
prmSessionID.Direction = ParameterDirection.Output;
objCommand.Parameters.Add(prmSessionID);

SqlParameter prmPurchaseID = new SqlParameter("@PurchaseID",
SqlDbType.BigInt, 8);
prmPurchaseID.Direction = ParameterDirection.Output;
objCommand.Parameters.Add(prmPurchaseID);
try
{
objConnection.Open();
objCommand.ExecuteNonQuery();
objConnection.Close();

if (prmSessionID.Value != System.DBNull.Value)
{
strPurchaseID = Convert.ToString(prmPurchaseID.Value);
strSessionID = Convert.ToString(prmSessionID.Value); drFindData =
DResult.Valid;
}
else
{
drFindData = DResult.Invalid;
}
}
catch
{
drFindData = DResult.Error;
}
Cheers,

Mike

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 16 '05 #1
8 2438
That stored procedure won't return any rows, it only returns the out params.

Regards

Richard Blewett - DevelopMentor
http://www.dotnetconsult.co.uk/weblog
http://www.dotnetconsult.co.uk

nntp://news.microsoft.com/microsoft.public.dotnet.languages.csharp/<eL**************@TK2MSFTNGP12.phx.gbl>

If you have a stored procedure that may return one row or many rows, but
you only actually want the first row, should you use a datareader or
dataset, or will just reading the output parameters give you the first
row?

CREATE PROCEDURE CCFindData
(
@sessionid bigint output,
@purchaseid bigint output
)

AS
select @sessionid = sessionid, @purchaseid = purchaseid
from attemptedpurchase
where status = 0
GO
Nov 16 '05 #2
That stored procedure won't return any rows, it only returns the out params.

Regards

Richard Blewett - DevelopMentor
http://www.dotnetconsult.co.uk/weblog
http://www.dotnetconsult.co.uk

nntp://news.microsoft.com/microsoft.public.dotnet.languages.csharp/<eL**************@TK2MSFTNGP12.phx.gbl>

If you have a stored procedure that may return one row or many rows, but
you only actually want the first row, should you use a datareader or
dataset, or will just reading the output parameters give you the first
row?

CREATE PROCEDURE CCFindData
(
@sessionid bigint output,
@purchaseid bigint output
)

AS
select @sessionid = sessionid, @purchaseid = purchaseid
from attemptedpurchase
where status = 0
GO
Nov 16 '05 #3
That's what I meant, just the out parameters. I've tried this code and
it always seems to return the LAST set of output parameters that meet
this condition. I suppose I could get around this by changing my stored
procedure to order records in descending order, but I'm guessing this is
not the best way to do this?
Mike

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 16 '05 #4
That's what I meant, just the out parameters. I've tried this code and
it always seems to return the LAST set of output parameters that meet
this condition. I suppose I could get around this by changing my stored
procedure to order records in descending order, but I'm guessing this is
not the best way to do this?
Mike

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 16 '05 #5
select top 1 @sessionid = sessionid, @purchaseid = purchaseid
from attemptedpurchase
where status = 0

does that do what you want?

Regards

Richard Blewett - DevelopMentor
http://www.dotnetconsult.co.uk/weblog
http://www.dotnetconsult.co.uk

nntp://news.microsoft.com/microsoft.public.dotnet.languages.csharp/<e3**************@TK2MSFTNGP15.phx.gbl>

That's what I meant, just the out parameters. I've tried this code and
it always seems to return the LAST set of output parameters that meet
this condition. I suppose I could get around this by changing my stored
procedure to order records in descending order, but I'm guessing this is
not the best way to do this?
Mike

Nov 16 '05 #6
select top 1 @sessionid = sessionid, @purchaseid = purchaseid
from attemptedpurchase
where status = 0

does that do what you want?

Regards

Richard Blewett - DevelopMentor
http://www.dotnetconsult.co.uk/weblog
http://www.dotnetconsult.co.uk

nntp://news.microsoft.com/microsoft.public.dotnet.languages.csharp/<e3**************@TK2MSFTNGP15.phx.gbl>

That's what I meant, just the out parameters. I've tried this code and
it always seems to return the LAST set of output parameters that meet
this condition. I suppose I could get around this by changing my stored
procedure to order records in descending order, but I'm guessing this is
not the best way to do this?
Mike

Nov 16 '05 #7
Thanks Richard!
Cheers,

Mike

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 16 '05 #8
Thanks Richard!
Cheers,

Mike

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 16 '05 #9

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

Similar topics

0
by: Golawala, Moiz M (GE Infrastructure) | last post by:
Hi All, I am having problem returning values from a Stored Procedure that creates a dynamic table (table variable) inserts values during a procedure and then I select from that dynamic table to...
4
by: Michael Trosen | last post by:
Hi Everyone, I hope someone can help, I'm pretty new to pro*c programming. I have the following application setup: a pro*c program calls a stored procedure and recieves a cursor back: the...
5
by: Stanley Sinclair | last post by:
I have a need to return multiple result sets from a stored procedure. Want that SP to call others to get the data. Win2003, db2 8.1.5. Can't figure out how to handle open cursors, and return...
1
by: Todd Peterson | last post by:
I'm a newbie to DB2 and am trying to figure out how to write a stored procedure, using dynamic SQL statements to return a result set. I believe the majority of the hurdles I have been facing might...
3
by: Mike P | last post by:
Is it possible to return a dataset from a stored procedure, or would you need to write the SQL in your .cs file to return the dataset? Any assistance would be really appreciated. Cheers, ...
1
by: Peter Rilling | last post by:
To minimize database calls, I would like to have a single stored procedure return all the data necessary to display on my page. This information is related from several different tables and what I...
1
by: j090757 | last post by:
Returning parm data to vb.net from AS400 stored procedure This example loads a textbox which is used by javascript for error handling. First create the stored procedure on the AS400: CREATE...
1
by: Joe Van Meer | last post by:
Hi all, I have an app that currently runs through 3 seperate stored procedures each returning a count of records. What I would like to do is combine these calls into one call, however I am...
4
by: scparker | last post by:
Hello, We have a stored procedure that does a basic insert of values. I am then able to retrieve the ID number created for this new record. We are currently using ASP.NET 2.0 and use N-Tier...
3
by: bogdan | last post by:
Hi, I have a stored procedure that returns a single value. Example: SELECT @RowCount = COUNT(*) FROM t WHERE RETURN @RowCount I created a data set, table adapter, and adapter's method...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.