We help IT Professionals succeed at work.
Get Started

C# Help With IF Value = 0 Do Something

jasont09
jasont09 asked
on
331 Views
Last Modified: 2013-12-16
Now I know the Title sounds like I should know the answer. But here is my problem and I dont know how to code it

I am fetching an xml response, Most of the time DS.Tables["Price"] is returned in the response. But if its not returned my update fails.

DS.Tables["Price"] is only actually returned if the value = 1 in DS.Tables["Offers"]
Row["TotalOffers"]


if the value = 0  my script crashes.

please can someone explain / show me how I can change my code below to check for it and put an else statement in if the value  = 0


for (int i = 0; i < DS.Tables["Price"].Rows.Count; i++)
          {
              string s6 = DS.Tables["Price"].Rows[i]["FormattedPrice"].ToString().Replace("£", "").Replace(",", "");
              string s7 = "1";// DS.Tables["Price"].Rows[i]["OfferListing_Id"].ToString();
              string n70 = (s11); 
              string sqld = string.Format("update dbo.price set Price ='"+ s6 +"' where productid='" + n70 +"'");
             

              SqlConnection con = new SqlConnection();
              con.ConnectionString = "Data Source=xxx;Initial Catalog=xxx;User Id=xxx; Password=xxx";
              SqlCommand cmd = new SqlCommand();
              cmd.Connection = con;
              cmd.Connection.Open();
              cmd.CommandText = sqld;
              cmd.ExecuteNonQuery();
              cmd.Connection.Close();

          }

Open in new window

Comment
Watch Question
Commented:
This problem has been solved!
Unlock 1 Answer and 7 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE