I have cruised through many questions now to get a solution to my problem but I really can't find any!
I am doing integrations toward ERP systems and encounter the same problem regularly so now it's time to do something about it.
Many SOAP webservices return query result as System.Data.DataSet, Where the dataset has 1 table.
The problem is that the specification I get might say that a date value is of datatype DateTime, but my program doesn't really agree.
Is there a way to get the specific data types of each column in a DataRow?
I have created a UnitTest to test my extension function, GetColumnTypes(DataTable Table).
DataTable tbl = new DataTable("TestTable");
tbl.Columns.Add("INTEGER");
tbl.Columns.Add("STRING");
tbl.Columns.Add("DATETIME");
tbl.Columns.Add("DOUBLE");
tbl.Columns.Add("FLOAT");
tbl.Columns.Add("LONG");
tbl.Rows.Add(int.MaxValue, string.Empty, DateTime.MaxValue, double.MaxValue, float.MaxValue, long.MaxValue);
This is just a dummy table but should serve the purpose. And my extension method.
public static Type[] GetColumnTypes(DataTable Table)
{
IList<Type> types = new List<Type>();
DataRow row = Table.Rows[0];
foreach (object item in row.ItemArray)
{
types.Add(item.GetType());
}
return types.ToArray();
}
The result here is string on each item in the row array. Even though I send in specific primitive data types in the row, eg. long.MaxValue etc.
If I try to fetch Table.Columns and then use DataType I only get string as well.
Is there a way to do this?
Thanks :)