简体   繁体   中英

SQL Server 2008 dbms and Visual Studio

I need to add one more column in gridview as difference of Supplier_Quantity - Store_quantity and that difference should be stored in new column after the supplier_Quantity .

But, when I click on Calculate button column what should I do then ?

I tried the following query:

select 
    Product_Name, Supplier_Quantity, Store_Quantity,
    'DIFFRENCE' = Supplier_Quantity - Store_Quantity 
from 
    relatesupp

but it shows in sql only and as soon as I use it in Visual Studio it doesn't show in gridview.

You can place the code in the button and get the desired result in the 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;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM