private static object GetDataFieldValue(object obj, DbConnType connType) { if (SmartCrudHelper.IsNullOrDBNull(obj)) { return(null); // DBNull.Value; //dapper下不可使用 DBNull.Value } else { if (connType == DbConnType.ODPNET) { Type t = obj.GetType(); if (t == GuidType) { return(obj?.ToString().ToUpper()); } else if (t == Bool) { return((byte)(((bool)obj) ? 1 : 0)); } else if (t == SmartCrudHelper.SByte) { return(Convert.ToByte(obj)); } } return(obj); } }
public int GetInterId(string branchCode, int billType) { string sql = $"SELECT #ISNULL#(MAX(FMAXID),0) FROM {BillTableName} where FBranchCode=#BranchCode# and FBillType=#BillType#"; RequestBase pars = new RequestBase(); pars.Add("BranchCode", branchCode); pars.Add("BillType", billType); object ret = _Conn.ExecuteScalar(sql, pars); if (SmartCrudHelper.IsNullOrDBNull(ret)) { return(0); } else { return(Convert.ToInt32(ret)); } }
/// <summary> /// 返回的字段不能为NULL,最好就是 'Y' /// </summary> /// <param name="connInfo"></param> /// <param name="sql"></param> /// <param name="param"></param> /// <returns></returns> public static bool ExistsPrimitive(this DbContext connInfo, string sql, object param = null) { object result = connInfo.ExecuteScalar(sql, param); return(!SmartCrudHelper.IsNullOrDBNull(result)); }