Click here to Skip to main content
15,909,530 members
Home / Discussions / Database
   

Database

 
Generaldata communication method Pin
Irfan12-Mar-01 3:28
Irfan12-Mar-01 3:28 
GeneralRe: data communication method Pin
Anders Molin19-Mar-01 7:01
professionalAnders Molin19-Mar-01 7:01 
Generaldata communication method Pin
Irfan12-Mar-01 3:27
Irfan12-Mar-01 3:27 
GeneralGetting Interbase Data through ADO. Pin
5-Mar-01 18:00
suss5-Mar-01 18:00 
GeneralNested outer joins Pin
5-Mar-01 0:20
suss5-Mar-01 0:20 
GeneralRe: Nested outer joins Pin
Bob Zagars17-Jan-06 20:48
Bob Zagars17-Jan-06 20:48 
GeneralADO RecordSet Paging & Netscape Pin
4-Mar-01 4:55
suss4-Mar-01 4:55 
GeneralProblem with a MTS-DAL (Data Access Layer) VB Object Pin
2-Mar-01 12:09
suss2-Mar-01 12:09 
Kind all,
I built this MTS object that runs a SP and should be able to returns to the user:

'1) (if existing) the Rs(s) found for the wanted DB table(s);
'2) the adParamOutput, adParamReturnValue ADODB.Parameters
from the SP.

When I run the component the following things happen:

* the adParamOutput and the adParamReturnValue ARE EMPTY
(note that I forced the SP to return in any case a Return value and a value as output paramter).

** when I loop the array that should comntain all the RS(s) contained in a specific DB field, I get
the usual "Subscript out of range".

I poste my code: both the code (DBObj.cls) for the DB object and the code (.frm) I used x testing it.

The name of the DLL project is: OggettoDB.


-----------------START OF THE DB OBJ (DBObj.cls)----------
Option Explicit
Implements ObjectControl
Dim ctxObject As ObjectContext

'******************************************************************************************
'this function should returns:
'1) all the Rs found for the wanted DB table fields: Id(), Datacurr(), TipoRep() and path()
'are the arrays that should contain the found Rs(s) for the 4 choiched DB fields;
'all these are passed byref
'2) the adParamReturnValue parameter: I choiched here that the return value from the
'SP be the return value of this function
'3) the adParamOutput: is the outparam passed byref too.
'4) currdata is the adParamInput
'*******************************************************************************************

Public Function RunAnySP(Id() As Variant, Datacurr() As Variant, TipoRep() As Variant, _
path() As Variant, outparam As Variant, ByVal currdata As Variant) As Variant


'ho scelto che il valore di ritorno della funzione sia il valore di ritorno dalla SP

Dim Cn As ADODB.Connection, Rs As ADODB.Recordset
Dim Cmd As ADODB.Command
Dim Param1 As ADODB.Parameter, Param2 As ADODB.Parameter, Param3 As ADODB.Parameter

On Error GoTo ErrorHandler

Dim cnstring As String
cnstring = "Provider=SQLOLEDB.1;Initial Catalog=Finanza;Data Source=direct-comflcg;"

Cn.Open cnstring
Set Cmd.ActiveConnection = Cn
Cmd.CommandText = "myProc"
Cmd.CommandType = adCmdStoredProc

Set Param1 = Cmd.CreateParameter("paramimput", adDate, adParamInput, currdata)
Cmd.Parameters.Append Param1

Set Param2 = Cmd.CreateParameter("parametroutput", adInteger, adParamOutput)
Cmd.Parameters.Append Param2

Set Param3 = Cmd.CreateParameter("valoreritorno", adInteger, adParamReturnValue)
Cmd.Parameters.Append Param3

Set Rs = Cmd.Execute

'Dim recordsAff As Long
'Cmd.Execute recordsAff

'If recordsAff = 0 Then MsgBox "Nessun record trovato/inserito!"


'here I fill the 4 array (corresponding to the 4 choiched DB fields) with the data found in the DB

Dim contatore As Variant
contatore = 0

While Not Rs.EOF

Id(contatore) = Rs.Fields(0)
Datacurr(contatore) = Rs.Fields(1)
TipoRep(contatore) = Rs.Fields(2)
path(contatore) = Rs.Fields(3)

contatore = contatore + 1
Rs.MoveNext

Wend

Rs.Close

'After having close the Rs I assign its value to the parameter n 1: as I said, this is the outparam
outparam = Cmd.Parameters(1)



'as I already said, the return value of the function is the adParamReturnValue
Set RunAnySP = Param3
Cn.Close

Set Cn = Nothing
Set Rs = Nothing
Set Cmd = Nothing


