PC Review


Reply
Thread Tools Rate Thread

ADO: how to execute SQL Server stored procedure and get return val

 
 
jrsmoots
Guest
Posts: n/a
 
      22nd Jun 2009

I have a stored procedure that looks like this:
--=======
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE procAddNewPatient
-- parameters for the stored procedure here
@PatientIDOLD nvarchar(50),
@SiteID tinyint,
@PatientID int Output
AS
BEGIN

SET NOCOUNT ON;

-- Insert statements for procedure here
INSERT INTO tblPatients (PatientIDOLD, SiteID)
VALUES(@PatientIDOLD, @SiteID)

SELECT @PatientID = Scope_Identity()
END
GO
--======

I then call it with this ADO code, which is in an Access 2002 'mdb'

'===
Dim cmd As New adoDB.Command
Dim param1 As New adoDB.Parameter
Dim param2 As New adoDB.Parameter
'Dim param3 As New adoDB.Parameter

'These are here, from the stored procedure, for reference
'@PatientIDOLD nvarchar(50),
'@SiteID tinyint,
'@PatientID int Output


With cmd
.CommandText = "procAddNewPatient"
.CommandType = adCmdStoredProc
.ActiveConnection = CurrentProject.Connection

'the value here is hard coded for tesing purposes
Set param1 = .CreateParameter("@PatientIDOLD", adVarWChar,
adParamInput, 50, "9999999999-ZZ")
.Parameters.Append param1

'the value here is hard coded for tesing purposes
Set param2 = .CreateParameter("@SiteID", adTinyInt,
adParamInput, , 1)
.Parameters.Append param2

Set param3 = .CreateParameter("@PatientID", adInteger,
adParamOutput)
.Parameters.Append param3

.Execute Options:=adExecuteNoRecords

Set param1 = Nothing
Set param2 = Nothing
End With

'Two different ways to display the output parameter
MsgBox param3.Value
MsgBox cmd.Parameters("@PatientID")

Set param3 = Nothing
Set cmd = Nothing

'===

Every time I run the code, it dies when it hits the .Execute command, saying
there's an overflow.

I can't figure this one out, though I'm guessing I've got a setting wrong in
the createparameter statements...

 
Reply With Quote
 
 
 
 
Stefan Hoffmann
Guest
Posts: n/a
 
      23rd Jun 2009

hi,

jrsmoots wrote:
> Every time I run the code, it dies when it hits the .Execute command, saying
> there's an overflow.

This indicates a data type mismatch.

> I can't figure this one out, though I'm guessing I've got a setting wrong in
> the createparameter statements...

Check the parameter data types. Especially the adTinyInt parameter.


mfG
--> stefan <--
 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
how to execute a stored procedure in SQL server from Excel 2007? smwikipedia Microsoft Excel Programming 0 16th Sep 2008 01:17 PM
Need help: Call server side Stored Procedure and get the return va =?Utf-8?B?ZGF2aWQ=?= Microsoft ASP .NET 3 20th Oct 2006 05:09 PM
Checking permission rights using SQL Server Stored Procedure and return values Scott Microsoft Access Form Coding 0 1st Oct 2006 03:22 PM
Capturing return value from SQL Server's stored procedure =?Utf-8?B?UGF0cmljaw==?= Microsoft ADO .NET 2 30th Jul 2005 03:40 AM
Handling exception inside SQL Server stored procedure & return custmised message Amit Microsoft ADO .NET 0 20th Nov 2003 06:49 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:28 AM.