using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Data.SQLite; using System.Windows.Forms; namespace WindowsFormsApp1.utils { class SQLiteDataBaseUtil { SQLiteConnection con; private static SQLiteDataBaseUtil instance; public static SQLiteDataBaseUtil getInstance() { if (instance == null) { SQLiteConnection.CreateFile("BKZ");//创建数据库 instance = new SQLiteDataBaseUtil(); instance.con = new SQLiteConnection("Data Source=BKZ;Version=3;"); instance.init(); } return instance; } //初始化数据库 private void init() { this.con = new SQLiteConnection("Data Source=record.sqlite;Version=3;"); con.Open(); string sql = "CREATE TABLE IF NOT EXISTS tb_account_info (accountName varchar(128), loginState int)"; SQLiteCommand command = new SQLiteCommand(sql, con); command.ExecuteNonQuery(); con.Close(); } //添加本地淘宝账号 public void AddTaoBaoAccount() { con.Open(); string sql = "insert into tb_account_info (accountName, loginState) values ('贺小辉1011', 1)"; SQLiteCommand command = new SQLiteCommand(sql, con); command.ExecuteNonQuery(); con.Close(); } //查询淘宝账号 public void ListTaoBaoAccount() { con.Open(); string sql = "select * from tb_account_info"; SQLiteCommand command = new SQLiteCommand(sql, con); SQLiteDataReader reader = command.ExecuteReader(); while (reader.Read()) Console.WriteLine("accountName: " + reader["accountName"] + "\n loginState: " + reader["loginState"]); Console.ReadLine(); con.Close(); } //删除淘宝账号 //修改账号状态 } }