private void SearchBtn_Click(object sender, EventArgs e) { _photos.Clear(); var query = DBRequests.FindPhoto(); if (!string.IsNullOrWhiteSpace(NameTextBox.Text)) { query = query.WithName(NameTextBox.Text); } if (!string.IsNullOrWhiteSpace(CategoryCombo.Text)) { query = query.WithCategory(_categories[CategoryCombo.SelectedIndex].ID); } if (!string.IsNullOrWhiteSpace(AlbumCombo.Text)) { query = query.WithAlbum(_albums[AlbumCombo.SelectedIndex].ID); } if (!string.IsNullOrWhiteSpace(TagTextBox.Text)) { query = query.WithTag(TagTextBox.Text); } var queryString = query.ToString(); var wherePosition = queryString.IndexOf("WHERE", 0); var firstPart = queryString.Substring(0, wherePosition + 5); var secondPart = queryString.Substring(wherePosition + 5, queryString.Length - firstPart.Length); secondPart = secondPart.Replace("WHERE", "OR"); var newQueryString = firstPart + secondPart; DBRequests.MakeRequest(newQueryString, (connection, command) => { using (var reader = command.ExecuteReader()) { if (reader.HasRows) { while (reader.Read()) { Console.WriteLine(); _photos.Add(new Photo { ID = reader.GetInt32(0), Name = reader.GetString(1), Owner = reader.GetInt32(2), Desc = reader.GetString(3), Tags = reader.GetString(4), Category = reader.GetInt32(5), Album = reader.GetInt32(6), Format = reader.GetString(7), Resolution = reader.GetString(8), CreationDate = reader.GetDateTime(9).ToLongDateString(), Size = reader.GetInt32(10), PhotoData = reader.GetValue(11) as byte[] }); } // Initialize myListView. PhotoList.View = View.Tile; // Initialize the tile size. PhotoList.TileSize = new Size(200, 100); // Initialize the item icons. var ImageList = new ImageList(); foreach (var image in _photos) { var renFace = ImageFromByteArray(image.PhotoData); ImageList.Images.Add(renFace); PhotoList.Items.Add(new ListViewItem(new[] { image.Name }, PhotoList.Items.Count)); } ImageList.ImageSize = new Size(100, 100); PhotoList.LargeImageList = ImageList; // Add column headers so the subitems will appear. PhotoList.Columns.AddRange(new[] { new ColumnHeader() }); } } }); }