Neeraj Kumar
Neeraj Kumar

Reputation: 779

Implicit conversion from data type datetime to timestamp is not allowed

The error message:

Implicit conversion from data type datetime to timestamp is not allowed

The C# dateTime definition:

DateTime dateTime = DateTime.UtcNow;

Calling SQL Server stored procedure with DateTime parameter (from C#):

   sqlCommand.CommandText = "dbo.StoredPrcoName";
   sqlCommand.CommandType = CommandType.StoredProcedure;
   sqlCommand.Parameters.Clear();
   sqlCommand.Parameters.AddWithValue("@BirthDate", dateTime);

I get in SQL Server:

@BirthDate datetime  = NULL, 

What am I missing here?

Upvotes: 1

Views: 2902

Answers (1)

Dan Guzman
Dan Guzman

Reputation: 46301

The SQL Server timestamp data type is unrelated to date or time; timestamp is a poorly named legacy synonym for rowversion, an automatically incremented value used for optimistic concurrency checking.

The error message indicates you have inadvertently used timestamp it in your stored procedure or database schema instead of datetime or datetime2.

Upvotes: 2

Related Questions