Solved

How do I pass Query parameters to an adodc.

Posted on 2002-05-01
4
478 Views
Last Modified: 2008-02-01
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
Comment
Question by:Dwhite
  • 2
4 Comments
 
LVL 22

Accepted Solution

by:
Mohammed Nasman earned 200 total points
ID: 6985324
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
 

Author Comment

by:Dwhite
ID: 6985345
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
 
LVL 3

Expert Comment

by:n_narayanan
ID: 6985529
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
 

Author Comment

by:Dwhite
ID: 6987881
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now