Click here to Skip to main content
16,015,973 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Suppose, I have a dataset which has one datatable. I want to know the datatype of every columnname like Is it numeric or varchar (string)?

Is there any way to identify the datatype of a column ?
Posted

DataSet->Tables->DataTable->Columns->DataColum->DataType

http://msdn.microsoft.com/en-us/library/system.data.datacolumn.datatype.aspx[^]
 
Share this answer
 
Edit: as comments say it doesn't work. just wanted to help.

You can use something like this
C#
foreach (DataRow row in dataSet2.Tables[0].Rows)
{
    foreach (DataColumn col in dataSet2.Tables[0].Columns)
    {
        if(row[col].GetType() == typeof(int)){
            row[col] = 0;
        }
        if (row[col].GetType() == typeof(string))
        {
            row[col] = "no data";
        }
    }
}
 
Share this answer
 
v2
Comments
Kornfeld Eliyahu Peter 28-Mar-14 5:54am    
GetType() returns the type of the .NET class and not the SQL data type...for that there is property named DataType!
BELGIUMsky 28-Mar-14 6:01am    
col.DataType you mean?
BELGIUMsky 28-Mar-14 10:53am    
the people that downvote if you can do it better why don't you give him an answer.
No wonder people just delete there answers on this site
Kornfeld Eliyahu Peter 30-Mar-14 4:28am    
I mean DataColumn::DataType, and I didn't downvoted you (even your answer is wrong), and I did give my solution just before you...

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