2013-04-25 35 views
0

在我的工作,我有一個表如何檢索實際列值。

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 =「業務」。

但檢索的數據只顯示seat_type =「Business」的「seat_id」。 但我想要爲相應的seat_id選擇seat_type。

幫助需要

+1

你能澄清你想要做什麼,還可以指定你的模型/數據庫的詳細信息? – lexeRoy 2013-04-25 06:59:56

+0

您可以將座位類型作爲參數或寫入條件發送爲'seat_type ='Economic'或seat_type ='Business'' – Amit 2013-04-25 07:02:33

+0

@lexeRoy,當我選擇Economic時座位類型='Economic',座位類型seat_type =我選擇商業類型時選擇「商家」。我用兩個按鈕來選擇經濟和商業。 – 2013-04-25 07:09:09

回答

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 + "' 

或參數基於

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

@Sazzad Hossain,如果夠了,請標記爲答案 – Amit 2013-06-26 12:18:57