共用方式為


SPField.Update Method

Updates the database with changes that are made to the field.

Namespace:  Microsoft.SharePoint
Assembly:  Microsoft.SharePoint (in Microsoft.SharePoint.dll)
Available in Sandboxed Solutions: Yes
Available in SharePoint Online

Syntax

'Declaration
<ClientCallableExceptionConstraintAttribute(FixedId := "FieldCalculatedFormula3", ErrorCode := ,  _
    Condition := "The formula for a FieldCalculated contains a circular reference",  _
    ErrorType := GetType(SPException))> _
<ClientCallableExceptionConstraintAttribute(FixedId := "FieldCalculatedFormula7", ErrorCode := ,  _
    Condition := "The formula for a FieldCalculated refers functions or semi-calculated formula",  _
    ErrorType := GetType(SPException))> _
<ClientCallableExceptionConstraintAttribute(FixedId := "FieldCalculatedFormula4", ErrorCode := ,  _
    Condition := "The formula for a FieldCalculated refers to a field whose FieldTypeKind is not allowed in formula",  _
    ErrorType := GetType(SPException))> _
<ClientCallableExceptionConstraintAttribute(FixedId := "1", ErrorCode := , Condition := "Trying to set UCC property to true for a field which is not indexed",  _
    ErrorType := GetType(SPException))> _
<ClientCallableExceptionConstraintAttribute(FixedId := "2", ErrorCode := , Condition := "Tying to un-index a field which does not allow duplicate values.",  _
    ErrorType := GetType(SPException))> _
<ClientCallableExceptionConstraintAttribute(FixedId := "3", ErrorCode := , Condition := "Trying to change the type of a field which does not allow duplicate values.",  _
    ErrorType := GetType(SPException))> _
<ClientCallableExceptionConstraintAttribute(FixedId := "4", ErrorCode := , Condition := "Trying to change the type of a field to bool where allowing duplicate values in the field is not supported.",  _
    ErrorType := GetType(SPException))> _
<ClientCallableExceptionConstraintAttribute(FixedId := "5", ErrorCode := , Condition := "Trying to index and set UCC property to true to a field and the field has duplicate values in the existing list items.",  _
    ErrorType := GetType(SPException))> _
<ClientCallableExceptionConstraintAttribute(FixedId := "6", ErrorCode := , Condition := "Trying to change the type of a field which is also changing to be indexed or which is already indexed.",  _
    ErrorType := GetType(SPException))> _
<ClientCallableExceptionConstraintAttribute(FixedId := "7", ErrorCode := , Condition := "Trying to set UCC to true to a lookup field which is also changing to be indexed or which is already indexed.",  _
    ErrorType := GetType(SPException))> _
<ClientCallableExceptionConstraintAttribute(FixedId := "FieldCalculatedFormula2", ErrorCode := ,  _
    Condition := "The formula for a FieldCalculated has a syntax error",  _
    ErrorType := GetType(SPException))> _
<ClientCallableExceptionConstraintAttribute(FixedId := "Update2", ErrorCode := , Condition := "Field does not exist",  _
    ErrorType := GetType(SPException))> _
<ClientCallableExceptionConstraintAttribute(FixedId := "Update5", ErrorCode := , Condition := "Total Number of fields in the list exceeds the limit",  _
    ErrorType := GetType(SPException))> _
<ClientCallableAttribute> _
<ClientCallableExceptionConstraintAttribute(FixedId := "FieldType1", ErrorCode := , Condition := "If the field is derived from a built-in field type or the field is referred by another Calculated Field and is not changing to either FieldType.Text, FieldType.Calculated, FieldType.Number, FieldType.Integer, FieldType.Currency, FieldType.DateTime, FieldType.Coice, or FieldType.Boolean or the field type change is not allowed",  _
    ErrorType := GetType(SPException))> _
<ClientCallableExceptionConstraintAttribute(FixedId := "accessdenied", Condition := "User does not have permissions to update this list.",  _
    ErrorType := GetType(UnauthorizedAccessException))> _
<ClientCallableExceptionConstraintAttribute(FixedId := "FieldCalculatedFormula5", ErrorCode := ,  _
    Condition := "The formula for a FieldCalculated refers to a field that does not exist",  _
    ErrorType := GetType(SPException))> _
<ClientCallableExceptionConstraintAttribute(FixedId := "Update3", ErrorCode := , Condition := "Trying to change UCC from false to true or trying to index the field and the current user does not have permission to do big list operation",  _
    ErrorType := GetType(SPQueryThrottledException))> _
Public Overridable Sub Update
'Usage
Dim instance As SPField

instance.Update()
[ClientCallableExceptionConstraintAttribute(FixedId = "FieldCalculatedFormula3", ErrorCode = , 
    Condition = "The formula for a FieldCalculated contains a circular reference", 
    ErrorType = typeof(SPException))]
