/// <summary> /// SQL的条件符号枚举。dengyu表示“等于”,dayu表示“大于”,dayuOrdengyu表示“大于并且等于”,xiaoyuOrdengyu表示“小于并且等于”,inType表示“in”,like表示"like" /// </summary> enum OperaTeype { dengyu,dayu, xiaoyu, dayuOrdengyu, xiaoyuOrdengyu, inType, like }; /// <summary> /// 根据转入的条件拼凑SQL条件语句 /// </summary> /// <param name="type">条件符号。如大于,等于等</param> /// <param name="value">字段的值</param> /// <param name="filed">字段的名称</param> /// <param name="yihao">是否加引号</param> /// <returns></returns> private string GetReturnString(OperaTeype type, object value,string filed,bool yihao) { string strStart=" and "; if (value == null) { return string.Empty; } if (value.ToString().Length <= 0) { return string.Empty; } if (yihao == true) { value = "'" + value + "'"; } if ((type == OperaTeype.dayu)) { return string.Format("{0}{1}>{2}", strStart, filed, value); } if ((type == OperaTeype.dengyu)) { return string.Format("{0}{1}={2}", strStart, filed, value); } if ((type == OperaTeype.xiaoyu)) { return string.Format("{0}{1}<{2}", strStart, filed, value); } if ((type == OperaTeype.dayuOrdengyu)) { return string.Format("{0}{1}>={2}", strStart, filed, value); } if ((type == OperaTeype.xiaoyuOrdengyu)) { return string.Format("{0}{1}<={2}", strStart, filed, value); } if ((type == OperaTeype.inType)) { return string.Format("{0}{1} in ({2})", strStart, filed, value); } if ((type == OperaTeype.like)) { return string.Format("{0}{1} like '%{2}%'", strStart, filed, value); } return string.Empty; }