Reputation: 25
Ive got a problem and need your help with it. Here is my Main Window:
I fill the comboBox with the table tbl_Training From my Sql Server 2012 Database. On SelectionChange I get The ID and fill The ListBox:
string selectedValue = Convert.ToString(comboTraining.SelectedValue);
string sqlStrGridFill = @"SELECT (P.FirstName + ' ' + P.LastName) as Name
FROM tbl_Participant P
INNER JOIN tbl_Training T
ON P.ID_Training = T.ID_Training
WHERE P.ID_Training ="+ selectedValue +";";
conn.Open();
SqlDataAdapter da = new SqlDataAdapter(sqlStrGridFill, conn);
DataTable dt = new DataTable();
da.Fill(dt);
lbParticipantList.ItemsSource = dt.DefaultView;
lbParticipantList.DisplayMemberPath = Convert.ToString(dt.Columns["Name"]);
lbParticipantList.SelectedValuePath = "ID_Participant";
conn.Close();
now i want to get the ID_Participant on SelectChange from the ListBox. I tried a lot of things. This was my first and last try:
string selectedValue = Convert.ToString(lbParticipantList.SelectedValue);
selectedValue = ""
...Sadly it has to work until tommorow.
Upvotes: 0
Views: 504
Reputation: 1187
You don't have any column named "ID_Participant" in the result from the SQL.
The first line of your SQL should be
SELECT ID_Participant, (P.FirstName + ' ' + P.LastName) as Name
This is why you're getting an empty string every time.
Upvotes: 2