Created
March 16, 2018 09:11
-
-
Save anonymous/6818885b973d4f87b7f7338d3c9500c3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.Configuration; | |
using System.Data.SqlClient; | |
namespace muziekdatabaseje13 | |
{ | |
public partial class frmMain : Form | |
{ | |
SqlConnection connection; | |
string connectionString; | |
public frmMain() | |
{ | |
InitializeComponent(); | |
connectionString = ConfigurationManager.ConnectionStrings["muziekdatabaseje13.Properties.Settings.MuziekDBConnectionString"].ConnectionString; | |
PopulateArtists(); | |
} | |
private void frmMain_Load(object sender, EventArgs e) | |
{ | |
} | |
private void PopulateArtists() | |
{ | |
using (connection = new SqlConnection(connectionString)) | |
using (SqlDataAdapter adapter = new SqlDataAdapter("SELECT * FROM Artists", connection)) | |
{ | |
DataTable artistTable = new DataTable(); | |
adapter.Fill(artistTable); | |
listBoxArtists.DisplayMember = "ArtistName"; | |
listBoxArtists.ValueMember = "Info"; | |
listBoxArtists.DataSource = artistTable; | |
} | |
} | |
private void PopulateAlbums() | |
{ | |
string querry = "SELECT a.AlbumName FROM Albums a" + | |
"INNER JOIN Artists b ON a.ArtistsId = b.ArtistsId" + | |
"WHERE ArtistsId = @ArtistsId"; | |
using (connection = new SqlConnection(connectionString)) | |
using (SqlCommand command = new SqlCommand(querry, connection )) | |
using (SqlDataAdapter adapter = new SqlDataAdapter(command)) | |
{ | |
command.Parameters.AddWithValue("@ArtistsId", listBoxArtists.SelectedValue); | |
DataTable albumsTable = new DataTable(); | |
adapter.Fill(albumsTable); | |
listBoxAlbums.DisplayMember = "AlbumName"; | |
listBoxAlbums.ValueMember = "AlbumId"; | |
listBoxAlbums.DataSource = albumsTable; | |
} | |
} | |
private void listBoxArtists_SelectedIndexChanged(object sender, EventArgs e) | |
{ | |
PopulateAlbums(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment