如果query = = 0,则显示消息框

时间:2013-11-26 22:58:52

标签: c# mysql messagebox

此查询查找库存可用性,打印出的标签看起来像..

{
   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);
}

如果stock = = 0,我怎么能弹出一个消息框?

更新

好的,我会解释我要做的事情

我有一个UPDATE查询,每次点击一个按钮,它会将股票减1。查询如下:

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);

现在我想要的是,如果stock = 0,则会弹出一条消息或警告,说明选择缺货。

1 个答案:

答案 0 :(得分:1)

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

不确定是否能回答你的问题