Re: how to retrieve [RecordsAffected] count from cmd.Excecute in V
- From: "Daniel Crichton" <msnews@xxxxxxxxxxxxxxxx>
- Date: Tue, 25 Apr 2006 11:18:18 +0100
ADO should handle getting the value back for you into the variable. Did you
try declaring it as a Long instead of Variant?
Are you doing a SET NOCOUNT ON anywhere in the connection before running
this proc?
The only other thing I can think of is that the proc is confusing ADO by
returning a recordset. As you don't need this (you're using .Execute without
assigning the result to a Recordset object) try removing the SELECT
statement in your proc. I don't use SELECTs in my non-recordset returning
procs where I use RecordsAffected - as I never do anything with the returned
data, there's no point in returning it and wasting resources.
Dan
Rich wrote on Mon, 24 Apr 2006 13:47:01 -0700:
The SP is real basic
------------------------------------------
Create Proc stp_test1
As
Insert Into tbl1(fld1, fld2, fld3)
Select fdl1, fld2, fld3 from tbl2
Go
-------------------------------------------
Is there some @@ object I need to use get the recordsAffected count?
"Daniel Crichton" wrote:
Rich wrote on Thu, 20 Apr 2006 13:59:01 -0700:
Dim cmd As New ADODB.Command, j As variant
...
cmd.ActiveConnection.CursorLocation = adUseClient
cmd.CommandType = adCmdStoredProc
cmd.CommandText = "stp_Proc1"
'--Proc1 inserts rows into a table, for example
cmd.Excecute(j) '--[RecordsAffected]
Debug.Print j
j is always null. In Query Analyzer the message tab will say "29
records affected" when I execute the SP. How can I retrieve that count
from cmd.Execute in my VB app? If I use an ADODB recordset Object I
have to use
cmd.ActiveConnection.CursorLocation = adUseClient
to get a value from RS.RecordCount other than 0. I tried
cmd.ActiveConnection.CursorLocation = adUseClient and adUseServer for
the RecordsAffected count, but neither returned a value for
RecordsAffected. Any suggestions appreciated.
MSDN defines RecordsAffected as being a Long, so first thing I'd do is
change the variable definition in case that is causing a problem.
What is the code in stp_Proc1? I've used the RecordsAffected value many
times to determine if my proc does anything and so far I've never seen it
return null, always a 0 or a number.
Dan
.
- Follow-Ups:
- References:
- Re: how to retrieve [RecordsAffected] count from cmd.Excecute in VB?
- From: Daniel Crichton
- Re: how to retrieve [RecordsAffected] count from cmd.Excecute in VB?
- Prev by Date: RE: oledb problem in VS2005
- Next by Date: ADO270.CHM help file
- Previous by thread: Re: how to retrieve [RecordsAffected] count from cmd.Excecute in VB?
- Next by thread: Re: how to retrieve [RecordsAffected] count from cmd.Excecute in V
- Index(es):
Relevant Pages
|
|