开发者

Can I use SQLParameter when having a variable quantity of fields to update?

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)
    开发者_Python百科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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