保存编辑/更新记录在数据库表中的时间戳 [英] save the timestamp of edited/updated record in database table

查看:41
本文介绍了保存编辑/更新记录在数据库表中的时间戳的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

朋友们,



在我的网页上我有gridview插入,删除,更新记录



我正在从gridview插入,更新,删除记录。使用C#ASp.net Sqlserver 2005.



我的要求是我想在更新记录后保存时间戳。所以我们可以知道这条记录何时被编辑/更新。



请你帮我,谢谢。

hi friends,

on my webpage i have gridview to insert,delete, update records

am inserting, updating, deleting records from gridview. using C# ASp.net Sqlserver 2005.

my requirement is i want to save the time stamp after updating the record..so we can know when this record was edited/updated.

Please can you help me, thanks in advance.

推荐答案

用于插入和更新是一个简单的方法:添加时间戳字段和触发器来更新它。而且你不需要(不应该)从代码中干扰它。但这已经不够了。

如果你真的需要删除它,你也可以实现审计日志功能。这是一个很好的解决方案: http://www.sqlservercentral.com/Forums/Topic1307316-392-1。 aspx [ ^ ]。

如果您还需要记录用户,这可能会使其更加复杂,具体取决于您的应用程序的身份验证方案。

以下是审核方法的一个很好的比较可以处理: http:// www。 slideshare.net/sqlserver.co.il/a-comparative-analysis-of-auditing-solutions-in-sql-server [ ^ ]
For insert and update there is a simple method: add a timestamp filed, and a trigger to update it. And you don''t need to (should not) interfere with it from code. But this is rarely enough.
If you really need that for deletion too, you have do implement audit log functionality. Here is a good solution: http://www.sqlservercentral.com/Forums/Topic1307316-392-1.aspx[^].
If you need to log the user also, that can make it more complicated depending on your application''s authentication scenario.
Here is a good comparison of auditing methods you can deal with: http://www.slideshare.net/sqlserver.co.il/a-comparative-analysis-of-auditing-solutions-in-sql-server[^]


您应该在表格中有一个 ModifiedDate 列,您的数据将被保存。



对于该表的一行上的任何操作(编辑/更新),使用< a href =http://msdn.microsoft更新该列.com / zh-CN // library / system.datetime.now.aspx> DateTime.Now< / a> [< a href =http://msdn.microsoft.com/en-us//library /system.datetime.now.aspx\"target =_ blanktitle =新窗口> ^< / a>] ,以便它包含 DateTime 在该特定事件中。
You should have a ModifiedDate Column in the table, where your data is getting saved.

For any operation(Edit/Update) on a row of that table, update that column with <a href="http://msdn.microsoft.com/en-us//library/system.datetime.now.aspx">DateTime.Now</a>[<a href="http://msdn.microsoft.com/en-us//library/system.datetime.now.aspx" target="_blank" title="New Window">^</a>], so that it will contain the DateTime at that particular event.


这篇关于保存编辑/更新记录在数据库表中的时间戳的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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