【发布时间】:2011-10-23 13:24:16
【问题描述】:
int availableSeat = 0;
string query = "select flight_no flight_seat from flight_info where flight_departure_time = @selectedFlight AND flight_from = @flightFrom AND flight_to = @flightTo ";
string url = "Server=localhost;Database=flight;uid=******;password=*****";
con1 = new MySqlConnection(url);
con1.Open();
cmd1 = new MySqlCommand(query,con1);
cmd1.Parameters.AddWithValue("@selectedFlight",comboBox3.SelectedItem);
cmd1.Parameters.AddWithValue("@flightFrom",comboBox1.SelectedItem);
cmd1.Parameters.AddWithValue("@flightTo",comboBox2.SelectedItem);
reader = cmd1.ExecuteReader();
while (reader.Read())
{
availableSeat.Equals(reader["flight_seat"]);
if(availableSeat > 0)
{
MessageBox.Show("The seat is available!!");
}
else
{
MessageBox.Show("Sorry, all seat has been booked!!");
}
}
con1.Close();
正如您在此处看到的,我想将 SQL 中的 flight_seat 列存储到 availableSeat 中,以检查是否有空位。
我该怎么做?因为它一直在其他地方。
【问题讨论】:
标签: c# mysql datareader