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
Solved

How do I pass Query parameters to an adodc.

Posted on 2002-05-01
4
480 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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
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…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

856 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