'将数据类型nvarchar转换为datetime'

时间:2018-01-25 06:51:38

标签: c# sql-server entity-framework datetime

我从实体框架调用过程并传递DateTime参数值,如下所示:

("@dtAnsweredOn", SqlDbType.DateTime, objTestApplicationTaskProperty.AnsweredTime.Value )
  

'将数据类型nvarchar转换为datetime'

时出错

AnsweredTime是一个c#属性,它返回一个日期时间对象

private Nullable<DateTime> dtAnsweredTime = null;

public Nullable<DateTime> AnsweredTime
{
    get { return dtAnsweredTime; }
    set { dtAnsweredTime = value; }
}

该参数在我的程序中定义,如@dtAnsweredOn DATETIME。我错过了什么?

编辑:

正如其他人所说,这是我在使用@dtAnsweredOn的过程中的sql代码。仅供参考dtCreatedOn也是日期时间列。

CREATE PROCEDURE [dbo].[Some_Proc]
(...
 @dtAnsweredOn datetime,
 ...
)
AS                                                    
BEGIN
 IF(Some_Condition)
  BEGIN
   INSERT INTO Some_Table (... dtCreatedOn...)
   VALUES (...@dtAnsweredOn...)
  END
 ELSE
  BEGIN
   UPDATE Some_Table SET Some_column = Some_value  
   WHERE dtCreatedOn = @dtAnsweredOn
  END
END

**

更新

**

使用Profiler我可以看到传递给过程的值在t-sql中被视为nvarchar,原因不明@dtAnsweredOn=N'25.01.2018 16:08:57'

0 个答案:

没有答案