這是一個簡單最安全/優化的代碼「不記錄存在」的問題:最乾淨的方式來確定是否存在一行?
. . . // "oc" is an OracleConnection component
const string sql = "SELECT COUNT(*) FROM CONGRESS WHERE IQ > WEIGHT"; //Most politicians have more pounds than sense
try {
using (OracleCommand ocmd = new OracleCommand(sql, oc)) {
return Convert.ToInt32(ocmd.ExecuteScalar()) > 0;
}
. . . // the rest elided to spare the vertical scroll-bar bearings
?
對我來說看起來不錯 –