[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 500
  • Last Modified:

How do I pass Query parameters to an adodc.

I need to set up my ado Data Control to use a Parameterised Query.
I have set the .CommandType to adCmdStoredProc and the stored procedure name to the name of my Query but how do I set the parameters of the Query.

For various reasons I can't create the recordset first and then assign that recordset to the adodc.
e.g. Set adodc.RecordSet = RecordSet
If I do this then one of my problems is that I can't use adodc.RecordSet.AbsolutePosition because it always returns -1.
0
Dwhite
Asked:
Dwhite
  • 2
1 Solution
 
Mohammed NasmanSoftware DeveloperCommented:
Hello

  I think adodc.RecordSet.AbsolutePosition will not working with you, cuz it's need curos location to be in the client

 try to set the CursorLocation to : adUseClient

0
 
DwhiteAuthor Commented:
Hello mnasman

That is possible as I am using a server side cursor.
The project is at Home I will let U know tomorrow.

I would still like to know if I can set the parameters for the ADO Data Control.
Thanks for your Input
Dean.
0
 
n_narayananCommented:
Check this,

http://www.vbusers.com/code/codeget.asp?ThreadID=130&PostID=1&NumReplies=0

I am also appending the code

The following routine calls DAO parameterized queries from ADO without
using ADOX. A demonstration routine can be found at the bottom of this post:

'Purpose   :    Run a parameterised DAO query using ADO
'Inputs    :    cCon            ADO Database connection
'               sQueryName      Name of the query
'               avResults       Array of results returned from the query
'               avParameters    Array of parameters to pass into the query.
'                               The array should be a zero based 1d variant array
'Outputs   :    Returns True if the routines fails to run the query
'Author    :    Andrewb
'Date      :    21/08/2000
'Notes     :    
'Revisions :

Function ExecuteParamQuery(cCon As ADODB.Connection, sQueryName As String, avResults As Variant, ParamArray avParameters() As Variant) As Boolean
    Dim Cmd As ADODB.Command, rsResults As ADODB.Recordset
   
    On Error GoTo ErrFailed
    Set Cmd = New ADODB.Command
    'Create the command
    Set Cmd.ActiveConnection = cCon
    Cmd.CommandText = sQueryName
    'Execute the Command, passing in the parameter values
    Set rsResults = Cmd.Execute(, avParameters, adCmdStoredProc)
    If rsResults.EOF = False Then
        'Recordset contains values
        avResults = rsResults.GetRows
        rsResults.Close
        Set rsResults = Nothing
    Else
        'Empty the result array
        avResults = Nothing
    End If
    Set Cmd = Nothing
   
    Exit Function
   
ErrFailed:
    'Failed to run query
    ExecuteParamQuery = True
End Function


'Demonstration routine:
Private Sub Command1_Click()
    Dim cCon As New adodb.Connection, avResults As Variant, vThisItem As Variant

    'Assumes there is a database called "Test.mdb" in the application directory
    cCon.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\test.mdb;Persist Security Info=False"
    'See below for "qryGetSurname" SQL
    ExecuteParamQuery cCon, "qryGetSurname", avResults, "Andrew"
    'Print results
    For Each vThisItem In avResults
        Debug.Print CStr(vThisItem)
    Next
End Sub

'SQL for qryGetSurname:
'SELECT tblNames.Surname, tblNames.FirstName
'From tblNames
'WHERE (((tblNames.FirstName)=[iFirstName]));
0
 
DwhiteAuthor Commented:
Thanks you it does work.
But it still does not answer the Question of weather you can or can't assign parameters to a query in the ado data control.
We'll leave that for another Time :-)
Thank you again.
Dean.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now