Sums and Totals

B

BD

Writing C# database app with VS 2005, I need to have a text box that
computes and displays only a total from a datagridview computed totals
column. I did this before with VBA with the following:

=nz(WorkOrderMaterial.Form![Total Parts])

How would I do this with C#. I have added the computed column in the
datagridview and I have been able to sum all totals in the text box
(every record in that table), but I want to sum the totals that are
only associated with the main record.

Thanks in advance.

Brian
 
G

Guest

I assume your "main record" is more like a filtered version of the table you
are deriving your data from? If that is the case you can write code to get
the column you are interested in and then go through it's records and compute
the sum. This way you can handle any special cases you might want to handle.

Adrian.
 
B

BD

I assume your "main record" is more like a filtered version of the table you
are deriving your data from? If that is the case you can write code to get
the column you are interested in and then go through it's records and compute
the sum. This way you can handle any special cases you might want to handle.

Adrian.
--
[Please mark my answer if it was helpful to you]



BD said:
Writing C# database app with VS 2005, I need to have a text box that
computes and displays only a total from a datagridview computed totals
column. I did this before with VBA with the following:
=nz(WorkOrderMaterial.Form![Total Parts])
How would I do this with C#. I have added the computed column in the
datagridview and I have been able to sum all totals in the text box
(every record in that table), but I want to sum the totals that are
only associated with the main record.
Thanks in advance.
Brian- Hide quoted text -

- Show quoted text -

I apoligize for the mutiple posts but when I posted the question, it
didn't show up. This has happened before when I post and acts like my
post gets lost. I waited quite some time after I posted to issue
another one. Any way, I thought about adding a query to my dataset to
compute this but am unsure as to how to word my query.
 
G

Guest

You can use the SUM function in SQL to produce the totals column in your
query. Check out the links below on how to use this function:

http://www.techonthenet.com/sql/sum.php
http://www.w3schools.com/sql/func_sum.asp

Your query will then populate a table in your dataset with the help of the
data adapter you have set up. This table is the table that you are using for
your datagrid.

Adrian.
--
[Please mark my answer if it was helpful to you]




BD said:
I assume your "main record" is more like a filtered version of the table you
are deriving your data from? If that is the case you can write code to get
the column you are interested in and then go through it's records and compute
the sum. This way you can handle any special cases you might want to handle.

Adrian.
--
[Please mark my answer if it was helpful to you]



BD said:
Writing C# database app with VS 2005, I need to have a text box that
computes and displays only a total from a datagridview computed totals
column. I did this before with VBA with the following:
=nz(WorkOrderMaterial.Form![Total Parts])
How would I do this with C#. I have added the computed column in the
datagridview and I have been able to sum all totals in the text box
(every record in that table), but I want to sum the totals that are
only associated with the main record.
Thanks in advance.
Brian- Hide quoted text -

- Show quoted text -

I apoligize for the mutiple posts but when I posted the question, it
didn't show up. This has happened before when I post and acts like my
post gets lost. I waited quite some time after I posted to issue
another one. Any way, I thought about adding a query to my dataset to
compute this but am unsure as to how to word my query.
 
B

BD

You can use the SUM function in SQL to produce the totals column in your
query. Check out the links below on how to use this function:

http://www.techonthenet.com/sql/sum.phphttp://www.w3schools.com/sql/func_sum.asp

Your query will then populate a table in your dataset with the help of the
data adapter you have set up. This table is the table that you are using for
your datagrid.

Adrian.
--
[Please mark my answer if it was helpful to you]



BD said:
I assume your "main record" is more like a filtered version of the table you
are deriving your data from? If that is the case you can write code to get
the column you are interested in and then go through it's records and compute
the sum. This way you can handle any special cases you might want to handle.
Adrian.
--
[Please mark my answer if it was helpful to you]
:
Writing C# database app with VS 2005, I need to have a text box that
computes and displays only a total from a datagridview computed totals
column. I did this before with VBA with the following:
=nz(WorkOrderMaterial.Form![Total Parts])
How would I do this with C#. I have added the computed column in the
datagridview and I have been able to sum all totals in the text box
(every record in that table), but I want to sum the totals that are
only associated with the main record.
Thanks in advance.
Brian- Hide quoted text -
- Show quoted text -
I apoligize for the mutiple posts but when I posted the question, it
didn't show up. This has happened before when I post and acts like my
post gets lost. I waited quite some time after I posted to issue
another one. Any way, I thought about adding a query to my dataset to
compute this but am unsure as to how to word my query.- Hide quoted text -

- Show quoted text -

Thank you for your response, I have found many articles about doing
this in a datagrid but a datagridview.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top