在选择上减少库存量 [英] reducing stock by one on selection
本文介绍了在选择上减少库存量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
嘿伙计我接力卡住,我有一个数据网格显示一些数据然后我有一个选择按钮激活你点击按钮,标题选择打印在下面。
问题是我现在想要在选择选择后选择运行更新查询后减少股票购买一个。我遇到了一些问题
我的代码
Hey guys I am relay rather stuck, I have a data-grid showing some data then I have a on select button active you click on the button and the titles selection is printed bellow.
problem is I now want the on select selection chose to run a update query after to reduce the stock buy one. I am having some problems with this
My Code
protected void Button2_Click(object sender, EventArgs e)
{
var myquery = string.Format("UPDATE DVD SET Stock = Stock - 1");
da.InsertCommand = new OleDbCommand("INSERT INTO DVD (Stock) VALUES (@MessageLabel)", conn);
{
da.InsertCommand.Parameters.AddWithValue("@Stock", MessageLabel.Text);
conn.Open();
da.InsertCommand.ExecuteNonQuery();
using (OleDbCommand cmd = new OleDbCommand(myquery, conn))
cmd.ExecuteNonQuery();
conn.Close();
conn.Dispose();
}
}
以前的精选活动代码
Previous code for select event
public void Latest_DVD()
{
{
using (OleDbDataAdapter dataquer = new OleDbDataAdapter("SELECT Title,Category,Director,Stock,Year FROM DVD ", conn))
{
dataquer.Fill(dt);
}
}
DG_Latest.ShowHeader = true;
DG_Latest.DataSource = dt;
DG_Latest.DataBind();
conn.Close();
conn.Dispose();
}
protected void Latest_DVD_SelectedIndexChanged(Object sender, EventArgs e)
{
GridViewRow row = DG_Latest.SelectedRow;
MessageLabel.Text = "You selected to rent " + row.Cells[1].Text + ".";
}
推荐答案
写一个合适的数据层。请勿将其丢弃在使用区域中。编写一个进行一次dB更新并调用它的方法。你的两个SQL语句没有意义。如果stock是一个文本值的列,那么它不是你可以减去的数字,除非你的表只有一行,否则你的SQL也不值得。
Write a proper data layer. Don't dispose in a using block. Write a method that does one dB update and call it. Your two SQL statements don't make sense. If stock is a column you at to a text value, it's not a number you can subtract, nor would your SQL be worth anything unless your table has only one row.
这篇关于在选择上减少库存量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文