Populating a comboBox from data table and use the combobox selection value in another query
<p>I am having an issue with the result of a comboBox which is populated from a query to a data table.</p>

<p>Like a lot of community members say" I've been at this for hours, in my case it's days". Any help would be great, or am I doing this completely wrong.</p>

<p>I want to be abale to populate the comboBox with a description and use the value of that description in another query.</p>

<p>The comboBox populates with the correct data but for some reason I can not read the value.</p>

<p>I am trying to read the value of the comboBox, "which is a data table name" and use it in the second query.</p>

<p>This is what I have so far:</p>

<pre><code>// POPULATED THE COMBOBOX

MySqlConnection myConnAirport = new MySqlConnection(myConnectionA);
MySqlCommand SelectCommandAirport = new MySqlCommand("SELECT AirportName, DataTable " + 
                                                     "FROM AirportList;", myConnAirport);

MySqlDataAdapter objDA = new MySqlDataAdapter(SelectCommandAirport);
objDA.SelectCommand.CommandText = SelectCommandAirport.CommandText.ToString();

DataTable dt = new DataTable();
objDA.Fill(dt);
comboBox1.DataSource = dt;
comboBox1.DisplayMember = dt.Columns[0].ColumnName;
comboBox1.ValueMember = dt.Columns[1].ColumnName;
string pn = comboBox1.ValueMember;
textBox1.Text = pn;
AirportID.Airport = comboBox1.ValueMember;


// CODE FOR COMBOBOX CHANGE
string asid;
asid = AirportID.Airport;

MySqlConnection myConnAirportSelect = new MySqlConnection(myConnectionU);
MySqlCommand SelectCommandU = new MySqlCommand("SELECT DataTable FROM AirportList " + 
                                               "WHERE DataTable = '" + asid + "';", 
                                               myConnAirportSelect);
MySqlDataReader myReader;
myConnAirportSelect.Open();
myReader = SelectCommandU.ExecuteReader();
try
{
    if (myReader.Read())
    {
        string sAirport = myReader.GetString("DataTable");
        AirportID.Airport = sAirport;
    }
}
catch (Exception ex)
{
    MessageBox.Show(ex.Message);
}
myConnAirportSelect.Close();


// CODE FOR SECOND QUERY THAT SHOULD USE THE RESULT OF THE COMBOBOX CHANGE
string asid = AirportID.Airport;
try
{
    MySqlConnection myConnFlight = new MySqlConnection(myConnection);
    MySqlCommand SelectCommand = new MySqlCommand("SELECT ArriveDepart, Flight, FlightDate, " +
                                                  "ScheduledTime, IATALookup, Terminal, " + 
                                                  "RemarkswithTime, Logo, AirlineName " + 
                                                  "FROM '"+ asid +"' " + 
                                                  "WHERE Flight = '" + 
                                                  this.flightno_txt.Text + "';", myConnFlight);
    MySqlDataReader myReader;
    myConnFlight.Open();
    myReader = SelectCommand.ExecuteReader();
    if (myReader.Read())
    {
        // POPULATE TEXTBOXES
    }
    flightno_txt.Clear();
    myConnFlight.Close();
}
catch (Exception ex)
{
    MessageBox.Show(ex.Message);
}
</code></pre>
