Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / ADO.NET / January 2008

Tip: Looking for answers? Try searching our database.

Calling a stored procedure with a output parameter

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
kkbullen@yahoo.com - 29 Jan 2008 13:45 GMT
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
William Vaughn - 29 Jan 2008 17:32 GMT
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?

Signature

__________________________________________________________________________
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)
____________________________________________________________________________________________

> I've been testing a stored procedure that has an output parameter.
>
[quoted text clipped - 22 lines]
> Thanks,
> Kevin

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.