private void ConnectWithSelectedAlbums(string imgPath) { int imgId = SqlUtilities.GetImageId(imgPath); foreach (ListItem item in UserAlbums.Items) { int albumId; if (item.Selected && int.TryParse(item.Value, out albumId)) { if (albumId == -1) { albumId = SqlUtilities.InsertIntoAlbums(NewAlbumName.Text, (string)Session["username"]); } SqlUtilities.InsertIntoIncludedIn(imgId, albumId); } } }