Click here to Skip to main content
12,948,130 members (89,939 online)
Rate this:
Please Sign up or sign in to vote.
See more:
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 8: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
Top Experts
Last 24hrsThis month
OriginalGriff 5,344
CHill60 3,275
Maciej Los 2,703
Jochen Arndt 1,935
ppolymorphe 1,795

Advertise | Privacy | Mobile
Web02 | 2.8.170524.1 | Last Updated 16 Sep 2012
Copyright © CodeProject, 1999-2017
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