ctxObject.SetComplete
Exit Function
ErrorHandler:
If Not Cmd Is Nothing Then
Set Cmd = Nothing
End If

If Not Rs Is Nothing Then
Set Rs = Nothing
End If

If Not Cmd Is Nothing Then
Set Cmd = Nothing
End If


ctxObject.SetAbort

End Function





Private Sub ObjectControl_Activate()
Set ctxObject = GetObjectContext()
End Sub

Private Function ObjectControl_CanBePooled() As Boolean
ObjectControl_CanBePooled = False
End Function

Private Sub ObjectControl_Deactivate()
Set ctxObject = Nothing
End Sub

----------------START OF CODE X THE .FRM MODULE-----------

Option Explicit
Option Base 1


Private Sub Form_Load()

Dim OggettoDB As OggettoDB.DBObj

Dim id() As Variant
Dim Data() As Variant
Dim Tipo() As Variant
Dim Path() As Variant
Dim out As Variant

Dim myvar As Variant
Dim parainput As Variant
parainput = "1/16/2001"


Set OggettoDB = CreateObject("OggettoDb.DBObj")


myvar = OggettoDB.RunAnySP(id(), Data(), Tipo(), Path(), out, parainput)
'myvar is the return value
MsgBox myvar 'the value is empty

MsgBox out 'the value is empty too Frown | :-(

Dim x As Integer
For x = 0 To UBound(Data) 'when I start this cycle I get out of range error
MsgBox Data(x)
Next x



End Sub






Private Sub ObjectControl_Activate()
Set ctxObject = GetObjectContext()
End Sub

Private Function ObjectControl_CanBePooled() As Boolean
ObjectControl_CanBePooled = False
End Function

Private Sub ObjectControl_Deactivate()
Set ctxObject = Nothing
End Sub
GeneralAdding first record in the Database Pin
yamini2-Mar-01 0:05
yamini2-Mar-01 0:05 
GeneralRe: Adding first record in the Database Pin
14-Mar-01 7:02
suss14-Mar-01 7:02 
QuestionMS-SQL use HASHING for text key..??!?!? Pin
26-Feb-01 11:00
suss26-Feb-01 11:00 
AnswerRe: MS-SQL use HASHING for text key..??!?!? Pin
Bob Zagars17-Jan-06 20:55
Bob Zagars17-Jan-06 20:55 
QuestionHow to Lock Records with ODBC Access 2000 Driver ??? Pin
Ariel25-Feb-01 11:19
Ariel25-Feb-01 11:19 
GeneralIDispatch Error #3092 when I execute a stored proc that does an insert on a Sybase SQL Anywhere. Why can I find the meaning of such errors. Pin
21-Feb-01 19:27
suss21-Feb-01 19:27 
GeneralRe: IDispatch Error #3092 when I execute a stored proc that does an insert on a Sybase SQL Anywhere. Why can I find the meaning of such errors. Pin
25-Feb-01 10:45
suss25-Feb-01 10:45 
QuestionHow do you return the primarykey/identity value after an INSERT using ODBC or ADO (without a stored proc) Pin
21-Feb-01 19:09
suss21-Feb-01 19:09 
AnswerRe: How do you return the primarykey/identity value after an INSERT using ODBC or ADO (without a stored proc) Pin
22-Feb-01 16:20
suss22-Feb-01 16:20 
AnswerRe: How do you return the primarykey/identity value after an INSERT using ODBC or ADO (without a stored proc) Pin
Chris Maunder14-Mar-01 9:48
cofounderChris Maunder14-Mar-01 9:48 
AnswerRe: How do you return the primarykey/identity value after an INSERT using ODBC or ADO (without a stored proc) Pin
Bob Zagars17-Jan-06 21:03
Bob Zagars17-Jan-06 21:03 
GeneralRecord Headers in ListBox and retrival Pin
Ariel21-Feb-01 14:20
Ariel21-Feb-01 14:20 
GeneralTrying to Lock Records in ODBC Pin
Ariel21-Feb-01 14:10
Ariel21-Feb-01 14:10 
GeneralRe: Trying to Lock Records in ODBC Pin
Anders Molin23-Feb-01 2:56
professionalAnders Molin23-Feb-01 2:56 
GeneralRe: Trying to Lock Records in ODBC Pin
Ariel24-Feb-01 23:38
Ariel24-Feb-01 23:38 
GeneralCreating Database with ADO Pin
yamini20-Feb-01 19:40
yamini20-Feb-01 19:40 
GeneralCreating Database with ADO Pin
yamini20-Feb-01 19:40
yamini20-Feb-01 19:40 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.