[ClientCallableExceptionConstraintAttribute(FixedId = "FieldCalculatedFormula7", ErrorCode = , 
    Condition = "The formula for a FieldCalculated refers functions or semi-calculated formula", 
    ErrorType = typeof(SPException))]
[ClientCallableExceptionConstraintAttribute(FixedId = "FieldCalculatedFormula4", ErrorCode = , 
    Condition = "The formula for a FieldCalculated refers to a field whose FieldTypeKind is not allowed in formula", 
    ErrorType = typeof(SPException))]
[ClientCallableExceptionConstraintAttribute(FixedId = "1", ErrorCode = , Condition = "Trying to set UCC property to true for a field which is not indexed", 
    ErrorType = typeof(SPException))]
[ClientCallableExceptionConstraintAttribute(FixedId = "2", ErrorCode = , Condition = "Tying to un-index a field which does not allow duplicate values.", 
    ErrorType = typeof(SPException))]
[ClientCallableExceptionConstraintAttribute(FixedId = "3", ErrorCode = , Condition = "Trying to change the type of a field which does not allow duplicate values.", 
    ErrorType = typeof(SPException))]
[ClientCallableExceptionConstraintAttribute(FixedId = "4", ErrorCode = , Condition = "Trying to change the type of a field to bool where allowing duplicate values in the field is not supported.", 
    ErrorType = typeof(SPException))]
[ClientCallableExceptionConstraintAttribute(FixedId = "5", ErrorCode = , Condition = "Trying to index and set UCC property to true to a field and the field has duplicate values in the existing list items.", 
    ErrorType = typeof(SPException))]
[ClientCallableExceptionConstraintAttribute(FixedId = "6", ErrorCode = , Condition = "Trying to change the type of a field which is also changing to be indexed or which is already indexed.", 
    ErrorType = typeof(SPException))]
[ClientCallableExceptionConstraintAttribute(FixedId = "7", ErrorCode = , Condition = "Trying to set UCC to true to a lookup field which is also changing to be indexed or which is already indexed.", 
    ErrorType = typeof(SPException))]
[ClientCallableExceptionConstraintAttribute(FixedId = "FieldCalculatedFormula2", ErrorCode = , 
    Condition = "The formula for a FieldCalculated has a syntax error", 
    ErrorType = typeof(SPException))]
[ClientCallableExceptionConstraintAttribute(FixedId = "Update2", ErrorCode = , Condition = "Field does not exist", 
    ErrorType = typeof(SPException))]
[ClientCallableExceptionConstraintAttribute(FixedId = "Update5", ErrorCode = , Condition = "Total Number of fields in the list exceeds the limit", 
    ErrorType = typeof(SPException))]
[ClientCallableAttribute]
[ClientCallableExceptionConstraintAttribute(FixedId = "FieldType1", ErrorCode = , Condition = "If the field is derived from a built-in field type or the field is referred by another Calculated Field and is not changing to either FieldType.Text, FieldType.Calculated, FieldType.Number, FieldType.Integer, FieldType.Currency, FieldType.DateTime, FieldType.Coice, or FieldType.Boolean or the field type change is not allowed", 
    ErrorType = typeof(SPException))]
[ClientCallableExceptionConstraintAttribute(FixedId = "accessdenied", Condition = "User does not have permissions to update this list.", 
    ErrorType = typeof(UnauthorizedAccessException))]
[ClientCallableExceptionConstraintAttribute(FixedId = "FieldCalculatedFormula5", ErrorCode = , 
    Condition = "The formula for a FieldCalculated refers to a field that does not exist", 
    ErrorType = typeof(SPException))]
[ClientCallableExceptionConstraintAttribute(FixedId = "Update3", ErrorCode = , Condition = "Trying to change UCC from false to true or trying to index the field and the current user does not have permission to do big list operation", 
    ErrorType = typeof(SPQueryThrottledException))]
public virtual void Update()

Exceptions

Exception Condition
SPException

An error was encountered during the operation.

Examples

The following code example updates the display name, default value, and description for the specified field.

Dim siteCollection As SPSite = SPContext.Current.Site
Dim list As SPList = 
    siteCollection.AllWebs("Site_Name").Lists("List_Name")
Dim field As SPField = list.Fields("Field_Name")

field.DefaultValue = "Default_Value"
field.Description = "Description"
field.Title = "New_Field_Title"

field.Update() 
SPSite oSiteCollection = SPContext.Current.Site;
SPList oList = 
    oSiteCollection.AllWebs["Site_Name"].Lists["List_Name"];
SPField oField = oList.Fields["Field_Name"];

oField.DefaultValue = "Default_Value";
oField.Description = "Description";
oField.Title = "New_Field_Title";

oField.Update();

See Also

Reference

SPField Class

SPField Members

Update Overload

Microsoft.SharePoint Namespace