I don't really know how to make a specific question of this in the title but. How can I get the Lname, Fname and Mname to string from the comboBox selectedItem. This is my idea but it won't work :/
private void FillWinemakerComboBox()
{
SqlCommand cmand = new SqlCommand("SELECT (Lname+', '+Fname+' '+Mname) AS combinedName, Lname, Fname, Mname FROM Winemaker", con);
con.Open();
SqlDataReader sqlReader = cmand.ExecuteReader();
while (sqlReader.Read())
{
//This is where the comboBox fills the names
winemaker_comboBox.Items.Add(sqlReader["combinedName"].ToString());
//The part where I don't really know how to get the other values
if (winemaker_comboBox.SelectedItem != DBnull.Value)
{
string lastname = sqlReader["Lname"].ToString();
string firstname = sqlReader["Fname"].ToString();
string middlename = sqlReader["Mname"].ToString();
}
}
sqlReader.Close();
con.Close();
}