2016-07-23 4 views
0

salesresult를 클라이언트에 표시하기위한 코드를 작성했습니다. 그러나 결국, 나는 모든 가격을 합하여 lable에 총 가격을 보여주고 싶다. 하지만이 단계에서 실패하고 "입력 문자열이 올바른 형식이 아닙니다." 비주얼 스튜디오에서. 뭐가 문제 야 ?입력 문자열의 형식이 올바르지 않습니다.

protected void Page_Load(object sender, EventArgs e) 
{ 


    /////Fetching Reservation Date and Reservation Time 
    using (SqlConnection connection3 = DBConnection.getConnection()) 
    { 
     string strquery3 = "SELECT SaloonReservationDate,SaloonReservationTime FROM SaloonGeneralReservation"; 
     connection3.Open(); 
     SqlCommand cmd3 = new SqlCommand(); 
     cmd3.Connection = connection3; 
     cmd3.CommandText = strquery3; 
     SqlDataReader reader3 = cmd3.ExecuteReader(); 
     if (reader3.Read()) 
     { 
      lbl4_ResDate.Text = reader3[0].ToString(); 
      lbl6_ResTime.Text = reader3[1].ToString(); 

     } 
    } 


    /////Fetching Service Prices 
    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 reader1 = cmd2.ExecuteReader(); 
     if (reader1.Read()) 
     {        
      Fruit_price = reader1[0].ToString(); 
      Drink_price = reader1[1].ToString(); 
      Desert_price = reader1[2].ToString(); 
      MainFood_price = reader1[3].ToString(); 
      Salad_price = reader1[4].ToString(); 
      TableFlower_price = reader1[5].ToString(); 
      SaloonLighting_price = reader1[6].ToString(); 
      SaloonDesign_price = reader1[7].ToString(); 
      SaloonCrew_price = reader1[8].ToString(); 
      Pastry_price = reader1[9].ToString(); 
      GiftCard_price = reader1[10].ToString(); 

     } 
    } 


    /////Fetching Selected Items by User 
    using (SqlConnection connection1 = DBConnection.getConnection()) 
    {   
     string strquery1 = "SELECT (select top 1 'Fruit' FROM WeedingSalonGeneralRes where Fruit=1) as fruit, (select top 1 'Drink' FROM WeedingSalonGeneralRes where Drink=1) as drink, (select top 1 'Desert' FROM WeedingSalonGeneralRes where Desert=1) as desert,(select top 1 'MainFood' FROM WeedingSalonGeneralRes where MainFood=1) as MainFood,(select top 1 'Salad' FROM WeedingSalonGeneralRes where Salad=1) as salad,(select top 1 'TableFlower' FROM WeedingSalonGeneralRes where TableFlower=1) as TableFlower,(select top 1 'SaloonLighting' FROM WeedingSalonGeneralRes where SaloonLighting=1) as SaloonLighting,(select top 1 'Saloondesign' FROM WeedingSalonGeneralRes where Saloondesign=1) as Saloondesign,(select top 1 'SloonCrew' FROM WeedingSalonGeneralRes where SloonCrew=1) as SloonCrew,(select top 1 'Pastry' FROM WeedingSalonGeneralRes where Pastry=1) as Pastry,(select top 1 'GiftCard' FROM WeedingSalonGeneralRes where GiftCard=1) as GiftCard "; 
     connection1.Open(); 
     SqlCommand cmd1 = new SqlCommand(); 
     cmd1.Connection = connection1; 
     cmd1.CommandText = strquery1; 
     string cis = Session["customerID"].ToString(); 
     lbl2_customerid.Text = cis; 

     double totalcost; 

     SqlDataReader reader2 = cmd1.ExecuteReader(); 
     if (reader2.Read()) 
     { 
      if (reader2[0].ToString() != null && reader2[0].ToString() != "") 
      lbl8_fruit.Text = reader2[0].ToString() + Fruit_price; 



      if (reader2[1].ToString() != null && reader2[1].ToString() != "") 
      lbl10_drink.Text = reader2[1].ToString()+Drink_price; 


      if (reader2[2].ToString() != null && reader2[2].ToString() != "") 
      lbl11_desert.Text = reader2[2].ToString()+Desert_price; 

      if (reader2[3].ToString() != null && reader2[3].ToString() != "") 
      lbl12_mainfood.Text = reader2[3].ToString()+MainFood_price; 


      if (reader2[4].ToString() != null && reader2[4].ToString() != "") 
      lbl13_salad.Text = reader2[4].ToString()+Salad_price; 


      if (reader2[5].ToString() != null && reader2[5].ToString() != "") 
      lbl14_tableflower.Text = reader2[5].ToString()+TableFlower_price; 


      if (reader2[6].ToString() != null && reader2[6].ToString() != "") 
      lbl15_saloonlighting.Text = reader2[6].ToString()+SaloonLighting_price; 


      if (reader2[7].ToString() != null && reader2[7].ToString() != "") 
      lbl16_saloondesign.Text = reader2[7].ToString()+SaloonDesign_price; 


      if (reader2[8].ToString() != null && reader2[8].ToString() != "") 
      lbl17_salooncrew.Text = reader2[8].ToString()+SaloonCrew_price; 


      if (reader2[9].ToString() != null && reader2[9].ToString() != "") 
      lbl18_pastry.Text = reader2[9].ToString()+Pastry_price; 


      if (reader2[10].ToString() != null && reader2[10].ToString() != "") 
      lbl19_giftcard.Text = reader2[10].ToString()+GiftCard_price; 


      totalcost = Convert.ToDouble(lbl8_fruit.Text) + Convert.ToDouble(lbl10_drink.Text); 
      lblTotalCost.Text = totalcost.ToString(); 


     } 
    } 
} 
+0

오류가 발생하는 줄은 무엇입니까? 게시 된 코드의 해당 줄을 지적 할 수 있습니까? – Sami

+0

이 줄에 오류가 있습니다. "totalcost = Convert.ToDouble (lbl8_fruit.Text) + Convert.ToDouble (lbl10_drink.Text);" – meysam

+0

업데이트 해 주셔서 감사합니다. 내 대답을 확인하십시오 – Sami

답변

1

확인!

+0

내 문제가 해결되었습니다 – meysam

+0

좋은 소리. 이 경우에 투표하십시오. 또한 대답으로 받아 들일 것을 잊지 마라. – Sami

0

텍스트에 포함 된 것으로 보입니다. 이 도움이

double fruit; 
double drink; 

if (Double.TryParse(lbl8_fruit.Text.Text.Trim(), out fruit) && Double.TryParse(lbl10_drink.Text.Text.Trim(), out drink)) 
{ 
     totalcost = fruit + drink; 
} 
else 
{ 
//not valid numeric values 
} 

희망 : 같은 텍스트 상자에 유효한 숫자 값에 대한

totalcost = Convert.ToDouble(lbl8_fruit.Text.Trim()) + Convert.ToDouble(lbl10_drink.Text.Trim()) 
+0

트림과 함께 공간을 제거하지만 다시 그 오류가 있습니다. 내가 맞습니까? 진정한 방식으로 총 가격을 보여주는거야? – meysam

+0

많은 감사를드립니다! – Sami

관련 문제