How to set value in a field by UI?

73 views Asked by At

I use three fields in Sqlserver Datavbase tables, for prevent delete records permanently by user:

IsDelete (bit)
DeletedDate (DateTime)
DeletedUserID (bigint)

I wish to set third field (DeletedUserID) by UI by some thing like this:

        this.ExamdbDataSet.AcceptChanges();
        DataRowView row = (DataRowView)this.BindingSource.Current;
        row.BeginEdit();
        row["DeletedUserID"] = User.User.Current.ID;
        row.EndEdit();
        this.ExamdbDataSet.AcceptChanges();
        row.Delete();

and other two fields ,'IsDeleted' field and 'DeletedDate' are set automatically in table's 'After Delete Trigger'.

then commit changes to database with desire command successfuly with this code:

        this.TableAdapterManager.UpdateAll(this.ExamdbDataSet);

but problem is , the 'DeletedUserID' is null in database.

and Question is : How to set 'DeletedUserID' field value by true way in UI?

1

There are 1 answers

3
Delphi.Boy On

I don't think it is a good way to do that. You have sliced a simple logic to separate parts, each being done in a different part of the application (UI, Trigger, ...). You set value of some field, and then DELETE the whole record! Don't expect anything else that the current situation. You would better set all fields in UI (i.e. no trigger in this case), and change the query that loads data. For example,

Select * from table1 where IsDeleted=0

You didn't tell us anything about whether your use ASP.Net or WinForms. Give us more info.