0

This query looks for the Stock availability and the label print out looks like..

{
   string selection_price = DdPetPist.SelectedValue;
   string selection_stock = DdPetPist.SelectedValue;
   string petPrice = string.Empty;
   string available = string.Empty;
   {
      MySqlCommand cd_price = new MySqlCommand(String.Format("SELECT Price FROM Animals WHERE Specie ='{1}' and Country ='{0}'", ddlcountry.SelectedItem.ToString().Trim(), selection_price), cs);
      MySqlCommand cd_available = new MySqlCommand(String.Format("SELECT Stock FROM Animals WHERE Specie ='{1}' and Country ='{0}'", ddlcountry.SelectedItem.ToString().Trim(), selection_stock), cs);

      cs.Open();
      petPrice = Convert.ToString(cd_price.ExecuteScalar());
      available = Convert.ToString(cd_available.ExecuteScalar());
      cs.Close();
   }
   PetPrice.Text = String.Format("Minimum Donation For A {0}  Is £{1}.", selection_price, petPrice);
   Availble.Text = String.Format("{0}'s Avalible {1} In Your Country.", selection_stock, available);
}

How can I have a message box pop up if stock is = to 0 ?

UPDATE

OK so I will explain what I am trying to do

I have an UPDATE query that will decrement the stock by 1 every time a button is clicked. The query is below:

var myquery = string.Format("UPDATE Animals SET Stock = Stock - 1 WHERE Specie ='{1}'
and Country ='{0}' and Stock >0", ddlcountry.SelectedItem.ToString().Trim(), 
selection_price);

Now what I want is if the stock is = to 0 a message or alert to pop up saying selection out of stock.

Brian
  • 5,069
  • 7
  • 37
  • 47
Beep
  • 2,737
  • 7
  • 36
  • 85
  • Updated question to include more code. – Beep Nov 26 '13 at 23:45
  • 2
    you'll need to read from the database prior to applying the decrement, as the query runs on a completely different scope (DB engine) – planestepper Nov 26 '13 at 23:54
  • Ok @Leon so run query for this first? – Beep Nov 26 '13 at 23:58
  • `string selection_price = DdPetPist.SelectedValue;` and `string selection_stock = DdPetPist.SelectedValue;` look to be the exact same. Aren't you overwriting your values here? – Brian Nov 26 '13 at 23:58
  • hmm gives a error if I do not have both as I use the two different strings at the bottom but I will look into it, thanks for pointing it out – Beep Nov 27 '13 at 00:02
  • 1
    yes, you can't bubble events from the db directly into your app. you need that data to decide whether to display the message box. – planestepper Nov 27 '13 at 12:44

1 Answers1

1
if(available == 0)
{
   Messagebox.show("stock is equal to zero");
}

not sure if that answers your question

Brian
  • 5,069
  • 7
  • 37
  • 47
Theo Anderson
  • 163
  • 1
  • 1
  • 5