Can I use a parameter multiple times in a single query?

I am wondering if a parameter can be used more than once in a single request, for example:

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?

+4
source share
2 answers

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

If the database driver does not process named parameters, the parameter names are ignored, and you need to add the same parameter values ​​for each use in the order in which they are used.

From the code you presented, it looks like the driver supports named parameters. If the code works without errors, it works. If the driver does not support name parameters, the code will fail because there is only one parameter value.

+4
source

I do not know why you cannot do this.

+2
source

Source: https://habr.com/ru/post/1312206/


All Articles