Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Determine type of column
Message
 
 
À
16/05/2013 20:18:01
Information générale
Forum:
ASP.NET
Catégorie:
ADO.NET
Versions des environnements
Environment:
C# 2.0
Divers
Thread ID:
01574150
Message ID:
01574155
Vues:
38
Thank you, Bill.

>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
"The creative process is nothing but a series of crises." Isaac Bashevis Singer
"My experience is that as soon as people are old enough to know better, they don't know anything at all." Oscar Wilde
"If a nation values anything more than freedom, it will lose its freedom; and the irony of it is that if it is comfort or money that it values more, it will lose that too." W.Somerset Maugham
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform