Click here to Skip to main content
15,885,868 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi all!

I have a crystal report that displays data from datatable as its data source.
One of these columns in the datatable may contain Zero value.
I want to check to that value; if it is Zero, Delete that row for datatable and crystal report.

I have tried this , but still Zeros appear:

C#
for(int m=0; m < mona.Rows.Count ; m++)
       {
       foreach(DataRow data in mona.Rows)
       {
          double Balance = double.Parse(data["Balance"].ToString());
          if (Balance == 0)
          {
              //data.Delete();
              dDebt.Rows[m].Delete();
          }
          else if (Balance > 0)
          {
              dCred.Rows[m].Delete();
          //  dDebt = AddedNewColumnDebt(mona);
          }
      }
       }


Any help, please.

Thanks
Posted
Updated 18-Apr-11 1:16am
v2
Comments
Ankur\m/ 18-Apr-11 7:22am    
Why don't you filter it at database level itself?
Ashishmau 18-Apr-11 7:29am    
Agree with ankur
moon2011 18-Apr-11 7:38am    
thanks for you both, but i know that we can do it in the database, but i need Zeros in another webform, so i have to handle it in the code.
thanks again

Try this one.

C#
DataTable updatedDataTable = new DataTable();
for (int m = 0; m < mona.Rows.Count; m++) {
        foreach (DataRow data in mona.Rows) {
            double Balance = double.Parse(data["Balance"].ToString());
            if (Balance > 0) {
                updatedDataTable.Rows.Add(data);
            }
        }
}


use updatedDataTable as your new DataTable to display the filtered rows.
 
Share this answer
 
Comments
moon2011 18-Apr-11 8:08am    
an exception appears telling "This row already belongs to another table."??????
i didn't understand it???
help???
Change this
dDebt.Rows[m].Delete();

to
dDebt.Rows.RemoveAt(m);
 
Share this answer
 
Comments
Henry Minute 18-Apr-11 7:35am    
This will not help at all.
moon2011 18-Apr-11 7:41am    
it appears an exception to me

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900