我想根据以前的库存状态更新我的库存数量。我需要根据向内或向外交易通过添加或减少它来更新以前的数据。我没有在 currentstock 表中更新库存。//这是问题部分的开始
SqlCommand cmd2 = new SqlCommand("select stock from currentstock where itemname=@a", con);
con.Open();
int x=0;
cmd2.Parameters.AddWithValue("@a",comboBox2.SelectedItem.ToString());
SqlDataReader dr = cmd2.ExecuteReader();
if (dr.Read())
{
x = dr.GetInt16(2);
}
if (radioButton1.Checked == true)
{
x = x + Convert.ToInt16(textBox1.Text);
}
else if (radioButton2.Checked == true)
{
x = x - Convert.ToInt16(textBox2.Text);
}
con.Close();
SqlCommand cmd1 = new SqlCommand("update currentstock set stock=@a where itemname=@b",con);
con.Open();
cmd1.Parameters.AddWithValue("@a", x);
cmd1.Parameters.AddWithValue("@b", comboBox2.SelectedItem.ToString());
cmd1.ExecuteNonQuery();
con.Close();
// 这是问题段的结尾