我有一个填充组合框的查询,并根据组合框的选择将值传递给另一个查询。
我到目前为止的代码是:
MySqlCommand SelectCommandAirport = new MySqlCommand("SELECT AirportName, DataTable FROM AirportList;", myConnAirport);
MySqlDataReader myAirportReader;
myConnAirport.Open();
myAirportReader = SelectCommandAirport.ExecuteReader();
DataTable dataTable = new DataTable();
dataTable.Columns.Add(new DataColumn("AirportName"));
dataTable.Columns.Add(new DataColumn("DataTable"));
comboBox1.DataSource = dataTable;
comboBox1.ValueMember = "AirportName";
comboBox1.DisplayMember = "DataTable";
try
{
while (myAirportReader.Read())
{
DataRow row = dataTable.NewRow();
row["AirportName"] = myAirportReader[1];
row["DataTable"] = myAirportReader[0];
dataTable.Rows.Add(row);
SelectAirport.sAirport = comboBox1.SelectedItem.ToString();
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
然后我有一个第二个查询,它应该使用组合框选择的结果作为第二个查询的变量。
string airportid;
airportid = SelectAirport.sAirport;
MySqlCommand SelectCommand = new MySqlCommand("SELECT ArriveDepart, Flight, FlightDate, ScheduledTime, IATALookup, Terminal, RemarkswithTime, Logo FROM '" + airportid + "' WHERE Flight = '" + this.flightno_txt.Text + "';", myConnFlight);
当我运行代码时,我收到一条 SQL 错误,上面写着“System.Data.DataRowView WHERE Flight =”。
因为这不起作用,我可以假设代码是正确的。谁能看到我哪里出错了。
提前谢谢了。
DCJ
当我运行代码时,我得到一个显示内容的 SQL 错误