r/csharp•
[deleted]

Generating safe insert/update SQL commands from existing data

I have a database table that I need to extract data from, properly format, then generate a safe insert/update SQL command containing the data from the table.

I have attempted to tackle the problem using string concatenation however this is a laughable solution at best. Is there some way this can be done in a more correct/sane way?

I know the problem could be solved using a select statement with like this: SELECT 'IF NOT EXISTS (SELECT column1, column2, column3 FROM sometable WHERE primary_key='+PRIMARY_KEY_COLMN+'....' FROM mytable; But there has to be a better way, hasn't there?

Posted Jun 24, 2012, 1:04 AM UTC

35
Loading comments…