gpt4 book ai didi

c# - 如何存储 sqlDataReader 的值?并进行比较?

转载 作者:行者123 更新时间:2023-11-29 09:03:24 25 4
gpt4 key购买 nike

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 中,以检查是否有可用座位。

我怎样才能做到这一点?因为它不断地去往其他地方。

最佳答案

availableSeat.Equals() 是比较而不是赋值。您需要分配该值。例如

availableSeat = (int)reader["flight_seat"];

关于c# - 如何存储 sqlDataReader 的值?并进行比较?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7866392/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com