PC Review


Reply
Thread Tools Rate Thread

Calling a stored procedure with a output parameter

 
 
kkbullen@yahoo.com
Guest
Posts: n/a
 
      29th Jan 2008
I've been testing a stored procedure that has an output parameter.

When I add parameters to the sqlcommand this way, the output parameter
returned is always what I pass in:
With InsertLeg
.Transaction = mySQLTrans
.CommandType = CommandType.StoredProcedure
.Parameters.Add(New SqlParameter("@Load_Num", SqlDbType.Int))
.Parameters.Add(New SqlParameter("@RC", SqlDbType.Int, 0,
ParameterDirection.Output))
End With

If I declare the sqlcommand this way, it works, the output parameter
from the stored procedure is returned in the @RC parameter.
With InsertLeg
.Transaction = mySQLTrans
.CommandType = CommandType.StoredProcedure
.Parameters.Add(New SqlParameter("@Load_Num", SqlDbType.Int))
Dim Param As New SqlParameter("@RC", SqlDbType.Int)
Param.Direction = ParameterDirection.Output
.Parameters.Add(Param)
End With

Can someone tell me why these declarations are treated differently?
Thanks,
Kevin
 
Reply With Quote
 
 
 
 
William Vaughn
Guest
Posts: n/a
 
      29th Jan 2008
Frankly, I don't use either syntax to build the Parameters collection, I use
the Constructor.

cmd.Parameters.Add("@Outparm", SqlDbType.Int).Direction =
ParameterDirection.Output

I would also turn on the SQL Profiler to see what's being sent for each
syntax. It would also help to see the stored procedure. Is this "RC" really
the RETURN value?

--
__________________________________________________________________________
William R. Vaughn
President and Founder Beta V Corporation
Author, Mentor, Dad, Grandpa
Microsoft MVP
(425) 556-9205 (Pacific time)
Hitchhiker's Guide to Visual Studio and SQL Server (7th Edition)
____________________________________________________________________________________________
<(E-Mail Removed)> wrote in message
news:3253fc13-598a-488b-872e-(E-Mail Removed)...
> I've been testing a stored procedure that has an output parameter.
>
> When I add parameters to the sqlcommand this way, the output parameter
> returned is always what I pass in:
> With InsertLeg
> .Transaction = mySQLTrans
> .CommandType = CommandType.StoredProcedure
> .Parameters.Add(New SqlParameter("@Load_Num", SqlDbType.Int))
> .Parameters.Add(New SqlParameter("@RC", SqlDbType.Int, 0,
> ParameterDirection.Output))
> End With
>
> If I declare the sqlcommand this way, it works, the output parameter
> from the stored procedure is returned in the @RC parameter.
> With InsertLeg
> .Transaction = mySQLTrans
> .CommandType = CommandType.StoredProcedure
> .Parameters.Add(New SqlParameter("@Load_Num", SqlDbType.Int))
> Dim Param As New SqlParameter("@RC", SqlDbType.Int)
> Param.Direction = ParameterDirection.Output
> .Parameters.Add(Param)
> End With
>
> Can someone tell me why these declarations are treated differently?
> Thanks,
> Kevin


 
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
Stored procedure with output parameter ashtek@gmail.com Microsoft C# .NET 7 6th Dec 2006 03:10 PM
Stored Procedure with Output parameter Phenom Microsoft ADO .NET 13 9th Nov 2005 09:50 PM
Stored procedure parameter output value Steven Microsoft ASP .NET 5 27th May 2004 04:16 AM
Stored procedure parameter output value Steven Microsoft Dot NET 4 27th May 2004 01:28 AM
not getting stored procedure Output Parameter value in VB.net chinns Microsoft ADO .NET 1 30th Jun 2003 03:03 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 09:24 PM.