为可为空的列获取数据集更改默认行为的麻烦 [英] trouble with changing default behavior for nullable column get in dataset

查看:105
本文介绍了为可为空的列获取数据集更改默认行为的麻烦的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

.designer.cs中dataRow的默认列获取就像

default column get for a dataRow in .designer.cs is like

    public partial class Fi_securityRow : global::System.Data.DataRow
{
    [global::system.diagnostics.debuggernonusercodeattribute()]
    [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Data.Design.TypedDataSetGenerator", "4.0.0.0")]
    public override System.DateTime Exp_dt
    {
        get
        {
            try
            {
                return ((global::System.DateTime)(this[this.tableFi_security.Exp_dtColumn]));
            }
            catch (global::System.InvalidCastException e)
            {
                throw new global::System.Data.StrongTypingException("The value for column \'Exp_dt\' in table \'Fi_security\' is DBNull.", e);
            }
        }
        set
        {
            this[this.tableFi_security.Exp_dtColumn] = value;
        }
    }
}

当我尝试通过在数据集类中添加.cs文件来更改该行为时

when I tried to change that behavior by adding in .cs file in the dataset class

public partial class IeFinExecPDataSet
{
    public partial class Fi_securityDataTable
    {

        /// <summary> line 19938
        ///Represents strongly named DataRow class.
        ///</summary>
        public partial class Fi_securityRow : global::System.Data.DataRow
        {
            [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
            [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Data.Design.TypedDataSetGenerator", "4.0.0.0")]
            public override System.DateTime? Exp_dt
            {
                get
                {
                    try
                    {
                    if (this[this.tableFi_security.Exp_dtColumn]==System.DBNull.Value) return null;
                        return ((global::System.DateTime)(this[this.tableFi_security.Exp_dtColumn]));
                    }
                    catch (global::System.InvalidCastException e)
                    {
                        throw new global::System.Data.StrongTypingException("The value for column \'Exp_dt\' in table \'Fi_security\' is DBNull.", e);
                    }
                }
                set
                {
                    this[this.tableFi_security.Exp_dtColumn] = value;
                }
            }
        }
    }
}

我得到错误12'mynamespace.ADataSet.Fi_securityDataTable.Fi_securityRow.Exp_dt':找不到合适的方法来覆盖...

I get Error 12 'mynamespace.ADataSet.Fi_securityDataTable.Fi_securityRow.Exp_dt': no suitable method found to override ...

我哪里出错了?

推荐答案

您将要解决所有这些错误.不要编辑生成的代码.如果要使用类型为DateTime?的属性,请添加具有该类型的额外属性的额外分部类.您可以这样实现该属性:

You're going about this all wrong. DO NOT edit the generated code. If you want a property that is type DateTime? then add an extra partial class with an extra property of that type. You might implement that property like this:

public DateTime? NullableExp_dt
{
    get
    {
        if (this.IsExp_dtNull())
        {
            return (DateTime?) null;
        }
        else
        {
            return (DateTime?) this.Exp_dt;
        }
    }
    set
    {
        if (value.HasValue())
        {
            this.Exp_dt = value.Value;
        }
        else
        {
            this.SetExp_dtNull();
        }
    }
}

这篇关于为可为空的列获取数据集更改默认行为的麻烦的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