4

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?

Stecya
  • 22,896
  • 10
  • 72
  • 102
Terry
  • 5,132
  • 4
  • 33
  • 66

2 Answers2

5

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.

Guffa
  • 687,336
  • 108
  • 737
  • 1,005
  • Indeed, afaik mysql itself doesn't support named parameters natively. However, implementations & drivers are often clever enough to mimic it for / map it to nuumbered parameters. – Wrikken Jun 08 '10 at 14:04
1

I don't know of any reason why you can't do that.

ChrisF
  • 134,786
  • 31
  • 255
  • 325
  • I am stuck in the dinosaur era using DB2. The driver doesn't recognize named parameters. So I just have to add the same value multiple times if needed more than once. Maybe one day I will join Doc and Marty in the future. – eaglei22 Nov 08 '17 at 18:20