做网站开发电脑配置,wordpress 优酷视频,php创建网页,网站优化联系1#xff0c;一般的访问方式。
1.1#xff0c;连接语句。
//sqlite 连接,支持相对位置#xff0c;也支持绝对位置
Data Source../../Database/cater.db// 连接数据库#xff0c;FailIfMissingfalse时若文件不存在会自动创建
string connStr DataSourcetest.db;Vers…1一般的访问方式。
1.1连接语句。
//sqlite 连接,支持相对位置也支持绝对位置
Data Source../../Database/cater.db// 连接数据库FailIfMissingfalse时若文件不存在会自动创建
string connStr DataSourcetest.db;Version3;Poolingtrue;FailIfMissingfalse;;
1.2配置文件设置。
//需在配置文件中进行如下配置否则报错
startup useLegacyV2RuntimeActivationPolicytrue supportedRuntime versionv4.0 sku.NETFramework,Versionv4.5.2 /
/startup1.3常用语法。
//语法
select * from AlarmHistory
insert into alarmhistory (AlarmDetails,starttime) values (abcgetdate())
//获取当前时间
select datetime(now)
SELECT datetime(now, localtime);
select CURRENT_TIMESTAMP//插入当前时间
insert into alarmhistory (alarmdetails,starttime) values(,datetime(now,localtime))//查找为null的数据
select * from alarmhistory where StartTime is null//修改表格序号update sqlite_sequence set seq 0 where name AlarmHistory//查询表格主键
select * from
pragma_table_info (ActualData) where pk1//查询表格是否存在
select exists( select * from sqlite_master where typetable and nameActualData)//删除表格drop table ActualData //获取和设置时间时间格式只支持类似yyyy-MM-dd这样用-连接的格式若用/连接则无效
select datetime(2024-08-22 16:23:55)
SELECT datetime(now, localtime);
1.4SQLite访问dll。
https://download.csdn.net/download/lingxiao16888/89914696
2基于EntityFramework的ORM数据访问。
2.1安装Nuget包
这部分比较简单直接Nuget包中下载即可
System.Data.SQLiteSystem.Data.SQLite.EF6System.Data.SQLite.LINQSQLite.CodeFirst 2.2配置文件需要进行如下修改。
?xml version1.0 encodingutf-8?
configurationconfigSections!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID237468 --section nameentityFramework typeSystem.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version6.0.0.0, Cultureneutral, PublicKeyTokenb77a5c561934e089 requirePermissionfalse //configSectionsstartupsupportedRuntime versionv4.0 sku.NETFramework,Versionv4.5.2 //startupentityFrameworkprovidersprovider invariantNameSystem.Data.SqlClient typeSystem.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer /provider invariantNameSystem.Data.SQLite typeSystem.Data.SQLite.EF6.SQLiteProviderServices, System.Data.SQLite.EF6 /provider invariantNameSystem.Data.SQLite.EF6 typeSystem.Data.SQLite.EF6.SQLiteProviderServices, System.Data.SQLite.EF6 //providers/entityFrameworksystem.dataDbProviderFactoriesremove invariantSystem.Data.SQLite.EF6 /add nameSQLite Data Provider (Entity Framework 6) invariantSystem.Data.SQLite.EF6 description.NET Framework Data Provider for SQLite (Entity Framework 6) typeSystem.Data.SQLite.EF6.SQLiteProviderFactory, System.Data.SQLite.EF6 /remove invariantSystem.Data.SQLite /add nameSQLite Data Provider invariantSystem.Data.SQLite description.NET Framework Data Provider for SQLite typeSystem.Data.SQLite.SQLiteFactory, System.Data.SQLite //DbProviderFactories/system.data
/configuration
2.3应用。
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity;
using System.Data.SQLite;
using System.Linq;
using System.Text;
using System.Threading.Tasks;namespace ConsoleApp2
{class Program{static void Main(string[] args){MyDbContext context new MyDbContext(cater.db);var set context.SetMemmberType();var ss set.FirstOrDefault();foreach (var item in set){Console.WriteLine(${item.MemTpName} ; {item.MemType} ; {item.MemTpDesc} ; {item.SubBy} ;{item.DelFlag});}Console.WriteLine(输出完成);Console.ReadKey();}}class MyDbContext : DbContext{public MyDbContext(string constr) : base(new SQLiteConnection{ConnectionString new SQLiteConnectionStringBuilder{DataSource constr,ForeignKeys true}.ConnectionString}, true){}//如果查询 MemmberType 表则该属性不能省略public virtual DbSetMemmberType MemmberType { get; set; }}[Table(MemmberType)]//该特性不能省略class MemmberType{[Key]//如果存在主键该特性不能省略[Column(MemType,TypeName INT)]public int MemType { get; set; }//[Column(MemTpName)]public string MemTpName { get; set; }[Column(MemTpDesc)]//可使用 Required 特性指定该列不能为空public string MemTpDesc { get; set; }//[Column(DelFlag)]public int DelFlag { get; set; }//[Column(SubBy)]public int SubBy { get; set; }}
}
2.4效果。
数据库文件数据。 查询结果。