Click here to Skip to main content
15,867,594 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How to check the Each row values datatype in dataTable.For Example ProjectId Column's row values are must be integer..how to check it
Posted

You can check for any type of variable
C#
string ot ="adas";
if (ot is string)
   return string;
else if (ot is int)
   return int;
 
Share this answer
 
v2
u can use int.TryParse for this:
C#
foreach (DataRow dr in datatable.Rows)
{
    int temp;

    bool flag = int.TryParse(dr["ProjectId"].ToString(), out temp);

    if (flag == true)
    {
        //if success, i.e. ProjectId is int. its value will be in variable temp
    }
    else
    {
        //if failure, i.e ProjectId is not integer
    }
}
 
Share this answer
 
v2
Comments
__PP__ 9-Nov-12 0:43am    
Thanks but how check for string
Gautam Raithatha 9-Nov-12 0:51am    
i dint understand.
__PP__ 9-Nov-12 1:02am    
How to check for row values for particular column in string.(EX:Name columns not contain numbers it has only string)
Gautam Raithatha 9-Nov-12 1:09am    
any datatype can can converted into string by ToString() method. so r u asking that u want to identify column by its data i.e. which dont contain any number? or by type of column?
__PP__ 9-Nov-12 1:35am    
ya it dont contain any number

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