Solved

How do I pass Query parameters to an adodc.

Posted on 2002-05-01
4
475 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:
mnasman 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

743 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

10 Experts available now in Live!

Get 1:1 Help Now