Click here to Skip to main content
15,355,608 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
A B C D E F  TOTAL
1 2 3 4 5 6  ....


How I do this????
and make last column current time

DataGridview Fill by from Access database...
Hare is My code:

C#
cn.Open();
OleDbCommand cmd = new OleDbCommand();
cmd.Connection = cn;
cmd.CommandText = "SELECT CounterSale.Pro_Batch AS BatchNo, CounterSale.Pro_name As Medicine, Sum(CounterSale.cun_qty) AS SaleQty, Sum(CounterSale.cun_totalAmt) AS TotalPrice, PurchaseBatch.Bth_qty As Batch_Qty, PurchaseBatch.Bth_Pur_rate As PurchaseRate, PurchaseBatch.Bth_sale_rate As SaleRate FROM SaleVouchers INNER JOIN (PurchaseBatch RIGHT JOIN CounterSale ON PurchaseBatch.Batch_no = CounterSale.Pro_Batch) ON SaleVouchers.Sal_voucher = CounterSale.Sal_voucher where  sal_voucher_date between @RechargeDateStart AND @RechargeDateEnd GROUP BY CounterSale.Pro_Batch, CounterSale.Pro_name, PurchaseBatch.Bth_qty, PurchaseBatch.Bth_Pur_rate, PurchaseBatch.Bth_sale_rate;";
cmd.Parameters.AddWithValue("@RechargeDateStart", dateTimePicker1.Value.Date);
cmd.Parameters.AddWithValue("@RechargeDateEnd", dateTimePicker2.Value.Date);
cmd.CommandType = CommandType.Text;
//        dataGridView2.AutoGenerateColumns = true;
DataSet ds = new DataSet();

OleDbDataAdapter adapter = new OleDbDataAdapter();
adapter.SelectCommand = cmd;
adapter.Fill(ds);
dataGridView2.DataSource = ds.Tables[0];
cn.Close();
Posted
Updated 2-Mar-13 3:55am
v2

1 solution

Try to use query like this::
SQL
SELECT BatchNo, Medicine, SaleQty, TotalPrice, Batch_Qty, PurchaseRate, SaleRate, (A + B + C + N) AS Total, Now() AS [CurrentTime]
FROM( 
SELECT CounterSale.Pro_Batch AS BatchNo, CounterSale.Pro_name As Medicine, Sum(CounterSale.cun_qty) AS SaleQty, Sum(CounterSale.cun_totalAmt) AS TotalPrice, PurchaseBatch.Bth_qty As Batch_Qty, PurchaseBatch.Bth_Pur_rate As PurchaseRate, PurchaseBatch.Bth_sale_rate As SaleRate
FROM SaleVouchers INNER JOIN (PurchaseBatch RIGHT JOIN CounterSale ON PurchaseBatch.Batch_no = CounterSale.Pro_Batch) ON SaleVouchers.Sal_voucher = CounterSale.Sal_voucher
WHERE sal_voucher_date between @RechargeDateStart AND @RechargeDateEnd GROUP BY CounterSale.Pro_Batch, CounterSale.Pro_name, PurchaseBatch.Bth_qty, PurchaseBatch.Bth_Pur_rate, PurchaseBatch.Bth_sale_rate)
   
Comments
kashifjaat 2-Mar-13 18:10pm
   
I want sum last two column of datagrid view in third coloumn????
Maciej Los 2-Mar-13 19:31pm
   
So..., where is a problem? Replace SELECT statement in above example with:
SELECT BatchNo, Medicine, SaleQty, TotalPrice, Batch_Qty, PurchaseRate, SaleRate, (PurchaseRate + SaleRate) AS Total
FROM (...)

then bind data ;)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900