问题
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;
}
}
}
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;
}
}
}
}
}
I get Error 12 'mynamespace.ADataSet.Fi_securityDataTable.Fi_securityRow.Exp_dt': no suitable method found to override ...
where did I go wrong?
回答1:
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();
}
}
}
来源:https://stackoverflow.com/questions/25860241/trouble-with-changing-default-behavior-for-nullable-column-get-in-dataset