SQL 服务器 2008 数据库管理系统和 Visual Studio
SQL Server 2008 dbms and Visual Studio
我需要在 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 中显示。
您可以将代码放在按钮中,并在数据网格视图中获得所需的结果:
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;
我需要在 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 中显示。
您可以将代码放在按钮中,并在数据网格视图中获得所需的结果:
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;