我需要在gridview中再添加一列作为Supplier_Quantity - Store_quantity
的差异,并且差异应该存储在supplier_Quantity
之后的新列中。
但是,当我点击Calculate
按钮列时,我该怎么做?
我尝试了以下查询:
select
Product_Name, Supplier_Quantity, Store_Quantity,
'DIFFRENCE' = Supplier_Quantity - Store_Quantity
from
relatesupp
但它只在sql中显示,一旦我在Visual Studio中使用它,它就不会在gridview中显示。
答案 0 :(得分:1)
您可以将代码放在按钮中,并在datagridview中获得所需的结果:
string sQuery = "select Product_Name, Supplier_Quantity, Store_Quantity, Supplier_Quantity - Store_Quantity As 'DIFFRENCE' "
+"from relatesupp";
SqlCommand cmd = new SqlCommand(sQuery, con);
SqlDataReader sdr = cmd.ExecuteReader();
DataTable dt = new DataTable();
dt.Load(sdr);
dataGridView1 .DataSource = dt;