add or subtract Datagrid Dataset?

  • Thread starter Thread starter Michael Schindler
  • Start date Start date
M

Michael Schindler

ROW Accountnr Amount
1 1001 12.00
2 1001 -12.00
3 1002 40.00
4 1002 -12.00
5 1002 -28.00
6 1003 30.00
7 1003 -30.00
8 ???? ......


Hello NG

I have a datagrid whit a dataset.
If the user down into the datagrid whit the mouse or the curser
i set in the new line (Row) the new accountnr manually.
datagrid(x,y) = accountnr

The problem is the amount column.
I must check the when the same accountnr is 0.
For example accountnr 1002 (40.00 - 12.00 -28.00) = 0

The problem is when the amount = 0
Accountnr = Accountnr +1
and my problem is to find out when the amount is 0.


It is possible i can add or subtract from my dataset whitout a new database
connection?

If yes ..hmm...have you a small few code for me that i can see as I could
realize that?

Thanks Michael

PS: I work whit C# Windows Application
 
Hi Michael,

Your email is not very clear ,what I understand from it is that you want to
know which accounts have amount 0
if that is the case then is better not using the datagrid but the source
dataset

What first come into my mind is using a hashtable, being the key the
accountnr and the value the current amount, what you do is more or less like
this:
Hashtable table = new Hashtable();
foreach( DataRow row in dataset.Tables["table"].Rows )
if ( table.Contains( row["accountnr"] )
table[ row["accountnr"] ] = (double) table[ row["accountnr"] ] +
row["Amount"] ;
else
table.Add ( row["accountnr"], row["Amount"] );

then later you can iterate in the table searching for those with amount 0.

If this is not what you want post back, also remember that the code above
is not tested and may not be the best solution.

Hope this help,
 
Hello Ignacio

Thanks for your answer.

But i dont understand what this code to do.
If you have time please send me a few description thank you.

My problem is only the in the correct time the Accountnr to increase.

Present to you: The user give line vor line manually different datas into my
datagrid.
And this function is a work easement if the user go manually to line(row)
[8] the programm must check if Amount = 0
If Yes = the Accountnr +1
If No = the Accountnr variabel remains the same
that's all.
Hashtable table = new Hashtable();
foreach( DataRow row in dataset.Tables["table"].Rows )
if ( table.Contains( row["accountnr"] )
table[ row["accountnr"] ] = (double) table[ row["accountnr"] ] +
row["Amount"] ;
else
table.Add ( row["accountnr"], row["Amount"] );

then later you can iterate in the table searching for those with amount 0.

If this is not what you want post back, also remember that the code above
is not tested and may not be the best solution.

Hope this help,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

Michael Schindler said:
ROW Accountnr Amount
1 1001 12.00
2 1001 -12.00
3 1002 40.00
4 1002 -12.00
5 1002 -28.00
6 1003 30.00
7 1003 -30.00
8 ???? ......


Hello NG

I have a datagrid whit a dataset.
If the user down into the datagrid whit the mouse or the curser
i set in the new line (Row) the new accountnr manually.
datagrid(x,y) = accountnr

The problem is the amount column.
I must check the when the same accountnr is 0.
For example accountnr 1002 (40.00 - 12.00 -28.00) = 0

The problem is when the amount = 0
Accountnr = Accountnr +1
and my problem is to find out when the amount is 0.


It is possible i can add or subtract from my dataset whitout a new database
connection?

If yes ..hmm...have you a small few code for me that i can see as I could
realize that?

Thanks Michael

PS: I work whit C# Windows Application
 
Hi Michael,

Well I think that I do understand you now :) , your first post was not clear
enough ,
the code I gave you is not useful for this.

What you can do is keep a variable in the form where the grid is located
that keeps the current value , when the user add a row you update this
variable, if the value is 0 then you create a new account number.



I hope this help,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

Michael Schindler said:
Hello Ignacio

Thanks for your answer.

But i dont understand what this code to do.
If you have time please send me a few description thank you.

My problem is only the in the correct time the Accountnr to increase.

Present to you: The user give line vor line manually different datas into my
datagrid.
And this function is a work easement if the user go manually to line(row)
[8] the programm must check if Amount = 0
If Yes = the Accountnr +1
If No = the Accountnr variabel remains the same
that's all.
Hashtable table = new Hashtable();
foreach( DataRow row in dataset.Tables["table"].Rows )
if ( table.Contains( row["accountnr"] )
table[ row["accountnr"] ] = (double) table[ row["accountnr"] ] +
row["Amount"] ;
else
table.Add ( row["accountnr"], row["Amount"] );

then later you can iterate in the table searching for those with amount 0.

If this is not what you want post back, also remember that the code above
is not tested and may not be the best solution.

Hope this help,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

ROW Accountnr Amount
1 1001 12.00
2 1001 -12.00
3 1002 40.00
4 1002 -12.00
5 1002 -28.00
6 1003 30.00
7 1003 -30.00
8 ???? ......


Hello NG

I have a datagrid whit a dataset.
If the user down into the datagrid whit the mouse or the curser
i set in the new line (Row) the new accountnr manually.
datagrid(x,y) = accountnr

The problem is the amount column.
I must check the when the same accountnr is 0.
For example accountnr 1002 (40.00 - 12.00 -28.00) = 0

The problem is when the amount = 0
Accountnr = Accountnr +1
and my problem is to find out when the amount is 0.


It is possible i can add or subtract from my dataset whitout a new database
connection?

If yes ..hmm...have you a small few code for me that i can see as I could
realize that?

Thanks Michael

PS: I work whit C# Windows Application
 
Back
Top