views:

68

answers:

3

if i try to add int value into array with string length Whole data is "0" why? and how can solve it?

  for (int j = 0; j < dTable.Columns.Count; j++)
                for (int i = 0; i < dTable.Rows.Count; i++)
                {

                    mycounter[i] = dTable.Rows[i][j].ToString().Length;
                }

it is not related to mycounter because:

  string test = "";
           foreach(DataColumn dc in dTable.Columns)
                for (int i = 0; i < dTable.Rows.Count; i++)
                {
                   // MessageBox.Show(dTable.Rows[i][dc].ToString());
                    test = dTable.Rows[i][dc].ToString().Length.ToString();
                }
+2  A: 

In mycounter[] you will have only values from last column of table. May be last column contains empty strings?

Orsol
A: 

Unless you are redeclaring mycounter between the for loops, you are overwriting mycounter[i] for each column 0 to Columns.Count-1 until the last column.

Did you want to sum the lengths? Or did you maybe want a 2-dimensional array for mycounter?

Andy_Vulhop
i updated my question:)
Phsika
+1  A: 

In addition to what @Orsol said, the fact that you're looping through both dimensions seems to indicate that you want a total length for each row, and therefore,

mycounter[i] = dTable.Rows[i][j].ToString().Length; 

should be changed to

mycounter[i] += dTable.Rows[i][j].ToString().Length; 

It is also possible that the ToString() method is returning empty strings. Perhaps you're looking for a Text property?

Jeffrey L Whitledge