c# - Append value in sql server -


i have written c# foreach function updates column in sql server. have 2 values append in same column. in foreach function, updates values in column, overwrites value on next "loop".

example:

string value = "blue"; sqlcommand cmdupdate = new sqlcommand("update colors set color=@value color_id = 11", connection); 

and next foreach loop string value "red"

string value = "red"; sqlcommand cmdupdate = new sqlcommand("update colors set color=@value color_id = 11", connection); 

how should write code both values in sql column. "blue, red"

thanks in advance

concat string first , update.

string value = "blue"; value += ", red"; sqlcommand cmdupdate = new sqlcommand("update colors set color=@value color_id = 11", connection); 

and of course in foreach clause.

edit: if want use sql:

sqlcommand cmdupdate = new sqlcommand("update colors set color='' color_id = 11", connection); foreach(...) {     value = "[your value]";     sqlcommand cmdupdate = new sqlcommand("update colors set color= color + ', ' + @value color_id = 11", connection); } 

Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -