Re: Can you see the problem?
- From: "Bob Barrows" <reb01501@xxxxxxxxxxxxxxx>
- Date: Mon, 20 Oct 2008 15:41:38 -0400
jamesfreddyc wrote:
VB6.0 / ADO recordsets / SQLServer 2005
Well, I am attempting to execute a StoredProcedure that is an UPDATE
on one single table in the db. There are no errors thrown and
previous testing on the SProc itself indicates that it works just
fine. But something is not right --- the UPDATE doesn't happen.
Your first step in such a situation should be to fire up SQL Profiler
and run a trace to make sure VB is doing what you expect it to be doing.
However, read on.
<snip>
Public Function rs_UPDATE_Storms(OID As Long, CSCHarge As Double,
UOWCharge As Double, MSCharge As Double) As ADODB.Recordset
On Error GoTo Proc_Err
Set rs_UPDATE_Storms = New ADODB.Recordset
Huh? Why are you using a recordset?
<snip>
ParamCSCHARGE.Type = adDoubleadDouble is not the correct datatype for numeric(38,8) parameters. You
need to use adNumeric, and then set the parameter object's Precision and
NumericScale properties to 38 and 8 before assigning its value.
With ParamCSCHARGE
.Type = adNumeric
.Precision=38
.NumericScale=8
End With
<snip>
pCommand.Parameters.Append ParamOIDThe first parameter you should be appending is the Return parameter,
even if you are not using a return value:
With pCommand
..Parameters.Append .CreateParameter("Return", _
adInteger, adParamReturnValue)
end with
Then append the rest of the parameter objects ... IN THE CORRECT ORDER.
They need to be appended in the same order in which they are declared in
the stored procedure!
cscharge, followed by uowcharge, followed by mscharge, followed by
stormsoid
Named-parameters does not work in VB.
<snip>
Set rs_UPDATE_Storms.ActiveConnection = pConnNo no no - you should be setting the Command object's active connection:
Set pCommand.ActiveConnection = pConn
You should be doing this even if your procedure returns a resultset and
you are planning to open a recordset on that returned resultset.
Oh wait, you already did that before starting the parameter creation
steps up in the part I snipped. The only Activeconnection you need to
set is the Command's.
<snip>
ALTER PROCEDURE [mmsadmin].[Storms_Property_Q2]<snip>
@CSCHARGE numeric(38,8),
@UOWCHARGE numeric(38,8),
@MSCHARGE numeric(38,8),
@STORMSOID int
This procedure does not return a resultset. You should not use a
recordset object to execute it.
This procedure could easily be executed by this code:
pConn.Storms_Property_Q2 CSCHarge, UOWCharge, _
MSCharge, OID
However, most VB programmers prefer to be more explicit, so go ahead and
create the Command object - just use its Execute method without setting
a recordset object to its return value:
pCommand.Execute
--
HTH,
Bob Barrows
.
- Follow-Ups:
- Re: Can you see the problem?
- From: jamesfreddyc
- Re: Can you see the problem?
- References:
- Can you see the problem?
- From: jamesfreddyc
- Can you see the problem?
- Prev by Date: Can you see the problem?
- Next by Date: Re: Can you see the problem?
- Previous by thread: Can you see the problem?
- Next by thread: Re: Can you see the problem?
- Index(es):
Relevant Pages
|