如何检索实际的列值。

时间:2013-04-25 06:56:59

标签: c# asp.net sql

在我的作品中,我有一张桌子

reservation_available(seat_id, seat_type, flight_id, available)

其中flight_id是外键,seat_type连续有两个值(经济,商业)。 要检索seat_id并且我写了:

 using (SqlCommand command = new SqlCommand("SELECT seat_id, seat_type, available FROM reservation_available WHERE seat_type = 'Economic' AND reservation_available.flight_id = '" + flight_id + "' ", connection))
                {

                    string s_ID = seat_id.ToString();
                    string e_avail = EconomicAvailable.ToString();
                    string st = seat_type;


                    SqlDataReader myReader = command.ExecuteReader();

                    while (myReader.Read())
                    {
                        s_ID = myReader[0].ToString();
                        st = myReader[1].ToString();
                        e_avail = myReader[2].ToString();

                    }
                    int sId = Convert.ToInt32(s_ID);
                    int eAvail = Convert.ToInt32(e_avail);

                    myReader.Close();
                    set2(sId, eAvail, st);
                }

和seat_type ='Business'的类似代码。

但检索到的数据仅显示seat_type =“Business”的“seat_id”。 但我想为所选的seat_type分别设置seat_id。

需要帮助

1 个答案:

答案 0 :(得分:0)

试试这个

SELECT seat_id, seat_type, available FROM reservation_available WHERE (seat_type = 'Business' or seat_type = 'Economic') AND reservation_available.flight_id = '" + flight_id + "' 

OR参数

SELECT seat_id, seat_type, available FROM reservation_available WHERE seat_type = '"+varSeatType+"' AND reservation_available.flight_id = '" + flight_id + "'