c# - 将 DataGridView 转换为数据表
问题描述
我必须将datagridview转换为datatable,才能使用下面的代码,但是我有一些问题,datagridview的第一行和最后一行没有插入到datatable和hours字段中,包含这种类型的值08:54 ,当它插入数据表时,值变为08:00,我该如何解决这个问题?
C#代码:
DataTable dtemp = new DataTable();
dtemp.Clear();
dtemp.Columns.Add("Giorno");
dtemp.Columns.Add("DataINS");
dtemp.Columns.Add("Ore");
for (int row = 0; row < dataGridViewPrincipale.Rows.Count; row++)
{
DataRow riga = dtemp.NewRow();
riga["Giorno"] = dataGridViewPrincipale.Rows[row].Cells[0].Value.ToString();
riga["DataINS"] = dataGridViewPrincipale.Rows[row].Cells[1].Value.ToString();
riga["Ore"] = dataGridViewPrincipale.Rows[row].Cells[2].Value.ToString();
dtemp.Rows.Add(riga);
}
解决方案
你能试试这个吗?
我将 datagridView 的数据源转换为 DataTable 并放入数据表中。
DataTable dtemp = new DataTable();
dtemp = dataGridViewPrincipale.DataSource as DataTable;
推荐阅读
- javascript - 当我回到上一个组件时,角度重新初始化组件
- excel-formula - Excel LOOKUP 返回 3.33333E-06
- python - 分类系列到分类数据框
- r - ifelse 不对数据帧执行子集
- android - 阻止应用程序部分的 Play 商店爬虫
- store - 我正在尝试将屏幕截图上传到我的应用,但我遇到了问题(应用商店连接)
- datetime - 从 Go 中从 1601-01-01 开始的时间戳计算 time.Time
- php - 在没有纯文本的mysql字段描述中搜索html文本中的单词
- php - chrome驱动程序在每次执行后清除所有会话cookie
- video - 自动播放 vimeo 在 2 个域上工作,但不是第 3 个域