I am using dapper CROD operation.
I am trying to enter a new row to a table with DataTime field.
I have created the following class:
//Properties
public int Id { get; set; }
public string Title { get; set; }
public string Message { get; set; }
public int UserID { get; set; }
public DateTime CreationDate { get; set; }
public DateTime UpdateDate { get; set; }
public DateTime ActiveStartDate { get; set; }
public DateTime ExpirationDate { get; set; }
Now, the insert statement is as follow:
public static string InsertNewMessage
=> @"INSERT INTO Messages
(Title,[Message],UserID,CreationDate,UpdateDate,ActiveStartDate,
ExpirationDate)
VALUES (N'@Title',N'@Message',@UserID,CAST('@CreationDate' as
DATETIME),CAST('@UpdateDate' as DATETIME),
CAST('@ActiveStartDate' as DATETIME)
,CAST('@ExpirationDate' as DATETIME))
SELECT CAST(SCOPE_IDENTITY() as int)";
int returnId = _db.Query<int>(QueriesRepository.InsertNewMessage,
_message).SingleOrDefault();
Now what am i doing wrong - i have dig the web for a solution for the following error - with no luck I know the problem is the formatting of the DateTime object, but i saw that Dapper should support that.
Conversion failed when converting date and/or time from character string
CAST
, Dapper can handle DateTime – Shyju Mar 26 '17 at 17:49