Click here to Skip to main content
15,883,999 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi Team,

I written the code as follows.
C#
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;
       }


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


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
Posted

Because you are setting them to different values!
SQL
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.

SQL
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);
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)
 
Share this answer
 
Comments
R Harshal 30-Jul-14 6:06am    
this trick i have done but no use .Why is it so ?
Thanks in advance
Harshal
CHill60 30-Jul-14 6:11am    
Why is it no use? Is there something else that is changing the UpdatedOn column? A trigger perhaps?
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.
SQL
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:

XML
<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>
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900