public static FileItem FindFileFromFileInfo(FileInfo item) { FileItem itemToReturn = new FileItem(); var SqlConnection = new SQLiteConnection("Data Source=" + DBLocation + "; Version=3"); SqlConnection.Open(); var sql = "Select * FROM FilesFound WHERE FileName = \"" + item.Name + "\" AND FileLocation = \"" + item.FullName + "\""; var cmd = new SQLiteCommand(sql, SqlConnection); cmd.ExecuteNonQuery(); SQLiteDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { itemToReturn = new FileItem { ID = Convert.ToInt32(reader["ID"].ToString()), FileLocation = reader["FileLocation"].ToString(), FileName = reader["FileName"].ToString(), DisplayName = reader["DisplayName"].ToString(), ExtensionID = Convert.ToInt32(reader["ExtensionID"].ToString()), Type = (FileType)Convert.ToInt32(reader["Type"].ToString()), LastUsed = Convert.ToDateTime(reader["LastUsed"].ToString()), TotalUsed = Convert.ToInt32(reader["TotalUsed"].ToString()) }; } SqlConnection.Close(); return itemToReturn; }
public static bool InsertIntoFilesTable(FileItem item) { try { var SqlConnection = new SQLiteConnection("Data Source=" + DBLocation + "; Version=3"); SqlConnection.Open(); var sql = "INSERT INTO FilesFound(FileName,ExtensionID,Type,DisplayName,LastUsed,TotalUsed,FileLocation) VALUES ('" + item.FileName + "','" + item.ExtensionID + "','" + (int)item.Type + "','" + item.DisplayName + "','" + item.LastUsed + "','" + item.TotalUsed + "','" + item.FileLocation + "')"; SQLiteCommand cmd = new SQLiteCommand(sql, SqlConnection); cmd = new SQLiteCommand(sql, SqlConnection); cmd.ExecuteNonQuery(); SqlConnection.Close(); return true; } catch (Exception e) { return false; throw e; } }