Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
VFP/ADO/SQL stored procedure syntax
Message
From
06/10/2005 12:57:12
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
 
 
To
06/10/2005 11:18:29
General information
Forum:
Visual FoxPro
Category:
Client/server
Environment versions
Visual FoxPro:
VFP 9
OS:
Windows XP SP2
Network:
Windows 2003 Server
Database:
MS SQL Server
Miscellaneous
Thread ID:
01056781
Message ID:
01056834
Views:
58
>Assuming we have the following SQL stored procedure:
>
>CREATE PROCEDURE usp_test
>	@Number	INT,
>	@NewNumber INT OUTPUT
>AS
>SET @NewNumber = @Number + 3
>RETURN @NewNumber
>GO
>
>
>In VFP we have valid ADODB.Connection object oConn and some variables. I want to use connection's Execute method:
>
>LOCAL lnIn AS Integer, lnOut AS Integer, lnReturn AS Integer
>lnIn=15
>oConn.Execute("What?")
>
>
>What would be the correct syntax for:
>a) getting procedure's return value?
>b) getting procedure's output parameter?
>
>Microsoft claims that it is possible to execute a stored procedure as a native method of a Connection object. Something like this:
>
>lnReturn = oConn.usp_test(lnIn, @lnOut)
>
>I has not been able to get it working. Has anyone?

With ADO I couldn't do it. According the ADO specification this should work but it doesn't:
oConn = CreateObject('ADODB.Connection')
oConn.ConnectionString= "Provider=SQLOLEDB;server=server;"+;
 "Trusted_connection=yes;initial catalog=pubs;"
oConn.Open;

cmd = CREATEOBJECT("ADODB.Command")
cmd.ActiveConnection = oConn
cmd.CommandText = "myStoredProc"
cmd.CommandType = 4
cmd.Parameters.Refresh
cmd.Parameters(1).Value = "FirstParameterTosend"
oRS = loADOCmd.Execute
? cmd.Parameters(0).Value
? oRS.Fields(0).Value
However SPT works nicely:
lnHandle=SQLStringConnect('DRIVER=SQL Server;SERVER=servername;Trusted_connection=Yes')
Text to m.lcSpCall noshow
DECLARE @return_status int
exec @return_status = db.owner.SpName
Select @return_status
endtext
SQLExec(m.lnHandle,m.lcSPCall,'retData')
SQLDisconnect(m.lnHandle)
Probably prototyping it in ADO would work and you would check with NextResultSet. Also you might try:
{? = call storedProc(?,?,?)}
Cetin
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform