【问题标题】:Object cannot be cast from DBNull to other types : Data Binding对象不能从 DBNull 转换为其他类型:数据绑定
【发布时间】:2020-09-15 21:21:09
【问题描述】:

将控件动态绑定到数据源时出现此错误。 (大多数答案在使用参数时都会做出响应:就像这个Object cannot be cast from DBNull to other types)。 绑定控件时可以扩展吗?

【问题讨论】:

    标签: data-binding datasource


    【解决方案1】:

    刚刚尝试了“DataBindings.Add”方法的扩展:因此这段代码:

                this.chkDispensed.DataBindings.Add("Checked", DT_items, "dispensedItem_bol");
                this.chkDirectionsAuto.DataBindings.Add("Checked", DT_items, "directionsAuto_bol");
    

    .. 更改

                bool myDefBool = false;
                this.chkDispensed.DataBindings.Add("Checked", DT_items, "dispensedItem_bol", true, DataSourceUpdateMode.OnPropertyChanged, myDefBool);
                this.chkDirectionsAuto.DataBindings.Add("Checked", DT_items, "directionsAuto_bol", true, DataSourceUpdateMode.OnPropertyChanged, myDefBool);
    

    这会处理数据库中的 NULL 值。我想它必须为所有控件完成,任何类型。谢谢。

    【讨论】:

      猜你喜欢
      • 2011-08-31
      • 1970-01-01
      • 1970-01-01
      • 2013-11-27
      • 2018-12-21
      相关资源
      最近更新 更多