我不知道如何处理我得到的错误: "无法从对象转换为字符串"
row["timeinseconds"] = TimeSpan.FromSeconds( double.Parse( r["timeinseconds"] ) ).ToString(@"hh\:mm\:ss");
timeinseconds来自sqlite数据库,并存储为整数值
我需要将其解析为double,以便我可以使用timepan的from seconds方法,以便将其转换为正确的格式
private void updateDgvTimesheet()
{
dgvTimesheet.Rows.Clear();
foreach (DataRow r in dataset.Tables[0].Rows)
{
DataRow row = this.dataset.Tables[0].NewRow();
row["taskname"] = r["taskname"];
row["timeinseconds"] = TimeSpan.FromSeconds( double.Parse( r["timeinseconds"] ) ).ToString(@"hh\:mm\:ss");
row["date"] = r["date"];
row["paid"] = r["paid"];
dgvTimesheet.Rows.Add(row);
}
}
答案 0 :(得分:1)
您必须转换r["timeinseconds"].ToString()
将您的功能更改为:
private void updateDgvTimesheet()
{
dgvTimesheet.Rows.Clear();
foreach (DataRow r in dataset.Tables[0].Rows)
{
DataRow row = this.dataset.Tables[0].NewRow();
row["taskname"] = r["taskname"];
row["timeinseconds"] = TimeSpan.FromSeconds( double.Parse( r["timeinseconds"].ToString() ) ).ToString(@"hh\:mm\:ss");
row["date"] = r["date"];
row["paid"] = r["paid"];
dgvTimesheet.Rows.Add(row);
}
}