SQL Server 2008 dbms和Visual Studio

时间:2015-08-01 06:28:49

标签: sql sql-server sql-server-2008 gridview

我需要在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中显示。

1 个答案:

答案 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;