Results 1 to 7 of 7

Thread: parameters Value Order

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Feb 2014
    Posts
    169

    Red face parameters Value Order

    friends;
    Code:
    UPDATE Table1 SET Table1.Pname = "@Pr1"
    WHERE (((Table1.ID)="@pr2") AND ((Table1.City)="@pr3") AND ((Table1.telephone)="@pr4"));
    
    command.parameters.addwithvalue("@Pr2",10);
    command.parameters.addwithvalue("@Pr4","416546546565");
    command.parameters.addwithvalue("@Pr3",Paris);
    command.parameters.addwithvalue("@Pr1","ssdsd");
    i ask about if parameters is the same name

    in sql code and when enter parameters value

    is there any problem in the code above

    should i arrange the parameters

    or the above code is right


    thank you for your help and answer?

  2. #2
    PowerPoster PlausiblyDamp's Avatar
    Join Date
    Dec 2016
    Location
    Pontypool, Wales
    Posts
    2,458

    Re: parameters Value Order

    If you are using a SqlCommnd that should work as it supports named parameters, other providers may not work.

    Easiest way is probably to run the code and see if it works or not.

  3. #3
    Smooth Moperator techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,532

    Re: parameters Value Order

    For SQL Server and Oracle, they both support named parameters, so they can be added in any order, as long as the names match. For Access, it uses Ordinal Positioning, so the order you Parameters.Add DOES matter, though the names do not. I'm not sure about MySQL..

    Generally speaking, I personally add the parameters in the same order they appear in the query, but that's just a personal organizational thing.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Feb 2014
    Posts
    169

    Re: parameters Value Order

    Quote Originally Posted by PlausiblyDamp View Post
    If you are using a SqlCommnd that should work as it supports named parameters, other providers may not work.

    Easiest way is probably to run the code and see if it works or not.
    i'm using oledbcommand

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Feb 2014
    Posts
    169

    Re: parameters Value Order

    Quote Originally Posted by techgnome View Post
    For Access, it uses Ordinal Positioning, so the order you Parameters.Add DOES matter, though

    -tg
    techgnome
    i'm using access

    Code:
    UPDATE Table1 SET Table1.Pname = "@Pr1"
    WHERE (((Table1.ID)="@pr2") AND ((Table1.City)="@pr3") AND ((Table1.telephone)="@pr4"));
    command.parameters.addwithvalue("@Pr1","ssdsd");
    command.parameters.addwithvalue("@Pr2",10);
    command.parameters.addwithvalue("@Pr3",Paris);
    command.parameters.addwithvalue("@Pr4","416546546565");
    is the arrange like the above code or Parameters run by using sql code arrange because i know the WHERE is run first part in sql code

  6. #6
    Smooth Moperator techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,532

    Re: parameters Value Order

    Since you are using Access, then you must add them IN THE SAME ORDER THEY APPEAR ... so since @Pr1 is first in your query it MUST be added first.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  7. #7
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,299

    Re: parameters Value Order

    You've already been given all the information you need.
    Quote Originally Posted by PlausiblyDamp View Post
    Easiest way is probably to run the code and see if it works or not.
    Did you do that? Did it work or not? If it did then the code is correct and if it didn't then it's not. You never need to ask whether code will work or not when you can simply run it for yourself.
    Quote Originally Posted by techgnome View Post
    For Access, it uses Ordinal Positioning, so the order you Parameters.Add DOES matter, though the names do not.

    ...

    Generally speaking, I personally add the parameters in the same order they appear in the query...
    Nothing ambiguous about that.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width