tags:

views:

26

answers:

1

Hello ADO.NET experts,

I have a table with eighty fields, none to seventy of them can change depending of an update process I have. For example:

if (process.result == 1)
    cmd.CommandText = "UPDATE T SET f1=1, f6='S'" ;
else if (Process.result == 2)
    cmd.CommandText = string.Format("UPDATE T SET f1=2, f12={0},f70='{1}'", getData(), st);
else if ..... etc.

I can optimize the building process of the UPDATE statement, however I would like to use SQLParameter; is that possible and convenient given the variablity of data to update?

Thanks.

A: 

For each if statement you currently are using inline string formats, you could just as well just add the sql params instead.

The formatting of the UPDATE string could be replaced with the selected sql params you require to be updated insted.

astander
astander, I understand that the key with SQL parameters is to create a command text only once, for example in the way "UPDATE ... SET f1=?, f2=?,....,f70=?", but my problem is that not all the fields will need to be updated; may be for one record no update is needed or, for another, only the last ten fields will need to be updated, and so on.
Tristan

related questions