/// <summary> /// 执行存储过程带参数 /// </summary> /// <param name="db">链接数据库EF DbContext对象</param> /// <param name="cmdText">SQL语句、存储过程名称</param> /// <param name="sqlParams">参数 SqlParameter集合</param> /// <returns></returns> public static string ExecuteScalarPro(this CTMSContext db, string cmdText, DbParameter[] sqlParams) { try { return(db.ExecuteScalar(CommandType.StoredProcedure, cmdText, sqlParams)); } catch (Exception ex) { throw new Exception(ex.Message); } }
/// <summary> /// 执行SQL语句不带参数 /// </summary> /// <param name="db">链接数据库EF DbContext对象</param> /// <param name="cmdText">SQL语句、存储过程名称</param> /// <returns></returns> public static string ExecuteScalar(this CTMSContext db, string cmdText) { try { return(db.ExecuteScalar(CommandType.Text, cmdText, null)); } catch (Exception ex) { throw new Exception(ex.Message); } }
public string ExecuteCommand(string cmdText) { return(dbContext.ExecuteScalar(cmdText)); }