473,495 Members | 2,021 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Problems with records returned from Stored Proc

CJM
I've created a Stored Procedure which adds a new record and updates some
more records and then returns the primary key for the added record.

The SP seems to work OK, but I'm having problems getting at the returned key
in my ASP code:

"Item cannot be found in the collection corresponding to the requested name
or ordinal."

A common error, but in this case I can't see why... I output the SQL
instruction that is sent to the DB and have run it in Query Analyser and it
runs OK and returns a single row, with a single column - the new primary
key...

But when I try and access this in ASP, I get the error message.

Any ideas? It's bound to be something simple but I just cant see what it
it....

Thanks

Chris

Code snippets
---------------------
ASP:

sSQL = "Exec Orders_GenerateManifest"
response.Write sSQL

Set rsResult = oConn.Execute (sSQL)
response.Write rsResult("ManifestID")

iManifestID = rsResult("ManifestID")

Store Proc:

SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO

/****** Object: Stored Procedure dbo.Orders_GenerateManifest Script
Date: 06/09/2005 12:10:12 ******/
ALTER Proc Orders_GenerateManifest
@CarrierID int,
@CollectionDay tinyint,
@NextDate smalldatetime
As

Set NoCount Off

Declare @ManifestID int

Set @ManifestID = 0

Begin Tran

/* Create Manifest record */
Insert into Manifests
(ManifestDate, CollectionDay, CarrierID)
Values
(@NextDate, @CollectionDay, @CarrierID)

Set @ManifestID = Scope_Identity()

If @ManifestID > 0
Begin
/* Update Order lines */
Update OrderDetail
Set ManifestID = @ManifestID
From OrderDetail D
inner join Orders O on O.OrderID = D.OrderID
inner join Customers C on C.CustomerID = O.CustomerID
Where D.CollectionDay = @CollectionDay
and C.CarrierID = @CarrierID
and (D.ManifestID is null or D.ManifestID = '')

If @@RowCount > 0
Commit tran
Else
Begin
Rollback Tran
Set @ManifestID = 0
End

End
Else
Begin
Rollback Tran
Set @ManifestID = 0
End

Select @ManifestID as ManifestID

Set NoCount Off

GO

SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO

--
cj*******@REMOVEMEyahoo.co.uk
[remove the obvious bits]
Sep 6 '05 #1
6 1605
Do you really mean to have SET NOCOUNT OFF at the beginning or is it
supposed to be ON?

--
Andrew J. Kelly SQL MVP
"CJM" <cj*******@newsgroup.nospam> wrote in message
news:ur**************@TK2MSFTNGP09.phx.gbl...
I've created a Stored Procedure which adds a new record and updates some
more records and then returns the primary key for the added record.

The SP seems to work OK, but I'm having problems getting at the returned
key in my ASP code:

"Item cannot be found in the collection corresponding to the requested
name or ordinal."

A common error, but in this case I can't see why... I output the SQL
instruction that is sent to the DB and have run it in Query Analyser and
it runs OK and returns a single row, with a single column - the new
primary key...

But when I try and access this in ASP, I get the error message.

Any ideas? It's bound to be something simple but I just cant see what it
it....

Thanks

Chris

Code snippets
---------------------
ASP:

sSQL = "Exec Orders_GenerateManifest"
response.Write sSQL

Set rsResult = oConn.Execute (sSQL)
response.Write rsResult("ManifestID")

iManifestID = rsResult("ManifestID")

Store Proc:

SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO

/****** Object: Stored Procedure dbo.Orders_GenerateManifest Script
Date: 06/09/2005 12:10:12 ******/
ALTER Proc Orders_GenerateManifest
@CarrierID int,
@CollectionDay tinyint,
@NextDate smalldatetime
As

Set NoCount Off

Declare @ManifestID int

Set @ManifestID = 0

Begin Tran

/* Create Manifest record */
Insert into Manifests
(ManifestDate, CollectionDay, CarrierID)
Values
(@NextDate, @CollectionDay, @CarrierID)

Set @ManifestID = Scope_Identity()

If @ManifestID > 0
Begin
/* Update Order lines */
Update OrderDetail
Set ManifestID = @ManifestID
From OrderDetail D
inner join Orders O on O.OrderID = D.OrderID
inner join Customers C on C.CustomerID = O.CustomerID
Where D.CollectionDay = @CollectionDay
and C.CarrierID = @CarrierID
and (D.ManifestID is null or D.ManifestID = '')

