How I convert boolean value to int (1 for True and 2 for false) inside ItemArray. Below is function for converting DataTable to csv.
public string ToCSV(DataTable tbl, Boolean ColumnHeader)
{
string FinalResult = string.Empty;
StringBuilder strb = new StringBuilder();
if (ColumnHeader == true)
{
//column headers
strb.AppendLine(string.Join(",", tbl.Columns.Cast<DataColumn>()
.Select(s => "\"" + s.ColumnName + "\"")));
}
//rows
tbl.AsEnumerable().Select(s => strb.AppendLine(
string.Join(",", s.ItemArray.Select(
i => "\"" + i.ToString() + "\"")))).ToList();
FinalResult = strb.ToString();
strb= null;
return FinalResult;
//return strb.ToString();
}
boolcalled e.g.ToInt()and retruning anintstrb= null;line is a holdover from how things used to work in the vb6/vbscript era. It's no longer useful or helpful, and in rare cases can actually be harmful to your code.