Objectives is to write the DataTable content to the text file in the format
Expand|Select|Wrap|Line Numbers
- Col1 | Col2 | Col3
- ------|-------|---------
- Val11 | Val21 | Val31
- Val12 | Val22 | Val32
- Val13 | Val23 | Val33
I tried this by iterating through each Row in the table.While writing the DataRow content to the text file, the code I wrote is as -
Expand|Select|Wrap|Line Numbers
- strArray = new string[row.ItemArray.Length];
- row.ItemArray.CopyTo(strArray,0); //<---- error occurs here
- string rowForTextFile = string.Join("\t", (string[])row.ItemArray);
- //functionality to write the the rowForTextFile to text file
"The error was At least one element in the source array could not be cast down to the destination array type"
Later it is occured to me that of the columns Col1,Col2,Col3 - Col3 is integer.Hence the error.
In order to join separate strings (Call to string.Join() ) I need to copy the object array to string array (Call to row.ItemArray.CopyTo() ) .Is there any solution over this..?
I could have achived the result by iterating through Datacolumn of the datarow.. But I believe that will consume time if the rows count to a lacs or two.Hence I tried implementing it this way.
Please provide inputs.
Thanks!