Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How to ADO?
Message
From
18/09/2002 09:43:37
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
 
 
To
18/09/2002 08:40:52
General information
Forum:
Visual FoxPro
Category:
Other
Title:
Miscellaneous
Thread ID:
00701705
Message ID:
00701751
Views:
19
>Hi group.
>
>I'm now learning how to use ADO connections, recordSets and Commands. To use this, i'm testing on a VFP-made Database, just to learn how ADO works.
>This code should access a PK-Generation Stored Procedure in the DB. I'm using the following code for tests:
>
>
>oConn = CREATEOBJECT([AdoDB.Connection])
>oRS = CREATEOBJECT([AdoDB.recordSet])
>oCmd = CREATEOBJECT([AdoDB.Command])
>*-- Parâmetro OUTPUT da SP = lnId
>*-- Valor de OutPut para oPrm1.Direction = 2
>*-- Parâmetro INPUT da SP = tcCampo
>*-- Valor de Input para oPrm2.Direction = 1
>lcConnString = [Provider = VFPOleDB.1; Data Source = d:\TESTE\MEUBD.DBC]
>oConn.CursorLocation = 2  && adUseServer
>oCOnn.Mode = 16  && adModeShareDenyNone
>oConn.Open(lcConnString)
>oCmd.CommandType = 4 && Stored Procedure
>oCmd.CommandText = [_st_GeraId] && Nome da Procedure
>oPrm1 = oCmd.CreateParameter()
>oPrm1.Name = [lnId]
>oPrm1.Type = 3  && adInteger
>oPrm1.Direction = 2
>oPrm1.Size = 4 && bytes
>oPrm1.Value = 0 && inicializei o valor de retorno.
>oCmd.Parameters.Append(oPrm1)
>oCmd.CreateParameter()
>oPrm2 = oCmd.CreateParameter()
>oPrm2.Name = [tcCampo]
>oPrm2.Type = 200  && adVarChar
>oPrm2.Direction = 1 && input Parameter
>oPrm2.Size = 25 && Um campo pode ter no máximo 25 caracteres, neste caso específico
>oPrm2.Value = [MinhaPK]
>oCmd.Parameters.Append(oPrm2) && Anexando outro parâmetro ao objeto oCmd
>oCmd.Execute() && Para executar o Comando
>
>
>This Code returns me:
>
>OLE IDispatch Exception code 0 From ADODB.Command: The connection cannot be used to perform this operation. It is either closed or invalid in this context...
>
>What's going on? Did I forget anything?
>
>Grato...

Pablo,
A side note :
You don't need to create recordset and parameters objects to execute a stored procedure. A connection would do. Assuming you need for an asp page ie:

set rsc = oconnection.execute("myStoredProc('ReverseMe')")
response.write(rsc.fields(0).value)

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