SQLite

发布于:2024-08-09 ⋅ 阅读:(160) ⋅ 点赞:(0)

SQLite Insert  插入 语句

方式1:

INSERT INTO TABLE_NAME [(column1, column2, column3,...columnN)]  
VALUES (value1, value2, value3,...valueN);

方式2:

INSERT INTO TABLE_NAME VALUES (value1,value2,value3,...valueN);

(如果要为表中的所有列添加值,您也可以不需要在 SQLite 查询中指定列名称。但要确保值的顺序)

与SQL对比

查询语句对比

sql sqlite
SqlConnection SQLiteConnection
SqlCommand SQLiteCommand
SqlDataReader SQLiteDataReader

数据类型对比

SQLite数据库中没有专门的bool类型

使用INTEGER类型:SQLite数据库中没有专门的布尔类型,但可以使用INTEGER类型来存储布尔值。可将0表为假(false),将
非零值(通常)表为真(true)。在创建表时,将字段的类型指定为INTEGER即可。

在winform项目中使用

1、nuget中引用,搜索System.Data.SQLite

2、app.config文件中添加connectionStrings

	......
    <connectionStrings>
		<add name="constr" connectionString="Data Source=testdb.db;Version=3;"
			 providerName="System.Data.SQLite" />
	</connectionStrings>	
</configuration>
3、添加using引用using System.Configuration;using System.Data.SQLite;
并使用connectionString
using System.Configuration;
using System.Data.SQLite;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace sqlite
{
    internal class Class1
    {
        public static string MyProperty;
        public static byte byteSB;
        public static int TaskNo;
      public static  string connectionString = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;