tweak of A2002 Enterprise Dev Handbook fails?
- From: "pietlinden@xxxxxxxxxxx" <pietlinden@xxxxxxxxxxx>
- Date: Wed, 06 Jun 2007 20:59:49 -0700
I'm tweaking the example on page 240-1 of book... I'm reading from an
Access DB... what's weird is that the create/append parameter part
seems to be ignored. Here's my tweaked code:
Public Sub GetTasks()
'Execute a stored procedure
'without parameters
'that returns records.
Dim cnn As ADODB.Connection
Dim cmd As ADODB.Command
Dim rst As ADODB.Recordset
Dim prm As ADODB.Parameter
Set cnn = CurrentProject.Connection
Set cmd = New ADODB.Command
Set rst = New ADODB.Recordset
Set cmd.ActiveConnection = CurrentProject.Connection
cmd.CommandText = "sp_ActiveSkills"
cmd.CommandType = adCmdStoredProc
' Create the paramater and append it to
' the Command object's Parameters collection.
Set prm = cmd.CreateParameter("WeekendNo", adInteger,
adParamInput, , 1)
cmd.Parameters.Append prm
' Execute the command and place results
' in Recordset object
Set rst = cmd.Execute()
If Not rst.EOF Then
Do Until rst.EOF
Debug.Print rst.Fields(0), rst.Fields(1)
rst.MoveNext
Loop
Else
Debug.Print "recordset contains no records"
End If
rst.Close
Set prm = Nothing
Set rst = Nothing
Set cmd = Nothing
Set cnn = Nothing
End Sub
The only significant differences are that I passed a value in the
CreateParameter line, and omitted the argument. (because it wasn't
working).
What's totally weird is that I get ALL the results back (i.e. an
unfiltered recordset), instead of just the ones I want (for weekNo=1.
Is it something I'm doing wrong? I figured ADH stuff would work
great, but for some reason, this returns weird values. Is it because
I'm not talking to SQL Server, but Access? (but I thought that was the
point of ADO - to generalize the connection to a datastore... huh???)
Thanks!
Pieter
.
- Follow-Ups:
- Re: tweak of A2002 Enterprise Dev Handbook fails?
- From: Bob Barrows [MVP]
- Re: tweak of A2002 Enterprise Dev Handbook fails?
- Prev by Date: Re: Submit Multiple SQL statemtents to one Execute statement
- Next by Date: Recordset.AbsolutePage - strange problem
- Previous by thread: Submit Multiple SQL statemtents to one Execute statement
- Next by thread: Re: tweak of A2002 Enterprise Dev Handbook fails?
- Index(es):
Relevant Pages
|
|