DisplayFormatAttribute.ConvertEmptyStringToNull 属性
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
获取或设置一个值,该值指示在数据源中更新数据字段时是否将空字符串值 ("") 自动转换为 null
。
public:
property bool ConvertEmptyStringToNull { bool get(); void set(bool value); };
C#
public bool ConvertEmptyStringToNull { get; set; }
member this.ConvertEmptyStringToNull : bool with get, set
Public Property ConvertEmptyStringToNull As Boolean
如果将空字符串值自动转换为 true
,则为 null
;否则为 false
。 默认值为 true
。
以下示例演示如何使用 ConvertEmptyStringToNull 启用空字符串值到 null
的转换。
C#
// Display the text [Null] when the data field is empty.
// Also, convert empty string to null for storing.
[DisplayFormat(ConvertEmptyStringToNull = true, NullDisplayText = "[Null]")]
public object Size;
' Display the text [Null] when the data field is empty.
' Also, convert empty string to null for storing.
<DisplayFormat(ConvertEmptyStringToNull:=True, NullDisplayText:="[Null]")> _
Public Size As Object
用户可能会为字段值输入空字符串。
ConvertEmptyStringToNull使用 属性可以指定在数据库中更新数据字段时是否自动将空字符串值转换为 null
。
备注
默认情况下, DynamicField 对象将值显示为 null
空字符串。 若要显示其他值,请 NullDisplayText 设置 属性。
产品 | 版本 |
---|---|
.NET | Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9 |
.NET Framework | 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |
UWP | 10.0 |