Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/oracle/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何检索实际列值。?_C#_Asp.net_Sql - Fatal编程技术网

C# 如何检索实际列值。?

C# 如何检索实际列值。?,c#,asp.net,sql,C#,Asp.net,Sql,我的工作中有一张桌子 reservation_available(seat_id, seat_type, flight_id, available) 其中flight_id为外键,seat_类型连续具有两个值(经济、业务)。 要检索座位号和可用座位号,我写了: using (SqlCommand command = new SqlCommand("SELECT seat_id, seat_type, available FROM reservation_available WHERE sea

我的工作中有一张桌子

reservation_available(seat_id, seat_type, flight_id, available)
其中flight_id为外键,seat_类型连续具有两个值(经济、业务)。 要检索座位号和可用座位号,我写了:

 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”。 但我需要所选座位类型的相应座位id

需要帮助

试试这个

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

你能澄清你想做什么,并指定你的模型/数据库详细信息吗?你可以发送座位类型作为参数,或者写条件为'seat_type='Economic'或seat_type='Business'@lexeRoy,我想在选择经济时显示seat_type='Economic'的seat_id,在选择业务类型时显示seat_type='Business'。我用了两个按钮来选择经济和商业。@AmitAgrawal,如果我这样做,下面的代码会有什么变化:'while(myReader.Read()){s_ID=myReader[0]。ToString();st=myReader[1]。ToString();e_avail=myReader[2]。ToString()}'如果我在卷曲大括号内添加b_avail:b_avail=myReader[0]。ToString();它将尝试读取另一列或行,但可用值位于同一列中。我只是尝试将可用值与变量分开。这可能会改变。选择座位id,座位类型,从预订可用(座位类型='商务'或座位类型='经济')和预订可用。航班id='“+航班id+”,或选择座位id,座位类型,从预订可用,座位类型='“+varSeatType+”'和预订可用。航班号='“+航班号+”'