dll:
值得注意的是:
将SQLite.Interop.dll
(路径:C:\Users\withyzu\.nuget\packages\stub.system.data.sqlite.core.netstandard\1.0.113.2\lib\netstandard2.1
)
复制到
C:\Users\withyzu\source\repos\ConsoleApp11\bin\Debug\netcoreapp3.1
一、Program.cs
using System;
using System.Data.SQLite;
using System.IO;
namespace ConsoleApp11
{
class Program
{
static void Main(string[] args)
{
//创建数据库
string DBname = "Terminator.sqlite";
if (!File.Exists("Terminator.sqlite"))
SQLiteConnection.CreateFile($"{DBname}");
//连接数据库
SQLiteConnection conn = new SQLiteConnection($"Data Source = {DBname}; Version = 3");
conn.Open();
//创建表
string sql = null;
sql = "select count(*) from sqlite_master where type='table' and name= 'robot';";
if (Convert.ToInt32((new SQLiteCommand(sql, conn)).ExecuteScalar()) == 0)
{
sql = $"create table robot(name string , model string)";
(new SQLiteCommand(sql, conn)).ExecuteNonQuery();
}
//插入数据
for (int i = 79; i <= 82; i++)
{
sql = $"insert into robot(name, model) values('Anrold-{Convert.ToChar(i)}', 'T800{Convert.ToChar(i)}')";
(new SQLiteCommand(sql, conn)).ExecuteNonQuery();
}
//查询
sql = "select * from robot";
SQLiteDataReader reader = (new SQLiteCommand(sql, conn)).ExecuteReader();
while (reader.Read())
Console.WriteLine("Name: " + reader["name"] + "\tModel: " + reader["model"]);
Console.ReadLine();
//关闭
conn.Close();
}
}
}
二、运行结果
三、解决方案管理器