SQLite is a software library that implements a self-sufficient, serverless, zero-configuration, transactional lightweight SQL database engine.
- Declare the variable Conn connected to SQLite
Add SQLite operation driver dll reference: System.Data.SQLite.dll
using System.Data.SQLite;
SQLiteConnection Conn;
Direct NuGet package search for System.Data.SQLite.Core
- Create a connection to the specified database
to determine whether the file exists, create it in the path if it does not exist, and then connect to the database
string FilePath = Application.StartupPath + "\\transfer.db";
if ( !File.Exists(FilePath))
SQLiteConnection.CreateFile(FilePath);
}
try
Conn = new SQLiteConnection("Data Source=" + FilePath + ";Version=3;"
);
Conn.Open();
}
catch (Exception ex)
throw new Exception("打开数据库:" + FilePath + "的连接失败: " + ex.Messag e);
}
- create table
string sql = "create table info (name varchar(20), address varchar(40))";
SQLiteCommand command = new SQLiteCommand(sql, m_dbConnection);
command.ExecuteNonQuery();
Author: Wu Hongtao