I have a string like this:
string query = "INSERT INTO CUSTOMER (id, name, address, address2) VALUES(@id, @name, @address, @address2)"
then I replace @address with ‘Elm Street’ using
query = query.Replace("@address", "'" + "Elm Street" + "'");
and the result become:
INSERT INTO CUSTOMER (id, name, address, address2) VALUES(@id, @name, 'Elm Street', 'Elm Street'2)
how to get the result:
INSERT INTO CUSTOMER (id, name, address, address2) VALUES(@id, @name, 'Elm Street', @address2) ?
Well, first I should mention that normally you shouldn’t be doing this at all. You should put the values in parameter objects that you use in the command.
If you really need to do that for some weird reason, you can use a regular expression to match all parameters, and replace one of them: