Click here to Skip to main content
Rate this: bad
Please Sign up or sign in to vote.
See more: C# .NET
Hey People ,m new nocturnal bug in and i was trying to make a billing form for shops,retaurents etc etc(for learning),I could successfuly connect grid with the SQL DB.
Since there are different entries in the Grid ( S.N,Particulars,Quantity and price) and the place where the Total amount is shown (Text boX),with the Button click event(Total Button) is outside the Grid so,Can anybody suggest me how to bring the total Price of the particulars into the textbox which is outside the grid, after clicking the Total Button.
Posted 16-Sep-12 9:33am
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Write code that works out hte total and puts it in to the textbox. You should ideally store your values in the DB and get your total from there, but you can do it by accessing values in your grid if you want.
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

You can get the sum directly from the database using sql query:
SELECT SUM(field_name) FROM table_name
or you can do it in code-behind file as:
double amount = 0;
        for (int i = 0; i < dataGridView1.Rows.Count; i++)
            amount += Convert.ToDouble(dataGridView1.Rows[i].Cells[cell_index].Value);

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

  Print Answers RSS
0 OriginalGriff 315
1 Jochen Arndt 190
2 DamithSL 125
3 PIEBALDconsult 110
4 Garth J Lancaster 90
0 OriginalGriff 5,790
1 DamithSL 4,601
2 Maciej Los 4,012
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,195

Advertise | Privacy | Mobile
Web04 | 2.8.141220.1 | Last Updated 16 Sep 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100