none
Setting Parameter to DB Query using ADODB RRS feed

  • Question

  • Hi,

    I need to use the below query where the input parameter is "Name"

    QueryStr = "Select custCode where name = ?"

    I refereed the link provided by microsoft. https://docs.microsoft.com/en-us/sql/ado/guide/data/command-object-parameters

    But in the below statement they are initializing the default param as below:

    ' Create new parameter for CustomerID. Initial value is ALFKI. Set objParm1 = objCmd.CreateParameter("CustId", adChar, _ adParamInput, 5, "ALFKI")

    But in my case, i should not initialize the default param. Can you please let me know how to achive this.

    _________________________________________________________________________

    My Currentt Code in VB as

    QueryStr = "Select custCode where name = ?"

    Set conObj= CreateObject("ADODB.Connection")
    conObj.CommandTimeout = 300

    conObj.Open strConnString

    Set objRecordSet = CreateObject("ADODB.RecordSet")

    objRecordSet.Open QueryStr,strConnString,3 

    The above code is working fine if my query is QueryStr = "Select custCode where name = 'ABC'" but not working when it is QueryStr = "Select custCode where name = ?". This is because i need to pass the param.

    Can you please help on this

    Tuesday, July 4, 2017 3:20 PM

All replies

  • Hello,

    Is this VB.NET, VB6 or withing ms-access in a module?

    For the record this forum is for vb.net only. If not vb.net I can make suggestions based on your reply.


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    Tuesday, July 4, 2017 3:48 PM
  • Karen,

    You know this is not VB for Visual Studio Net. 

    The Set will be direct removed. 


    Success
    Cor

    Tuesday, July 4, 2017 4:05 PM
  • Karen,

    You know this is not VB for Visual Studio Net. 

    The Set will be direct removed. 


    Success
    Cor

    Yes I do but need to know where to direct them properly by their reply.

    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    Tuesday, July 4, 2017 4:30 PM
  • http://social.msdn.microsoft.com/Forums/vstudio/en-US/home?forum=isvvba

    There they surely can handle this even if it is for an older version of VB For Visual studio 1997 or 1998


    Success
    Cor

    Tuesday, July 4, 2017 4:32 PM
  • Its VB Script. .vbs is my query extension

    I am new to VBS, dont know how to check the version. 

    Tuesday, July 4, 2017 4:47 PM
  • Yea there is the scriptingguys forum. However, for this probably the VBA forum (Visual Basic for Applications) is better, it has the same code but is more for Access databases. 


    Success
    Cor


    Tuesday, July 4, 2017 6:06 PM
  • Can someone help me to move it to correct forum /group
    Tuesday, July 4, 2017 6:18 PM
  • Can someone help me to move it to correct forum /group
    Please read my first reply, otherwise I may move your question to the wrong forum.

    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    Tuesday, July 4, 2017 8:57 PM
  • Hi LokanathNayak,

    Since this forum is discussing and asking questions about the Visual Basic programming language, IDE, libraries, samples, and tools .And your issue is more related to VBS This link about VBS, please refer that:

    https://social.technet.microsoft.com/Forums/scriptcenter/en-us/home?forum=ITCG


    Thank you for participating in the forum activities.

    Best Regards,

    Cherry



    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Wednesday, July 5, 2017 2:45 AM
  • Below is an example. You may need to change the constants to their actual values if running from VBScript:

    https://stackoverflow.com/questions/10352211/vba-ado-connection-and-query-parameters


    Paul ~~~~ Microsoft MVP (Visual Basic)

    Wednesday, July 5, 2017 3:28 AM
  • Hi LokanathNayak,

    Since this forum is discussing and asking questions about the Visual Basic programming language, IDE, libraries, samples, and tools .And your issue is more related to VBS This link about VBS, please refer that:

    https://social.technet.microsoft.com/Forums/scriptcenter/en-us/home?forum=ITCG


    Thank you for participating in the forum activities.

    Best Regards,

    Cherry



    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Cherry,

    Is that an offend to the community or just because you are ordered to give replies. Meaningful or not meaningful. Please take once the time to read first all already given replies. 


    Success
    Cor


    Wednesday, July 5, 2017 9:37 AM