-
May 25th, 2017, 06:58 AM
#1
Thread Starter
Addicted Member
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?
-
May 25th, 2017, 07:15 AM
#2
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.
-
May 25th, 2017, 07:32 AM
#3
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
-
May 25th, 2017, 07:33 AM
#4
Thread Starter
Addicted Member
Re: parameters Value Order
Originally Posted by PlausiblyDamp
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
-
May 25th, 2017, 07:43 AM
#5
Thread Starter
Addicted Member
Re: parameters Value Order
Originally Posted by techgnome
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
-
May 25th, 2017, 08:06 AM
#6
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
-
May 25th, 2017, 08:07 AM
#7
Re: parameters Value Order
You've already been given all the information you need.
Originally Posted by PlausiblyDamp
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.
Originally Posted by techgnome
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|