vs дать эту ошибку на этой строке «lbl10_drink.Text = reader [1] .ToString();» Мои соединения работают правильно и значения правильно соблюдаются для строки подключения и читателей [0] ...... также мои запросы работают правильно. в чем проблема?Индекс находился за пределами массива в asp.net
{
using (SqlConnection connection1 = DBConnection.getConnection())
{
string strquery1 = " with distinctvalueyes (typearticle) as (select top 1 'Fruit' FROM WeedingSalonGeneralRes where Fruit=1 union all select top 1 'Drink' FROM WeedingSalonGeneralRes where Drink=1 union all select top 1 'Desert' FROM WeedingSalonGeneralRes where Desert=1 union all select top 1 'MainFood' FROM WeedingSalonGeneralRes where MainFood=1 union all select top 1 'Salad' FROM WeedingSalonGeneralRes where Salad=1 union all select top 1 'TableFlower' FROM WeedingSalonGeneralRes where TableFlower=1 union all select top 1 'SaloonLighting' FROM WeedingSalonGeneralRes where SaloonLighting=1 union all select top 1 'Saloondesign' FROM WeedingSalonGeneralRes where Saloondesign=1 union all select top 1 'SloonCrew' FROM WeedingSalonGeneralRes where SloonCrew=1 union all select top 1 'Pastry' FROM WeedingSalonGeneralRes where Pastry=1 union all select top 1 'GiftCard' FROM WeedingSalonGeneralRes where GiftCard=1) select * from distinctvalueyes ";
connection1.Open();
SqlCommand cmd1 = new SqlCommand();
cmd1.Connection = connection1;
cmd1.CommandText = strquery1;
string cis = Session["customerID"].ToString();
lbl2_customerid.Text = cis;
SqlDataReader reader = cmd1.ExecuteReader();
if (reader.Read())
{
lbl8_fruit.Text = reader[0].ToString();
lbl10_drink.Text = reader[1].ToString();
lbl11_desert.Text = reader[2].ToString();
lbl12_mainfood.Text = reader[3].ToString();
lbl13_salad.Text = reader[4].ToString();
lbl14_tableflower.Text = reader[5].ToString();
lbl15_saloonlighting.Text = reader[6].ToString();
lbl16_saloondesign.Text = reader[7].ToString();
lbl17_salooncrew.Text = reader[8].ToString();
lbl18_pastry.Text = reader[9].ToString();
lbl19_giftcard.Text = reader[10].ToString();
using (SqlConnection connection2 = DBConnection.getConnection())
{
//query for fetch service prices
string strquery2 = "SELECT Fruit_price,Drink_price,Desert_price,MainFood_price,Salad_price,TableFlower_price,SaloonLighting_price,SaloonDesign_price,SaloonCrew_price,Pastry_price,GiftCard_price FROM GenReservationServicePrice";
connection2.Open();
SqlCommand cmd2 = new SqlCommand();
cmd2.Connection = connection2;
cmd2.CommandText = strquery2;
SqlDataReader reader2 = cmd2.ExecuteReader();
if (reader2.Read())
{
string Fruit_price;
string Drink_price;
string Desert_price;
string MainFood_price;
string Salad_price;
string TableFlower_price;
string SaloonLighting_price;
string SaloonDesign_price;
string SaloonCrew_price;
string Pastry_price;
string GiftCard_price;
Fruit_price = reader[0].ToString();
Drink_price = reader[1].ToString();
Desert_price = reader[2].ToString();
MainFood_price = reader[3].ToString();
Salad_price = reader[4].ToString();
TableFlower_price = reader[5].ToString();
SaloonLighting_price = reader[6].ToString();
SaloonDesign_price = reader[7].ToString();
SaloonCrew_price = reader[8].ToString();
Pastry_price = reader[9].ToString();
GiftCard_price = reader[10].ToString();
lbl8_fruit.Text = Fruit_price;
}
}
}
}
}
так что в первом запросе я хочу получить только истинные значения из sqlserver, возможно, более одного значения истинно, теперь что мне делать? – meysam
извините, но ваш запрос не работал, я тестирую это в студии управления и имеет больше ошибок – meysam
sory, но можете ли вы написать правильный запрос для меня? – meysam