简体   繁体   中英

Can i use a parameter multiple times in the same query?

i was wondering, can a parameter be used more then once in the same query, like this :

MySqlParameter oPar0 = new MySqlParameter("e164", MySqlDbType.String);
oPar0.Value = user.E164;
string sSQL0 = "Delete from callmone.call where (caller=?e164 or called=?e164);";
clsDatabase.ExecuteSQL(sSQL0, oPar0);

Is this possible or should i write 2 parameters?

If the database driver handles named parameters, then you can reuse the parameter.

If the database driver doesn't handle named parameters, the parameter names are ignored and you have to add one parameter values for each use, in the exact order that they are used.

From the code that you presented it looks like the driver supports named parameters. If the code runs without an error, it works. If the driver would not support names parameters, the code would cause an error as there is only one parameter value.

我不知道为什么你不能这样做。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM