【发布时间】:2013-11-26 22:58:51
【问题描述】:
此查询查找库存可用性,并且标签打印输出看起来像..
{
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,则弹出一条消息或警报,提示选择缺货。
【问题讨论】:
-
更新问题以包含更多代码。
-
您需要在应用减量之前从数据库中读取数据,因为查询在完全不同的范围(数据库引擎)上运行
-
好的 @Leon 所以先运行查询?
-
string selection_price = DdPetPist.SelectedValue;和string selection_stock = DdPetPist.SelectedValue;看起来完全一样。你不是在这里覆盖你的价值观吗? -
是的,您不能将数据库中的事件直接冒泡到您的应用程序中。您需要该数据来决定是否显示消息框。
标签: c# mysql messagebox