Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/61.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如果查询=0,则显示消息框_C#_Mysql_Messagebox - Fatal编程技术网

C# 如果查询=0,则显示消息框

C# 如果查询=0,则显示消息框,c#,mysql,messagebox,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 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
is=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,则会弹出一条消息或警报,说selection out stock

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

不确定这是否回答了您的问题

更新了问题以包含更多代码。在应用减量之前,您需要从数据库中读取数据,因为查询在完全不同的作用域(DB engine)上运行Ok@Leon,所以先运行查询?
字符串选择\u price=DdPetPist.SelectedValue
字符串选择\u stock=DdPetPist.SelectedValue看起来完全一样。您不是在这里覆盖了您的值吗?是的,您不能将事件从数据库直接冒泡到您的应用程序中。您需要这些数据来决定是否显示消息框。-1。您的答案显示很少的解释或努力,并且您的代码格式不正确。它应该是
MessageBox.Show(“这里的字符串”)。我现在已经编辑了我的-1,至少你已经编辑过了。仍然是错的。应该是
.Show