dataReader + For Loop


my database

debtor             opening           debit               credit

james                   100                  20                      0

james                   100                  10                      0

james                  100                    0                       5

mr. j                      50                  0                        10

 

i want calculate balance of debtor. formula: new opening: opening+ debit - credit . example, james: 125 = 100 + 20 + 10 - 5

result

customer       opening

james               125

mr. j                  40

this code working with, keep failed me =(

i wanted use loop inside while read, dun know keyword find datareader's rows. 

 

 

string connectionstring = "provider=microsoft.jet.oledb.4.0;data source=" + this.lbldatabasedir.text + ";jet oledb:database password=password";  system.data.oledb.oledbconnection conndebtor = new system.data.oledb.oledbconnection(connectionstring); system.data.oledb.oledbcommand cmddebtor = conndebtor.createcommand();  cmddebtor.commandtext = "select debtor.debtorcode, debtor.opening, transaction.debit, transaction.credit [debtor] inner join [transaction] on debtor.debtorcode = transaction.accountno";             cmddebtor.connection.open();  system.data.oledb.oledbdatareader drdebtor = cmddebtor.executereader();  decimal opening = 0; decimal debit = 0; decimal credit = 0;  while (drdebtor.read())       {        opening = convert.todecimal(drdebtor["opening"].tostring());        debit = convert.todecimal(drdebtor["debit"].tostring());        credit = convert.todecimal(drdebtor["credit"].tostring());         this.lbltotal.text = convert.tostring(opening - debit + credit);       } cmddebtor.connection.close(); 


 


instead of using datareader,try using dataadapter fill datatabls. datatable contain 3 rows, u can calculate amount. if want code post it


Visual Studio Languages  ,  .NET Framework  >  Visual C#



Comments

Popular posts from this blog

Azure DocumentDB Owner resource does not exist

job syspolicy_purge_history job fail in sqlserver 2008

Trying to register with public marketplace error with 'Get-AzureStackStampInformation'