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