Click here to Skip to main content
15,889,116 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have 45 rows and 45 columns in data table.
* validate third column,(12 Th row to 39 row)in this in between field have at least one value(my requirement is the value is '1')
* if 3rd column 19 row value is '1' then other fields or empty.that's not a problem.
* if no row have any value then only through the error
How to do it.

What I have tried:

i have used looping for rows and column given below.
C#
for(int j= 3; j<= columncountvalue; j++)
	{
for (int i = 12; i <= rowcountvalue; i++)
            {
                if (ds.Tables[s].Columns[3][i].ToString().Trim() == "") 
                {

			// statements
		        }
            }
    }


C#
now i want which condition used for that requirements.
Posted
Updated 3-Oct-16 2:27am
v3

1 solution

0) You're using the same variable in both for loops. That is NOT going to give you the expected result.

1) You're hard coding the column number in your if statement instead of using the iterator.

Is this what you meant to do?

C#
for(int j = 3; j <= columncountvalue; j++)
{
    for (int i = 12; i <= rowcountvalue; i++)
    {
        if (string.IsNullOrEmpty(ds.Tables[s].Columns[j][i].ToString().Trim() )) 
        {
            // statements
        }
    }
}


And by the way, if you run into a null value in your table, the code will throw an exception because you tried to call ToString() on a null reference.

Further, if you didn't subtract 1 from columncountvalue and rowcountvalue, you'll probably get an out-of range exception when it hits the end of the rows and or columns.

Finally, I would probably iterate rows before columns, but that's more a matter of style I suppose.
 
Share this answer
 
v3
Comments
Raja Ganapathy 3-Oct-16 8:27am    
Sorry now i edit and put correct format

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