If @@RowCount > 0
Commit tran
Else
Begin
Rollback Tran
Set @ManifestID = 0
End

End
Else
Begin
Rollback Tran
Set @ManifestID = 0
End

Select @ManifestID as ManifestID

Set NoCount Off

GO

SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO

--
cj*******@REMOVEMEyahoo.co.uk
[remove the obvious bits]

Sep 6 '05 #2
"SET NOCOUNT ON" in the beginning av the SP (instead of SET NOCOUNT
OFF). This gives you one returned recordset. Another (better?) way is to
use an output parameter to return the key.
Regards
Lars Broberg
Elbe-Data AB
http://www.elbe-data.se
Remove "nothing." when replying to private e-mail!
CJM wrote:
I've created a Stored Procedure which adds a new record and updates some
more records and then returns the primary key for the added record.

The SP seems to work OK, but I'm having problems getting at the returned key
in my ASP code:

"Item cannot be found in the collection corresponding to the requested name
or ordinal."

A common error, but in this case I can't see why... I output the SQL
instruction that is sent to the DB and have run it in Query Analyser and it
runs OK and returns a single row, with a single column - the new primary
key...

But when I try and access this in ASP, I get the error message.

Any ideas? It's bound to be something simple but I just cant see what it
it....

Thanks

Chris

Code snippets
---------------------
ASP:

sSQL = "Exec Orders_GenerateManifest"
response.Write sSQL

Set rsResult = oConn.Execute (sSQL)
response.Write rsResult("ManifestID")

iManifestID = rsResult("ManifestID")

Store Proc:

SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO

/****** Object: Stored Procedure dbo.Orders_GenerateManifest Script
Date: 06/09/2005 12:10:12 ******/
ALTER Proc Orders_GenerateManifest
@CarrierID int,
@CollectionDay tinyint,
@NextDate smalldatetime
As

Set NoCount Off

Declare @ManifestID int

Set @ManifestID = 0

Begin Tran

/* Create Manifest record */
Insert into Manifests
(ManifestDate, CollectionDay, CarrierID)
Values
(@NextDate, @CollectionDay, @CarrierID)

Set @ManifestID = Scope_Identity()

If @ManifestID > 0
Begin
/* Update Order lines */
Update OrderDetail
Set ManifestID = @ManifestID
From OrderDetail D
inner join Orders O on O.OrderID = D.OrderID
inner join Customers C on C.CustomerID = O.CustomerID
Where D.CollectionDay = @CollectionDay
and C.CarrierID = @CarrierID
and (D.ManifestID is null or D.ManifestID = '')

If @@RowCount > 0
Commit tran
Else
Begin
Rollback Tran
Set @ManifestID = 0
End

End
Else
Begin
Rollback Tran
Set @ManifestID = 0
End

Select @ManifestID as ManifestID

Set NoCount Off

GO

SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO

Sep 6 '05 #3
CJM wrote:
Set NoCount Off


This statement is probably the problem. Remove it and see if it helps.

Bob Barrows
--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.
Sep 6 '05 #4
CJM,

Why are you setting "set nocount off" at the beginning of the sp?
ALTER Proc Orders_GenerateManifest
@CarrierID int,
@CollectionDay tinyint,
@NextDate smalldatetime
As

Set NoCount Off
it should be set "on", to avoid sql server returning the msg of rows
affected by the dml statement to the client app as if it were a recordset. If
you insist in doing this, then you have to use the method nextrecordset of
the recordset object to get traverse all recordsets sent by sql server.
AMB

"CJM" wrote:
I've created a Stored Procedure which adds a new record and updates some
more records and then returns the primary key for the added record.

The SP seems to work OK, but I'm having problems getting at the returned key
in my ASP code:

"Item cannot be found in the collection corresponding to the requested name
or ordinal."

A common error, but in this case I can't see why... I output the SQL
instruction that is sent to the DB and have run it in Query Analyser and it
runs OK and returns a single row, with a single column - the new primary
key...

But when I try and access this in ASP, I get the error message.

Any ideas? It's bound to be something simple but I just cant see what it
it....

Thanks

Chris

Code snippets
---------------------
ASP:

sSQL = "Exec Orders_GenerateManifest"
response.Write sSQL

Set rsResult = oConn.Execute (sSQL)
response.Write rsResult("ManifestID")

iManifestID = rsResult("ManifestID")

Store Proc:

SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO

/****** Object: Stored Procedure dbo.Orders_GenerateManifest Script
Date: 06/09/2005 12:10:12 ******/
ALTER Proc Orders_GenerateManifest
@CarrierID int,
@CollectionDay tinyint,
@NextDate smalldatetime
As

Set NoCount Off

Declare @ManifestID int

Set @ManifestID = 0

Begin Tran

/* Create Manifest record */
Insert into Manifests
(ManifestDate, CollectionDay, CarrierID)
Values
(@NextDate, @CollectionDay, @CarrierID)

Set @ManifestID = Scope_Identity()

If @ManifestID > 0
Begin
/* Update Order lines */
Update OrderDetail
Set ManifestID = @ManifestID
From OrderDetail D
inner join Orders O on O.OrderID = D.OrderID
inner join Customers C on C.CustomerID = O.CustomerID
Where D.CollectionDay = @CollectionDay
and C.CarrierID = @CarrierID
and (D.ManifestID is null or D.ManifestID = '')

If @@RowCount > 0
Commit tran
Else
Begin
Rollback Tran
Set @ManifestID = 0
End

End
Else
Begin
Rollback Tran
Set @ManifestID = 0
End

Select @ManifestID as ManifestID

Set NoCount Off

GO

SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO

--
cj*******@REMOVEMEyahoo.co.uk
[remove the obvious bits]

Sep 6 '05 #5
CJM

"Andrew J. Kelly" <sq************@shadhawk.com> wrote in message
news:OI**************@TK2MSFTNGP10.phx.gbl...
Do you really mean to have SET NOCOUNT OFF at the beginning or is it
supposed to be ON?

--
Andrew J. Kelly SQL MVP


F&^k!
DŁ"n!
B&%(&r!

See, I told you it was something simple...

Thanks

Andrew
Sep 6 '05 #6
Bob Barrows [MVP] wrote:
CJM wrote:
Set NoCount Off


This statement is probably the problem. Remove it and see if it helps.


Oops, I missed the fact that you used "Off" at the beginning of the
procedure as well. Due to quickly skimming, I read it as "On".

I was talking about the final "nocount" statement in the procedure: I was
suspecting that it might cause an informational message to be sent ... even
if that's not the case, the statement is not needed. "SET NOCOUNT ON" only
applies while the procedure is in scope, and it only applies to the thread
in which the procedure is running.

Bob Barrows
--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.
Sep 6 '05 #7

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

Similar topics

3
1215
by: bigDWK | last post by:
Hi- I'm having problems with the following stored procedure. Below first I have the stored proc, then I have the asp code that calls it. Randomly it won't insert the order into the database and a...
2
2126
by: M Wells | last post by:
Hi All, Just wondering if you perform an update using a where condition that actually returns no rows to be updated, does @@Error contain an error message afterwords? We want to fire an...
1
3365
by: Jamal | last post by:
I am working on binary files of struct ACTIONS I have a recursive qsort/mergesort hybrid that 1) i'm not a 100% sure works correctly 2) would like to convert to iteration Any comments or...
6
2856
by: Jamal | last post by:
I am working on binary files of struct ACTIONS I have a recursive qsort/mergesort hybrid that 1) i'm not a 100% sure works correctly 2) would like to convert to iteration Any comments or...
16
1891
by: LP | last post by:
Hi, Every morning a .NET application downloads a file with cumulative data which needs to be appended to SQL Server table. This program needs to identify records that have not been previously...
2
1517
by: Jiggaz | last post by:
Hi, I have a stored procedure (ms sql 2005) which is return add the user in the table USERS. But the sp (stored proc) tests if a user with the desired nickname already exists. If exists, return...
1
4135
by: rbg | last post by:
I am using derived tables to Page data on the SQL Server side. I used this link as my mentor for doing paging on the SQL Serverhttp://msdn2.microsoft.com/en-us/library/ms979197.aspx I wanted to...
8
2787
by: rbg | last post by:
I did use query plans to find out more. ( Please see the thread BELOW) I have a question on this, if someone can help me with that it will be great. In my SQL query that selects data from table,...
4
2317
by: Connie | last post by:
I have a query that takes blobs that have been created within the last day out of sql server and places them on a disk drive. The query is a stored proc which runs in a DTS job. The job shows...
0
7120
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
6991
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7160
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,...
1
6878
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
7373
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...
1
4897
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...
0
3078
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1405
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
649
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.