Categories: MSDN / DotNet / Java / Scripts / Linux / PHP Ask - La ask - La Answer

help With Stored Procedures

Hi!
I Want To Know How Can I Use A Stored Procedure In VB6 (With ADO).
I Don't Know How Can I Use The Parameters From The Stored Procedure.
Any Advise?
Thanks
[190 byte] By [George] at [2007-11-9 18:52:01]
# 1 Re: help With Stored Procedures
First you need to setup the Stored Procedure builder somewhere and install
a C compiler on the DB server, the base VC++ works fine.

Then they from VB they operate just like MS SQL Stored Procedures.

A gotcha I have found converting from MS SQL to UDB is don't use SmallInt
as a parm if you are invoking from VB. I don't understand why, but once I
changed them to Ints they got past that error. I do have several that work,
but I also have one that is issuing a junk message when invoked (see the
question a little further down in this discussion).

KlK, MCSE

"George" <goly@Email.com> wrote:
>
>
>Hi!
>I Want To Know How Can I Use A Stored Procedure In VB6 (With ADO).
>I Don't Know How Can I Use The Parameters From The Stored Procedure.
>
>Any Advise?
>
>Thanks
kevin knudson at 2007-11-12 0:00:41 >
# 2 Re: help With Stored Procedures
Hi,

You can't (yet) use the dataenvironment to automatically create a call
for you as DB2's OLEDB driver doesn't have the required "enumerator"

This code works for me.

Dim SPCall As New ADODB.Command
Dim parm0 As New ADODB.Parameter
Dim parm1 As New ADODB.Parameter

SPCall.CommandText = "MYQUAL.MYFUNC"
SPCall.CommandType = adCmdStoredProc
SPCall.ActiveConnection = gcn 'Setting it to an
existing connection

Set parm0 = SPCall.CreateParameter("myRetVal", adChar, adParamOutput,
20, " ")
SPCall.Parameters.Append parm0
Set parm1 = SPCall.CreateParameter("myIntParm", adSmallInt,
adParamInput, , iSomeInteger)
SPCall.Parameters.Append parm1

SPCall.Execute
returnValue = SPCall(0)

(I've removed extra parameters and error handling from my actual code to
keep the example simple)
--Greg

George wrote:

> Hi!
> I Want To Know How Can I Use A Stored Procedure In VB6 (With ADO).
> I Don't Know How Can I Use The Parameters From The Stored Procedure.
>
> Any Advise?
>
> Thanks
Greg Nash at 2007-11-12 0:01:47 >
# 3 Re: help With Stored Procedures
Hi,

When you say smallint, remember DB2's idea of a small integer is 16 bits

--greg

kevin knudson wrote:

> First you need to setup the Stored Procedure builder somewhere and install
> a C compiler on the DB server, the base VC++ works fine.
>
> Then they from VB they operate just like MS SQL Stored Procedures.
>
> A gotcha I have found converting from MS SQL to UDB is don't use SmallInt
> as a parm if you are invoking from VB. I don't understand why, but once I
> changed them to Ints they got past that error. I do have several that work,
> but I also have one that is issuing a junk message when invoked (see the
> question a little further down in this discussion).
>
> KlK, MCSE
>
> "George" <goly@Email.com> wrote:
> >
> >
> >Hi!
> >I Want To Know How Can I Use A Stored Procedure In VB6 (With ADO).
> >I Don't Know How Can I Use The Parameters From The Stored Procedure.
> >
> >Any Advise?
> >
> >Thanks
Greg Nash at 2007-11-12 0:02:41 >
# 4 Re: help With Stored Procedures
I never really investigated why smallint didn't work. I don't though agree
with your earlier note about 16 bits, as it is passed as a character string,
and I was passing numbers from 1 to 100. Changed to Int it moved to a different
error.
I am doing the stored procs almost unchanged from SQL Server, I'm just adding
the schema name on the front, and changing the date format. Most are working
just fine, although it has been an interesting adventure

KlK, MCSE

Greg Nash <gnash@namoicotton.com.au> wrote:
>Hi,
>
>You can't (yet) use the dataenvironment to automatically create a call
>for you as DB2's OLEDB driver doesn't have the required "enumerator"
>
>This code works for me.
>
> Dim SPCall As New ADODB.Command
> Dim parm0 As New ADODB.Parameter
> Dim parm1 As New ADODB.Parameter
>
> SPCall.CommandText = "MYQUAL.MYFUNC"
> SPCall.CommandType = adCmdStoredProc
> SPCall.ActiveConnection = gcn 'Setting it to an
>existing connection
>
> Set parm0 = SPCall.CreateParameter("myRetVal", adChar, adParamOutput,
>20, " ")
> SPCall.Parameters.Append parm0
> Set parm1 = SPCall.CreateParameter("myIntParm", adSmallInt,
>adParamInput, , iSomeInteger)
> SPCall.Parameters.Append parm1
>
> SPCall.Execute
> returnValue = SPCall(0)
>
>(I've removed extra parameters and error handling from my actual code to
>keep the example simple)
>--Greg
>
>George wrote:
>
>> Hi!
>> I Want To Know How Can I Use A Stored Procedure In VB6 (With ADO).
>> I Don't Know How Can I Use The Parameters From The Stored Procedure.
>>
>> Any Advise?
>>
>> Thanks
>
Kevin Knudson at 2007-11-12 0:03:46 >
# 5 Re: help With Stored Procedures
Hi Kevin,

I'll agree SP's under DB2 has been a bit of an adventure. It's getting there
though...
If you're still having problems, can you post the SP declaration and the calling
code?

--Greg

Kevin Knudson wrote:

> I never really investigated why smallint didn't work. I don't though agree
> with your earlier note about 16 bits, as it is passed as a character string,
> and I was passing numbers from 1 to 100. Changed to Int it moved to a different
> error.
> I am doing the stored procs almost unchanged from SQL Server, I'm just adding
> the schema name on the front, and changing the date format. Most are working
> just fine, although it has been an interesting adventure
>
> KlK, MCSE
>
> Greg Nash <gnash@namoicotton.com.au> wrote:
> >Hi,
> >
> >You can't (yet) use the dataenvironment to automatically create a call
> >for you as DB2's OLEDB driver doesn't have the required "enumerator"
> >
> >This code works for me.
> >
> > Dim SPCall As New ADODB.Command
> > Dim parm0 As New ADODB.Parameter
> > Dim parm1 As New ADODB.Parameter
> >
> > SPCall.CommandText = "MYQUAL.MYFUNC"
> > SPCall.CommandType = adCmdStoredProc
> > SPCall.ActiveConnection = gcn 'Setting it to an
> >existing connection
> >
> > Set parm0 = SPCall.CreateParameter("myRetVal", adChar, adParamOutput,
> >20, " ")
> > SPCall.Parameters.Append parm0
> > Set parm1 = SPCall.CreateParameter("myIntParm", adSmallInt,
> >adParamInput, , iSomeInteger)
> > SPCall.Parameters.Append parm1
> >
> > SPCall.Execute
> > returnValue = SPCall(0)
> >
> >(I've removed extra parameters and error handling from my actual code to
> >keep the example simple)
> >--Greg
> >
> >George wrote:
> >
> >> Hi!
> >> I Want To Know How Can I Use A Stored Procedure In VB6 (With ADO).
> >> I Don't Know How Can I Use The Parameters From The Stored Procedure.
> >>
> >> Any Advise?
> >>
> >> Thanks
> >
Greg Nash at 2007-11-12 0:04:40 >