public virtual T ExecuteScalar <T>(string sql, params IDacParameter[] parameters) { T retVal; using (var cn = CreateConnection()) { cn.Open(); using (var cmd = Driver.CreateCommand(cn, sql, null, parameters)) { var value = cmd.ExecuteScalar(); if (value == null || value == DBNull.Value) { retVal = default(T); } else { retVal = (T)Convert.ChangeType(value, typeof(T)); } } cn.Close(); } return(retVal); }
protected virtual IDbCommand CreateCommand(IDbConnection connection, string sql, params IDacParameter[] parameters) { return(Driver.CreateCommand(connection, sql, null, parameters)); }