主窗体类
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SQLite;
using System.IO;
namespace SqlitTest
{
public partial class Form1 : Form
{
static string DbName = "testc";
static string CurTable = "表2";
static string CurColNum = "列1";
static string filePath = "db";
public Form1()
{
InitializeComponent();
UpdateDbname();
}
private void UpdateDbname()
{
string[] files = Directory.GetFiles(filePath, "*.db");
foreach (string i in files)
{
string str = i.Replace($"{filePath}\\","");
str = str.Replace(".db", "");
if( !comboBoxDbNameList.Items.Contains(str))
comboBoxDbNameList.Items.Add(str);
}
if (comboBoxDbNameList.Items.Contains(DbName))
{
int m = 0;
foreach (string j in comboBoxDbNameList.Items)
{
if (DbName == j)
{
}
m++;
}
}
UpdateTbName2();
}
private void UpdateTbName()
{
DataTable dt = new DataTable();
using (SQLiteConnection connection = new SQLiteConnection($"Data Source=db/{DbName}.db"))
{
if (connection.State != ConnectionState.Open)
connection.Open();
using (SQLiteCommand command = new SQLiteCommand(connection))
{
command.CommandText = "select * from sqlite_master where type = 'table' order by name; ";
using (SQLiteDataAdapter sda = new SQLiteDataAdapter(command))
{
sda.Fill(dt);
}
comboBoxTbNameList.Items.Clear();
if (dt.Rows.Count > 0)
{
DataRow[] tbs = dt.Select("type = 'table'");
foreach (var tb in tbs)
comboBoxTbNameList.Items.Add(