C# SQLite未创建日期时间字段
在我的C#VS2015 Windows 10 Universal应用程序中,我无法在数据库架构中创建日期时间字段。它会创建一个bigint。我还有其他表创建了一个DateTime字段,没有问题 下面是一个示例:(请参见GameDate字段) 表[结果] 字段:17 [季节]:nvarchar(100) [Id]:整数 [家庭团队名称]:nvarchar(100) [OppTeamName]:nvarchar(100) [游戏日期]:日期时间C# SQLite未创建日期时间字段,c#,sqlite,win-universal-app,C#,Sqlite,Win Universal App,在我的C#VS2015 Windows 10 Universal应用程序中,我无法在数据库架构中创建日期时间字段。它会创建一个bigint。我还有其他表创建了一个DateTime字段,没有问题 下面是一个示例:(请参见GameDate字段) 表[结果] 字段:17 [季节]:nvarchar(100) [Id]:整数 [家庭团队名称]:nvarchar(100) [OppTeamName]:nvarchar(100) [游戏日期]:日期时间 Foreign Keys: 0 Indexes: 1
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; }
}
我使用以下参考资料:
sqlite网络pcl
SQLite.Net-PCL
SQLite for Universal App Platform如果我没有弄错的话,SQLite数据库中没有日期时间类型。
保存新对象时将日期转换为字符串,读取对象时将其转换回DateTime。Miiite,我看到其他引用,SQLite没有DateTime数据类型,但我有其他表,在计算模式时,它显示“datatime”类型。请参阅下面另一个表的模式并查看“GameDate”字段。表[结果]字段:17[季节]:nvarchar(100)[过度不足]:双精度[OverUnderAlpha]:nvarchar(100)[游戏总数]:int[Id]:INTEGER[HomeTeamName]:nvarchar(100)[OppTeamName]:nvarchar(100)[GameDate]:DateTime没错-参考文档中的第2.2节-
Table [TeamX]
Fields: 3
[id]: integer
[TeamName]: varchar
[GameDate]: bigint
Foreign Keys: 0
Indexes: 0
Triggers: 0
Unique constraints: 0
Check constraints: 0