Click here to Skip to main content
12,698,600 members (24,042 online)
Rate this:
Please Sign up or sign in to vote.
See more: C# ASP.NET
How to check the Each row values datatype in dataTable.For Example ProjectId Column's row values are must be to check it
Posted 8-Nov-12 19:23pm
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

You can check for any type of variable
string ot ="adas";
if (ot is string)
   return string;
else if (ot is int)
   return int;
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

u can use int.TryParse for this:
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
        //if failure, i.e ProjectId is not integer
__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
Gautam Raithatha 9-Nov-12 1:59am
u can chekck it by using regular expressions.
__PP__ 9-Nov-12 2:20am
K Thank u so much
Ankur\m/ 9-Nov-12 0:53am
Correct, 5!

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170118.1 | Last Updated 9 Nov 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100