Click here to Skip to main content
11,429,382 members (65,404 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# .NET
Hey People ,m new nocturnal bug in C#.net 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
good
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.
  Permalink  
Rate this: bad
good
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);
        }
  Permalink  

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



Advertise | Privacy | Mobile
Web04 | 2.8.150428.2 | Last Updated 16 Sep 2012
Copyright © CodeProject, 1999-2015
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