C#sql 更新 表1的销售总数= 表2相同ID的总和
int index = listBox20.SelectedIndex;
listBox20.SelectedIndex = index + 1;//下移
SqlConnection conn = new SqlConnection(label1.Text);
conn.Open();
string sql = "UPDATE 盘点表 SET 销售数 = (select SUM(CAST(销售数量 AS INT)) from 销售记录 where 药品ID = "+listBox20.Text +") from 盘点表 where 药品ID = "+listBox20.Text ;
SqlCommand com = new SqlCommand(sql, conn);
com.ExecuteNonQuery();
int count = com.ExecuteNonQuery();
if (count > 0)
{
}
else
{
}
conn.Close();