免费视频淫片aa毛片_日韩高清在线亚洲专区vr_日韩大片免费观看视频播放_亚洲欧美国产精品完整版

打開(kāi)APP
userphoto
未登錄

開(kāi)通VIP,暢享免費(fèi)電子書(shū)等14項(xiàng)超值服

開(kāi)通VIP
c#和SQL Server中的DateTimeOffset分辨率

Docs聲明,在.NET和SQL服務(wù)器中,分辨率為100ns.

DateTimeOffset值的時(shí)間分量以100納秒單位稱為刻度 – C#
準(zhǔn)確度 – 100納秒 – SQL Server

然而SQL似乎丟掉了最后一位數(shù)(例如我正試圖保存2013-08-15 09:19:07.2459675 -04:00,SQL保存2013-08-15 09:19:07.2459670 -04:00 – 通知最后一位數(shù)改變了.)

這發(fā)生在同一臺(tái)機(jī)器上,因此它不依賴于硬件.

并不是說(shuō)我實(shí)際上需要這個(gè)解決方案,但它使日期更難比較……我只是好奇.

解決方法:

我會(huì)說(shuō)問(wèn)題是你的…一個(gè)小代碼顯示:

namespace Test{    using System;    using System.Data;    using System.Data.SqlClient;    using System.Globalization;    /// <summary>    ///     /// </summary>    public class Program    {        /// <summary>        ///         /// </summary>        public static void Main()        {            // Change the connection string to specify your server.             // Probably you won't need an initial catalog because this            // program uses a temp table            string connStr = "Integrated Security=True";            // The temp table is called #Temp . It will cease to exist at the end             // of the program automatically            // Two columns, DateTimeOffset and ShortDateTimeOffset            string query = @"CREATE TABLE #Temp (DateTimeOffset datetimeoffset(7) NOT NULL, ShortDateTimeOffset datetimeoffset(6) NOT NULL);INSERT INTO #Temp VALUES (@DT1, @DT2);SELECT * FROM #Temp";            using (var connection = new SqlConnection(connStr))            using (var command = new SqlCommand(query, connection))            {                const string dtString = "2013-08-15 09:19:07.2459675 -04:00";                const string dtFormat = "yyyy-MM-dd HH:mm:ss.fffffff zzz";                DateTimeOffset dt = DateTimeOffset.Parse(dtString, CultureInfo.InvariantCulture);                string dtString2 = dt.ToString(dtFormat, CultureInfo.InvariantCulture);                Console.WriteLine("Sending          : {0}", dtString2);                // Just to be sure!                if (dtString != dtString2)                {                    throw new Exception("Problem in conversion");                }                command.Parameters.Add("@DT1", SqlDbType.DateTimeOffset).Value = dt;                command.Parameters.Add("@DT2", SqlDbType.DateTimeOffset).Value = dt;                try                {                    connection.Open();                    using (SqlDataReader reader = command.ExecuteReader())                    {                        if (reader.Read())                        {                            DateTimeOffset dtRec1 = (DateTimeOffset)reader[0];                            DateTimeOffset dtRec2 = (DateTimeOffset)reader[1];                            string dtRecString1 = dtRec1.ToString(dtFormat, CultureInfo.InvariantCulture);                            string dtRecString2 = dtRec2.ToString(dtFormat, CultureInfo.InvariantCulture);                            Console.WriteLine("Receiving (long) : {0}", dtRecString1);                            Console.WriteLine("Receiving (short): {0}", dtRecString2);                            if (dtRec1 != dt)                            {                                throw new Exception("Difference between DateTimeOffset(.NET) and DateTimeOffset(sql)");                            }                            if (Math.Abs(dtRec2.Ticks - dt.Ticks) > 10)                            {                                throw new Exception("Too much difference between DateTimeOffset(.NET) and DateTimeOffset(6)(sql)");                            }                            if (reader.Read())                            {                                throw new Exception("Too many rows");                            }                        }                        else                        {                            throw new Exception("No rows");                        }                    }                }                catch (Exception ex)                {                    Console.WriteLine(ex.Message);                }            }        }    }}


本站僅提供存儲(chǔ)服務(wù),所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊舉報(bào)
打開(kāi)APP,閱讀全文并永久保存 查看更多類似文章
猜你喜歡
類似文章
SQL Server 批量插入數(shù)據(jù)的兩種方法
DataTable類Clone及Copy方法的區(qū)別
SQL Server 2008 中新的日期時(shí)間數(shù)據(jù)類型
關(guān)于SQL Server的日期時(shí)間數(shù)據(jù)類型
datetime2 (Transact
c# mysql數(shù)據(jù)庫(kù)連接(我碰到的問(wèn)題)
更多類似文章 >>
生活服務(wù)
分享 收藏 導(dǎo)長(zhǎng)圖 關(guān)注 下載文章
綁定賬號(hào)成功
后續(xù)可登錄賬號(hào)暢享VIP特權(quán)!
如果VIP功能使用有故障,
可點(diǎn)擊這里聯(lián)系客服!

聯(lián)系客服