ling to sql 如何记录对数据库的更改 (2)
我的环境:winxp, c#2008, sql 2005。数据访问技术:linq to sql
目前策略思路:系统中有若干个表,包括一个用户表,我在登录的时候记录用户的登录id,然后在每个表里面设置一个用户id的列和一个自动时间戳timestamp,然后在insert和update的时候写入用户id,自动时间戳则把操作的具体时间自动记录,
表的定义如下:
create table class( class nvarchar(10) not null, --班级 specialty nvarchar(40), --专业 counsellor nvarchar(12), --班主任 enroll int,--入学年份 userID int not null, --操作员 autoTS timestamp not null --自动时间戳)goalter table class add constraint pkClass primary key (class)goalter table class add constraint users$op$class foreign key (userID) references usersgo
private void classesBindingNavigatorSaveItem_Click(object sender, EventArgs e) { try { db.SubmitChanges(); //private tuitionDBDataContext db = new tuitionDBDataContext(); } catch (Exception ex) { MessageBox.Show(ex.Message); } }