Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Determine type of column
Message
From
16/05/2013 20:18:01
 
General information
Forum:
ASP.NET
Category:
ADO.NET
Environment versions
Environment:
C# 2.0
Miscellaneous
Thread ID:
01574150
Message ID:
01574153
Views:
44
This is a snippet from some code that loops through all the columns in a datatable and checks the data type.
if (Table.Columns[i].DataType == typeof(System.String))
{
  // do something with the string
}
>Hi,
>
>Is there a way to determine in code the type of value in a column of a data set? Here is example:
>
>
>
>DataTable myTable = myDataSet.Tables[0];
>
>DataRow dr = myTable.Rows[0];
>
>// Row dr has a column ACCESS_ENABLED.  I need to know if the type is Int or Bit (True/False)
>
>
>What happened is that sometimes this column is integer and I check if the value 1 using the following method:
>
>
>lUserHasAccess = dr["ACCESS_ENABLED"].ToString().Equals("1");
>
>
>But if the value of the column is True (type in SQL Server is BIT) it always returns False. So I need to change the code to evaluate the type.
>
>TIA
Anyone who does not go overboard- deserves to.
Malcolm Forbes, Sr.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform