我如何设置更新的列与Createdby相同,并且Createdon与在Sql中的Updatedon相同 [英] How Do I Set The Column Updatedby Is Same As Createdby And Createdon Is Same As Updatedon In Sql

查看:63
本文介绍了我如何设置更新的列与Createdby相同,并且Createdon与在Sql中的Updatedon相同的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hi Team,



我编写的代码如下。

Hi Team,

I written the code as follows.

public int AddFileLogRecords(IEntityBase entityBase)
       {
           int rowsAffected = 0;
           try
           {
               Logger.Write("Inside Kaizen2GDataManager.AddFileLogRecords()", LogType.Information);
               IFileLog fileLog = entityBase as IFileLog;
               CommonDataAccess.CreateStoredProcCommandWrapper(KaizenConstants.SPK2INSERTFILELOG);
               CommonDataAccess.AddInParameter(KaizenConstants.FILEPATH, DbType.String, fileLog.FilePath);
               CommonDataAccess.AddInParameter(KaizenConstants.FILENAME, DbType.String, fileLog.FileName);
               CommonDataAccess.AddInParameter(KaizenConstants.FILETYPE, DbType.Int32, fileLog.FileType);
               CommonDataAccess.AddInParameter(KaizenConstants.FILEDATE, DbType.DateTime, fileLog.FileDate);
               CommonDataAccess.AddInParameter(KaizenConstants.CIRCLEID, DbType.Int32, fileLog.CircleId);
               CommonDataAccess.AddInParameter(KaizenConstants.TOTALROWS, DbType.Int32, fileLog.TotalRows);
               CommonDataAccess.AddInParameter(KaizenConstants.SUCCESSCOUNT, DbType.Int32, fileLog.SuccessCount);
               CommonDataAccess.AddInParameter(KaizenConstants.FAILURECOUNT, DbType.Int32, fileLog.FailureCount);
               CommonDataAccess.AddInParameter(KaizenConstants.ERROR, DbType.String, fileLog.ErrorMessage);
               CommonDataAccess.AddInParameter(KaizenConstants.PROCESSED, DbType.Boolean, fileLog.Processed);
               CommonDataAccess.AddInParameter(KaizenConstants.CREATEDBY, DbType.Int32, 1);
               CommonDataAccess.AddInParameter(KaizenConstants.CREATEDON, DbType.DateTime, DateTime.Now.ObjectToDBDateTime());
               CommonDataAccess.AddInParameter(KaizenConstants.UPDATEDON, DbType.DateTime, fileLog.CreatedOn);
               CommonDataAccess.AddInParameter(KaizenConstants.UPDATEDBY, DbType.Int32, fileLog.CreatedBy);
               CommonDataAccess.AddInParameter(KaizenConstants.DELETED, DbType.Boolean, 0);
               CommonDataAccess.AddOutParameter(KaizenConstants.ID, DbType.Int32, Int32.MaxValue, false, 0, 0);
               rowsAffected = CommonDataAccess.ExceuteNonQuery();
               int id = CommonDataAccess.GetParameterValue(KaizenConstants.ID).ObjectToInt32();
               Logger.Write("Exiting Kaizen2GDataManager.AddFileLogRecords()", LogType.Information);
           }
           catch (Exception exception)
           {
               throw exception;
           }

           return rowsAffected;
       }





我想在CREATEDBY和CREATEDON中出现UPDATEDBY和UPDATEDON的相同值。

我创建了一个存储过程如下



I want same value for UPDATEDBY and UPDATEDON which is present in CREATEDBY and CREATEDON.
I have created a stored procedure as follows

ALTER PROCEDURE [dbo].[K2_INSERTFILELOG] 
@FILENAME VARCHAR(150),
@FILEPATH VARCHAR(MAX),
@FILETYPE int,
@FILEDATE datetime,
@CIRCLEID INT,
@TOTALROWS int,
@SUCCESSCOUNT int,
@FAILURECOUNT int,
@PROCESSED bit,
@ERROR varchar(MAX),
@CREATEDBY INT ,
@CREATEDON DATETIME,
@UPDATEDBY INT ,
@UPDATEDON DATETIME,
@DELETED BIT,
@ID BIGINT OUT

AS
BEGIN

INSERT INTO K2FILELOG
	   (FILEPATH, [FILENAME],FILETYPE,FILEDATE,CIRCLEID,TOTALROWS,SUCCESSCOUNT,FAILURECOUNT,PROCESSED,ERROR,CREATEDBY, CREATEDON,UPDATEDBY,UPDATEDON, DELETED)
values (@FILEPATH ,@FILENAME,@FILETYPE,@FILEDATE,@CIRCLEID,@TOTALROWS,@SUCCESSCOUNT,@FAILURECOUNT,@PROCESSED,@ERROR ,@CREATEDBY,@CREATEDON,@UPDATEDBY,@UPDATEDON,@DELETED);
SET @ID = @@IDENTITY;
END





但它对我不起作用。

i得不到同样的价值适用于CREATEDBY和CREATEDON中的UPDATEDBY和UPDATEDON。为什么会这样.. ??



提前谢谢

Harshal



But it does not work for me.
i am not getting the same value for UPDATEDBY and UPDATEDON which is present in CREATEDBY and CREATEDON. Why is it so ..??

Thanks in advance
Harshal

推荐答案

因为你要将它们设置为不同的值!

Because you are setting them to different values!
CommonDataAccess.AddInParameter(KaizenConstants.CREATEDON, DbType.DateTime, DateTime.Now.ObjectToDBDateTime());
               CommonDataAccess.AddInParameter(KaizenConstants.UPDATEDON, DbType.DateTime, fileLog.CreatedOn);



如果在插入数据库时​​希望它们相同,为什么不为每个值使用相同的参数?例如




If you want them to be the same when you insert into the database why not just use the same parameter for each value? E.g.

INSERT INTO K2FILELOG
       (FILEPATH, [FILENAME],FILETYPE,FILEDATE,CIRCLEID,TOTALROWS,SUCCESSCOUNT,FAILURECOUNT,PROCESSED,ERROR,CREATEDBY, CREATEDON,UPDATEDBY,UPDATEDON, DELETED)
values (@FILEPATH ,@FILENAME,@FILETYPE,@FILEDATE,@CIRCLEID,@TOTALROWS,@SUCCESSCOUNT,@FAILURECOUNT,@PROCESSED,@ERROR ,@CREATEDBY,@CREATEDON,@CREATEDBY,@CREATEDON,@DELETED);

我通常使用SQL函数 GETDATE () ...

I usually use the SQL function GETDATE()...

values (@FILEPATH ,@FILENAME,@FILETYPE,@FILEDATE,@CIRCLEID,@TOTALROWS,@SUCCESSCOUNT,@FAILURECOUNT,@PROCESSED,@ERROR ,@CREATEDBY,GETDATE(),@UPDATEDBY,GETDATE(),@DELETED);

(但请注意,您将获得服务器日期,不是本地机器日期)

(but note that you will get the server date, not the local machine date)


在下面的代码中,您传递的是filelog.createdon和filelog.createdby,它与您为createdby和createdon传递的内容不同。请记住,仍未提交查询以供服务器提取数据。

In your code as below, you are passing filelog.createdon and filelog.createdby which is diffrent than what you are passing for createdby and createdon. Remember the query is still not submitted for the server to pull the data.
CommonDataAccess.AddInParameter(KaizenConstants.CREATEDBY, DbType.Int32, 1);
             CommonDataAccess.AddInParameter(KaizenConstants.CREATEDON, DbType.DateTime, DateTime.Now.ObjectToDBDateTime());
             CommonDataAccess.AddInParameter(KaizenConstants.UPDATEDON, DbType.DateTime, fileLog.CreatedOn);
             CommonDataAccess.AddInParameter(KaizenConstants.UPDATEDBY, DbType.Int32, fileLog.CreatedBy);





请更新以下代码:





Please update the code as below:

<pre lang="sql">CommonDataAccess.AddInParameter(KaizenConstants.CREATEDBY, DbType.Int32, 1);
             CommonDataAccess.AddInParameter(KaizenConstants.CREATEDON, DbType.DateTime, DateTime.Now.ObjectToDBDateTime());
             CommonDataAccess.AddInParameter(KaizenConstants.UPDATEDON, DbType.DateTime, DateTime.Now.ObjectToDBDateTime());
             CommonDataAccess.AddInParameter(KaizenConstants.UPDATEDBY, DbType.Int32, 1);</pre>


这篇关于我如何设置更新的列与Createdby相同,并且Createdon与在Sql中的Updatedon相同的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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