I want to refactor some code like this:
dSQL = "INSERT INTO inventory ( id, pksize, Description, supplier_id, UnitCost, UnitList," +
" Qty, UPC, dept, subdept, upc_pack_size, supplier_item, bqu_id)" +
" VALUES" + "('" + id +"'" + ", " +
pksize + ",'" + desc +"'" +
",'" + supplierID +"'" + ", " + cost + ", "
+ list + ", " + qty +
",'" + UPC +"'" + ", " + dept + ", " +
subdept + ", " + UPCpkSize +
",'" + supplierItem +"','" + redemption + "')";
...to this:
dSQL = string.Format(
"INSERT INTO inventory ( id, pksize, Description, supplier_id, UnitCost, UnitList," +
" Qty, UPC, dept, subdept, upc_pack_size, supplier_item, bqu_id)" +
" VALUES {0}, {1}, {2}, {3}, {4}, {5}, {6}, {7}, {8}, {9}, {10}, {11}, {12}",
id, pksize, desc, supplierID, cost, list, qty, UPC, dept, subdept, UPCpkSize, supplierItem, redemption);
Will this methodology suffice, or must I enclose the format values in single quotes?
UPDATE
I just noticed this comment I added "way back when" regarding this code:
// This works as a string.Format() assignment without param "?"s or single quotes because dSQL is not executed, it is simply passed to DBCommand for conditional display (if there is an exception)