0
Reply

make the column value null if it is repeating in a datatable

mohammed shamsheer

mohammed shamsheer

Nov 22 2013 7:12 AM
1.1k
 public DataSet GenerateReport()
    {
        
        //Loading Dataset
        LoadTrailBalance();
        DataSet ds = new DataSet();
        ds = LoadTrailBalance();

        //Intialization
        double TotalDebit, TotalCredit,TotalDrCr;
        TotalDebit = TotalCredit =TotalDrCr= 0;
        double Debit = 0; double Credit = 0; double subtotal=0;
        string str="";
        ds.Tables[0].Compute("Sum(Convert.ToInt32(Debit))", "AccGroupName='Accounts'");
        //find the result debit or credit and put it on respective column debit or credit by adding new row
//Calculating total of debit and credit 
        for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
        {
            TotalDebit += PolosysFrameWork.General.Val(ds.Tables[0].Rows[i]["Debit"]);
            TotalCredit += PolosysFrameWork.General.Val(ds.Tables[0].Rows[i]["Credit"]);

        }
        TotalDrCr = TotalDebit - TotalCredit;
        DataRow row = ds.Tables[0].NewRow();
        row[0] = "Total";

        //row[2] = TotalDebit;
        //row[3] = TotalCredit;
       
        if (TotalDrCr > 0)
        {
           row[2]  = Math.Abs(TotalDrCr) + "Dr";
           ds.Tables[0].Rows.Add(row);
        }
        else
        {
            row[3] = Math.Abs(TotalDrCr) + "Cr";
            ds.Tables[0].Rows.Add(row);
        }
        //ds.Tables[0].Rows[ds.Tables[0].Rows.Count]["Debit"]=TotalDrCr > 0 ? (Math.Abs(TotalDrCr) + "Dr") : (Math.Abs(TotalDrCr) + "Cr");
        int RowCount;
           RowCount = ds.Tables[0].Rows.Count;
        
        
          
               //ds.Tables[0].Compute("Sum(Debit)", "AccGroupName='Accounts'");

        //Creating rows between unIdentical LedgerGroup and Calculating SubTotal

               for (int i = 1; i < ds.Tables[0].Rows.Count; i++)
               {
                   string LedgerGroup = ds.Tables[0].Rows[i]["AccGroupName"].ToString();
                   LedgerGroup = ds.Tables[0].Rows[i - 1]["AccGroupName"].ToString();
                   Debit = Debit + PolosysFrameWork.General.Val(ds.Tables[0].Rows[i - 1]["Debit"]);
                   Credit = Credit + PolosysFrameWork.General.Val(ds.Tables[0].Rows[i - 1]["Credit"]);
                  

                   if (ds.Tables[0].Rows[i]["AccGroupName"].ToString() != LedgerGroup)
                   {
                       DR = ds.Tables[0].NewRow();
                     

                       ds.Tables[0].Rows.InsertAt(DR, i);
                       ds.Tables[0].AcceptChanges();
                       ds.Tables[0].Rows[i]["AccGroupName"] = "SubTotal";
                       subtotal = Debit - Credit;
                       if (subtotal < 0)
                       {
                           subtotal = Math.Abs(subtotal);
                           ds.Tables[0].Rows[i]["Credit"] = subtotal + "Cr";
                       }
                       else
                       {
                           subtotal = Math.Abs(subtotal);
                           ds.Tables[0].Rows[i]["Debit"] = subtotal + "Dr";
                       }

                       Debit = 0;
                       Credit = 0;

                    
                       i = i + 1;
                       if (i != ds.Tables[0].Rows.Count)
                       {
                           ds.Tables[0].Rows[i + 1]["AccGroupName"] = "";
                       }
                   }
               }
        return ds;
    }

i want to get the data in the format : 

AccG  Ledger Debit Credit

my        1        1        1
my        2        2        2
my        3        3        3

S        2        2        2
s        2        2        2

Required Format :

my        1        1        1
             2        2        2
              3        2        2
s             2        2        2
               2        2        2