如何将属性设置为 true,这将允许我插入空值

本文关键字:允许我 插入 空值 属性 设置 true | 更新日期: 2023-09-27 18:34:03

我在"AddEffectiveQuarterTest"方法的单元测试中遇到了错误。如何将属性设置为 true 以允许我插入空值?

AvailabilityBLTest.cs file : "AddEffectiveQuarterTest" 方法

    public void AddEffectiveQuarterTest()
    {
        AvailabilityBL target = new AvailabilityBL();
        AvailabilityDS ds = new AvailabilityDS();
        TestBusinessLogic.BusinessLogic_AvailabilityBLAccessor accessor = new TestBusinessLogic.BusinessLogic_AvailabilityBLAccessor(target);
        // SETUP STANDARD TEST DATA
        this.SetupTestData(ds, null);
        int newModelID = -1;    
        .........
    }

可用性DS.设计器.cs文件

public string QuarterDisplay {
    get {
            try {
                return ((string)(this[this.tableTime.QuarterDisplayColumn]));
            }
            catch (global::System.InvalidCastException e) {
                throw new global::System.Data.StrongTypingException("The value for column ''QuarterDisplay'' in table ''Time'' is DBNull.", e);
        }
    }
    set {
            this[this.tableTime.QuarterDisplayColumn] = value;
    }
}

如何使用以下代码进行编辑以将属性设置为 true 以允许我插入 null 值?

public bool AllowDBNull { get; set; }

如何检查数据库空?我收到以下代码的错误。

 public bool IsColumnNameNull() {
                    return this.IsNull(this.tableColumn.ColumnNameColumn);
                }
 public string SetColumnKeyNull() {
            {
                get
                {
                    try
                    {
                        return ((string)(this[this.tableColumn.ColumnKeyColumn]));
                    }
                    catch (global::System.InvalidCastException e)
                    {
                        throw new global::System.Data.StrongTypingException("The value for column ''SetColumnKeyNull'' in table ''Column'' is DBNull.", e);
                    }
                }
                set
                {
                    this[this.tableColumn.ColumnKeyColumn] = value;
                }
            }

如何将属性设置为 true,这将允许我插入空值

您似乎正在使用强类型的数据集。

在这种情况下,生成的代码将包含将字段设置为 null 的方法。

例如,如果您的字段QuarterDisplay允许 DBNull,则 AvailabilityDS.Designer.cs 中生成的代码将包含方法SetQuarterDisplayNull() 。 它还将包括一个可用于检查 DBNull 值的方法IsQuarterDisplayNull()