将 CreatedDate 和 ModifiedDate 放入 DataRow 中的最佳位置在哪里?
我有以下代码
public class SpecialItemRow : DataRow
{
public SpecialItemRow(DataRowBuilder builder)
: base(builder)
{
CreatedDate = DateTime.Now.ToLongTimeString();
}
public string ItemName { get { return Convert.ToString(base["_ItemName"]); } set { base["_ItemName"] = value; _UpdateModifiedDate(); } }
public string Price { get { return Convert.ToString(base["_Price"]); } set { base["_Price"] = value; _UpdateModifiedDate(); } }
public string CreatedDate { get { return Convert.ToString(base["_CreatedDate"]); } set { base["_CreatedDate"] = value; _UpdateModifiedDate(); } }
public string ModifiedDate { get { return Convert.ToString(base["_ModifiedDate"]); } set { base["_ModifiedDate"] = value; } }
private void _UpdateModifiedDate()
{
ModifiedDate = DateTime.Now.ToLongTimeString();
}
}
尝试自动设置修改和创建日期。但事实证明这些不是放置的正确位置。是否有其他可重写的方法来设置这些值?谢谢。
I have the following code
public class SpecialItemRow : DataRow
{
public SpecialItemRow(DataRowBuilder builder)
: base(builder)
{
CreatedDate = DateTime.Now.ToLongTimeString();
}
public string ItemName { get { return Convert.ToString(base["_ItemName"]); } set { base["_ItemName"] = value; _UpdateModifiedDate(); } }
public string Price { get { return Convert.ToString(base["_Price"]); } set { base["_Price"] = value; _UpdateModifiedDate(); } }
public string CreatedDate { get { return Convert.ToString(base["_CreatedDate"]); } set { base["_CreatedDate"] = value; _UpdateModifiedDate(); } }
public string ModifiedDate { get { return Convert.ToString(base["_ModifiedDate"]); } set { base["_ModifiedDate"] = value; } }
private void _UpdateModifiedDate()
{
ModifiedDate = DateTime.Now.ToLongTimeString();
}
}
which tries to set the modified and created dates automatically. but it turns out that those are not the right places to put. is there any other overridable methods to set these values? Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用 OnRowChanged 在
DataTable
中执行此操作 (或 OnRowChanging)。例如,(免责声明:未经测试的代码 - 仅供提供一个想法)
Do this in
DataTable
using OnRowChanged (or OnRowChanging). For example,(Disclaimer: Untested code - provided to just give an idea)