简体   繁体   English

Windows Phone 8.1运行时项目上的SQLite.Net Extensions数据插入错误

[英]SQLite.Net Extensions Data insertion error on Windows Phone 8.1 Runtime project

I have been using the SQLiteAsyncConnection for all the database operations and it was recently I came to know that it doesn't allow association between tables. 我一直在对所有数据库操作使用SQLiteAsyncConnection,最近我才知道它不允许表之间的关联。 Now I am in the process of moving the code to use the SQLite.Net Extension which supports extensions. 现在,我正在移动代码以使用支持扩展的SQLite.Net扩展。 I have found a weird issue when I insert datetime data into the table. 当我将日期时间数据插入表中时,我发现了一个奇怪的问题。 It completely changes the datetime on insertions. 它完全更改了插入的日期时间。

App.db2.Insert(new FrequentlyAssignedShifts()
                {
                    ShiftStart = Convert.ToDateTime(btnShiftStart.Content.ToString()),
                    ShiftEnd = Convert.ToDateTime(btnShiftEnd.Content.ToString()),
                });

And this is how the connection is established. 这就是建立连接的方式。

        string databasePath = Path.Combine(Windows.Storage.ApplicationData.Current.LocalFolder.Path, "Scheduler.sqlite");
    public static SQLiteConnection db2;
    var platform = new SQLite.Net.Platform.WinRT.SQLitePlatformWinRT();
    db2 = new SQLiteConnection(platform, databasePath);

I checked until the last point using breakpoints, whether the right data is getting inserted. 我使用断点检查到最后一点,是否插入了正确的数据。 It all seems fine, it is getting the right date from the button controls, but the moment it passes this part of the code the date value changes. 一切似乎都很好,它是从按钮控件中获取正确的日期,但是一旦它通过了代码的这一部分,日期值就会改变。 The "ShiftStart & ShiftEnd" variables are datetime variables in the Table. “ ShiftStart&ShiftEnd”变量是表中的日期时间变量。 Could someone please advise. 有人可以建议。

Thanks for reading the post. 感谢您阅读这篇文章。

也许为时已晚,但据我所知,时间在数据库中保存为滴答,所以不要使用“ Date”或“ Timestamp”或其他任何东西,而应使用bigint,因此,该字段将使用UTC将时间保存为滴答,一旦从数据库中检索到值,请使用DateTime和vioala中的函数“ ToLocalTime()”!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM