我需要获取 DataTable 中所有单元格的计数,我该怎么做?在将数据插入数据库之前,我需要这个来验证我的 2 个表是否具有相同的单元格数量。
问问题
187 次
2 回答
2
试试这个:
DataTable dt1 = new DataTable(), dt2 = new DataTable();
// define and populate your tables
int count1 = dt1.Columns.Count * dt1.Rows.Count;
int count2 = dt2.Columns.Count * dt2.Rows.Count;
bool verified = count1 == count2;
于 2013-01-16T14:19:20.367 回答
2
DataTable tbl = new DataTable();
foreach (DataRow row in tbl.Rows)
{
foreach (DataColumn col in tbl.Columns)
{
object cellData = row[col];
}
}
于 2013-01-16T14:22:13.603 回答