SqlDbType.DateTime System.DataTime conversion. RRS feed

  • Question

  • Hi.

    Why am I getting an overflow on the below. Everything I can find indicates that this should work.

    Will get around it for now using getdate() in the proc but would like to understand.

    cmd.Parameters.Add("@pdPackageCreationDate", SqlDbType.DateTime).Value = DateTime.Now;



    Monday, July 14, 2014 11:55 AM


All replies

  • When are you getting the error?  Is it when you execute the command?  Is the database field a DATE or a VARCHAR?  The method getdate() uses a string so I suspect the database field should be changed from a VARCHAR to a DATE?


    Monday, July 14, 2014 12:38 PM
  • Hi.

    @pdPackageCreationDate is DateTime type in the database.

    Exception throws when the stored procedure is called on the command execute.

    Sorry mislead you slightly with getdate(). All I was saying is that to get around I got rid of that parameter completely and just generated the desired date in the proc (using getdate()) instead passing it from the .net client.



    Monday, July 14, 2014 12:53 PM
  • Can you get the Stack Trace (including inner exception) by either copy details to clipboard on Pop-Up or add a CATCH and get the ex.StackTrace?


    Monday, July 14, 2014 4:54 PM
  • Does it happen even if you pass this value: ‘ . . . = new SqlDateTime(DateTime.Now)’, or use AddWithValue?

    Also confirm that the parameter of stored procedure (not only the column) is a datetime too.

    Monday, July 14, 2014 6:08 PM