In my application returns following datatable,
+-------------+----------+------------+-------+-------+----------+
| AccountName | WaitTime | AssistTime | FName | LName | FullName |
+-------------+----------+------------+-------+-------+----------+
| XXX | 18 | 15 | Mary | Sil | |
+-------------+----------+------------+-------+-------+----------+
| YYY | 67 | 3 | Jany | Joh | |
+-------------+----------+------------+-------+-------+----------+
| ZZZ | 50 | 100 | Kate | Ham | |
+-------------+----------+------------+-------+-------+----------+
In above datatable
, WaitTime
and AssistTime
data coming as double value,Now I need to change the format of WaitTime
and AssistTime
columns format to 00:00:00 (hh:mm:ss)
format. So I just write folowing code(please be noted this part of code).
DataTable tableone = ds.Tables[0];
tableone.Select().ToList().ForEach(row =>
{
string FirstName = Convert.ToString(row["FName"], CultureInfo.InvariantCulture);
string LastName = Convert.ToString(row["LName"], CultureInfo.InvariantCulture);
double xxx = Convert.ToDouble(row["WaitTime"]);
row.SetField("WaitTime",secondsToTime(xxx));
row.SetField("FullName", string.Format("{0} {1}", FirstName, LastName));
});
private string secondsToTime(double seconds)
{
TimeSpan t = TimeSpan.FromSeconds(seconds);
string answer = string.Format("{0:D2}:{1:D2}:{2:D2}",
t.Hours,
t.Minutes,
t.Seconds);
return answer;
}
But above code gives this error,
System.ArgumentException: 'Input string was not in a correct format.Couldn't store <00:00:18> in WaitTime Column. Expected type is Decimal.' FormatException: Input string was not in a correct format.
I need following DataTable as formated one.
+-------------+----------+------------+-------+-------+----------+
| AccountName | WaitTime | AssistTime | FName | LName | FullName |
+-------------+----------+------------+-------+-------+----------+
| XXX | 00:00:18 | 00:00:15 | Mary | Sil | Mary Sil |
+-------------+----------+------------+-------+-------+----------+
| YYY | 00:01:07 | 00:00:03 | Jany | Joh | Jany Joh |
+-------------+----------+------------+-------+-------+----------+
| ZZZ | 00:00:50 | 00:01:40 | Kate | Ham | Kate Ham |
+-------------+----------+------------+-------+-------+----------+
How can I do this? please help