Solved

How do I pass Query parameters to an adodc.

Posted on 2002-05-01
4
486 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
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…
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…

718 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