日期:2014-05-17 浏览次数:20455 次
#region 增加参数 public static SqlCommand AddParameterCollection(SqlCommand cmd, SqlParameterCollection SqlParameterCollection) { foreach (SqlParameter SqlParameter in SqlParameterCollection) { cmd.Parameters.Add(SqlParameter); } return cmd; } public static void AddOutParameter(SqlCommand cmd, string parameterName, DbType dbType, int size) { SqlParameter SqlParameter = cmd.CreateParameter(); SqlParameter.DbType = dbType; SqlParameter.ParameterName = parameterName; SqlParameter.Size = size; SqlParameter.Direction = ParameterDirection.Output; cmd.Parameters.Add(SqlParameter); } public static void AddInParameter(SqlCommand cmd, string parameterName, DbType dbType, object value) { SqlParameter SqlParameter = cmd.CreateParameter(); SqlParameter.DbType = dbType; SqlParameter.ParameterName = parameterName; SqlParameter.Value = value; SqlParameter.Direction = ParameterDirection.Input; cmd.Parameters.Add(SqlParameter); } public static void AddReturnParameter(SqlCommand cmd, string parameterName, DbType dbType) { SqlParameter SqlParameter = cmd.CreateParameter(); SqlParameter.DbType = dbType; SqlParameter.ParameterName = parameterName; SqlParameter.Direction = ParameterDirection.ReturnValue; cmd.Parameters.Add(SqlParameter); } public static SqlParameter GetParameter(SqlCommand cmd, string parameterName) { return cmd.Parameters[parameterName]; } #endregion