public static void CreateTable() { string dbPath = testDatabaseName; //如果不存在改数据库文件,则创建该数据库文件 if (!System.IO.File.Exists(dbPath)) { SQLiteDBHelper.CreateDB(testDatabaseName); } bool tableExist = false; using (SQLiteConnection connection = new SQLiteConnection("Data Source=" + dbPath)) { connection.Open(); using (SQLiteCommand command = new SQLiteCommand(connection)) { command.CommandText = "select count(*) from sqlite_master where type = 'table' and name = 'Test3'"; int num = Convert.ToInt32(command.ExecuteScalar()); if (num > 0) { tableExist = true; } } } if (!tableExist) { SQLiteDBHelper db = new SQLiteDBHelper(testDatabaseName); string sql = "CREATE TABLE Test3(id integer NOT NULL PRIMARY KEY AUTOINCREMENT UNIQUE,Name char(3),TypeName varchar(50),addDate datetime,UpdateTime Date,Time time,Comments blob)"; db.ExecuteNonQuery(sql, null); } }
static public bool SentToDB() { if (!System.IO.File.Exists(dbPath)) { SQLiteDBHelper.CreateDB(dbPath); } bool tableExist = false; using (SQLiteConnection connection = new SQLiteConnection("Data Source=" + dbPath)) { connection.Open(); using (SQLiteCommand command = new SQLiteCommand(connection)) { command.CommandText = "select count(*) from sqlite_master where type = 'table' and name = '" + existFilessName + "'"; int num = Convert.ToInt32(command.ExecuteScalar()); if (num > 0) { tableExist = true; } } } SQLiteDBHelper db = null; string sql = null; if (tableExist) { db = new SQLiteDBHelper(dbPath); sql = "DROP TABLE " + existFilessName; db.ExecuteNonQuery(sql, null); } db = new SQLiteDBHelper(dbPath); sql = "CREATE TABLE " + existFilessName + @"( name TEXT, filePath TEXT )"; db.ExecuteNonQuery(sql, null); sql = "INSERT INTO " + existFilessName + "(name,filePath)values(@name, @filePath)"; db = new SQLiteDBHelper(dbPath); for (int i = 0; i < g_FileInfoCollector.Count; i++) { SQLiteParameter[] parameters = new SQLiteParameter[] { new SQLiteParameter("@name", ((FileInformation)g_FileInfoCollector[i]).FileName), new SQLiteParameter("@filePath", ((FileInformation)g_FileInfoCollector[i]).FullName) }; db.ExecuteNonQuery(sql, parameters); } return(true); }