我正在使用 winforms 并遇到问题。
我在sql中有一些数据,其中一列是sql生成的unix时间戳。 sql正在自行更新,因此我无法更改数据表中的数据。
所以我填充数据表然后我用它(“获取最新项目”):
DataView dv = db.historyDataSet.Tables["historyTable"].AsEnumerable().Where(r => (Convert.ToInt64(r["timestamp"])) > (time)).AsDataView();
这会生成我的数据视图,我想通过以下方式简单地填充dataGridWiew:
dataGridView.DataSource = dv;
但是如何让datagridview显示人类可读的时间(我正在使用一个名为timeConvert的函数 - 转换不是我的问题)
我这样做:
foreach (DataGridViewRow row in batchvisGridView.Rows)
{
DataRow dr = ((DataRowView)row.DataBoundItem).Row;
dr["timestamp"] = timeConvert(Convert.ToInt64(dr["timestamp"]));
}
但我得到一个错误,表示我无法将字符串存储在单元格中,因为它有不同的类型: 附加信息: Inputstring的格式不正确。< 10:35 26 / 03-16>不能在时间戳中保存。预期类型为Int32。
我如何以最好的方式做到这一点? (我不想改变数据库)