Using DateTime in a SqlParameter for Stored Procedure, format error

后端 未结 4 1263
予麋鹿
予麋鹿 2020-11-27 20:04

I\'m trying to call a stored procedure (on a SQL 2005 server) from C#, .NET 2.0 using DateTime as a value to a SqlParameter. The SQL type in the s

4条回答
  •  南笙
    南笙 (楼主)
    2020-11-27 20:45

    If you use Microsoft.ApplicationBlocks.Data it'll make calling your sprocs a single line

    SqlHelper.ExecuteNonQuery(ConnectionString, "SprocName", DOB)
    

    Oh and I think casperOne is correct...if you want to ensure the correct datetime over multiple timezones then simply convert the value to UTC before you send the value to SQL Server

    SqlHelper.ExecuteNonQuery(ConnectionString, "SprocName", DOB.ToUniversalTime())
    

提交回复
热议问题