SQLite没有创建DateTime字段
本文关键字:DateTime 字段 创建 SQLite | 更新日期: 2023-09-27 18:11:14
在我的c# VS2015 Windows 10通用应用程序中,我无法在数据库模式中创建DateTime字段。它会创建一个bigint。我还有其他表,它们创建了一个DateTime字段,没有问题。
这里有一个例子:(参见GameDate字段)表[结果]领域:17(季):nvarchar (100)[Id]:整数[HomeTeamName]: nvarchar (100)[OppTeamName]: nvarchar (100)[GameDate]: datetime
Foreign Keys: 0
Indexes: 1
[] PRIMARY
[Id] AUTOINCREMENT
Triggers: 0
Unique constraints: 0
Check constraints: 0
private void AddUserButton_Click(object sender, RoutedEventArgs e)
{
User user = new User();
user.Name = "User1";
user.GameDate = Convert.ToDateTime("2015-09-02");
var path = Path.Combine(Windows.Storage.ApplicationData.Current.LocalFolder.Path, "BaseBallOU.db");
using (SQLite.Net.SQLiteConnection conn = new SQLite.Net.SQLiteConnection(new SQLite.Net.Platform.WinRT.SQLitePlatformWinRT(), path))
{
conn.Insert(user);
}
}
private void CreateTablesButton_Click(object sender, RoutedEventArgs e)
{
var path = Path.Combine(Windows.Storage.ApplicationData.Current.LocalFolder.Path, "BaseBallOU.db");
using (SQLite.Net.SQLiteConnection conn = new SQLite.Net.SQLiteConnection(new SQLite.Net.Platform.WinRT.SQLitePlatformWinRT(), path))
{
conn.CreateTable<User>();
conn.CreateTable<TeamX>();
}
}
}
public class User
{
[SQLite.AutoIncrement, SQLite.PrimaryKey]
public int id { get; set; }
public DateTime GameDate { get; set; }
public string Name { get; set; }
}
public class TeamX
{
[SQLite.AutoIncrement, SQLite.PrimaryKey]
public int id { get; set; }
public string TeamName { get; set; }
public DateTime GameDate { get; set; }
}
下面是在表中创建的内容:
Table [TeamX]
Fields: 3
[id]: integer
[TeamName]: varchar
[GameDate]: bigint
Foreign Keys: 0
Indexes: 0
Triggers: 0
Unique constraints: 0
Check constraints: 0
我使用以下引用:
sqlite-net-pclSQLite。Net-PCLSQLite for Universal App Platform
如果我没有弄错的话,在SQLite数据库中没有日期时间类型。保存新对象时将日期转换为字符串,读取对象时将其转换回DateTime。