Click here to Skip to main content
Rate this: bad
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 18: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__ at 9-Nov-12 0:43am
Thanks but how check for string
Gautam Raithatha at 9-Nov-12 0:51am
i dint understand.
__PP__ at 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 at 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__ at 9-Nov-12 1:35am
ya it dont contain any number
Gautam Raithatha at 9-Nov-12 1:59am
u can chekck it by using regular expressions.
__PP__ at 9-Nov-12 2:20am
K Thank u so much
Ankur\m/ at 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
0 OriginalGriff 390
1 Nirav Prabtani 273
2 _Amy 255
3 Richard Deeming 250
4 CHill60 195
0 _Amy 110
1 Maciej Los 90
2 OriginalGriff 85
3 Mehdi Gholam 80
4 Sergey Alexandrovich Kryukov 75

Advertise | Privacy | Mobile
Web04 | 2.8.140721.1 | Last Updated 9 Nov 2012
Copyright © CodeProject, 1999-2014
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