C# sqlite 晋级版
NuGet 中添加
sqlite-net-pcl
SQLitePCLRaw.bundle_green
数据类设置
[Table("TestProjectData")] public class TestProjectModel { [PrimaryKey, AutoIncrement] [Column("ID")] public int ID { get; set; } [Column("ProjectName")] public string ProjectName { get; set; } [Column("CreadTime")] public DateTime CreadTime { get; set; } }
数据库创建
string dbPath = Path.Combine(path, $"{ProjectName}.db"); // 只给路径就行, 自动创建文件 using (SQLiteConnection db = new SQLiteConnection(dbPath)) { db.CreateTable<TestProjectModel>(); db.CreateTable<MonitorDataModule>(); }
数据插入
using (SQLiteConnection db = new SQLiteConnection(dbPath)) { TestProjectModel testProject = new TestProjectModel(); testProject.ProjectName = ProjectName; testProject.CreadTime = DateTime.Parse(CreadTime); db.Insert(testProject); }