我需要获取DataTable中所有单元格的计数,我该怎么做?我需要这个来验证我的2个表在将数据插入数据库之前具有相同的单元格数量。
答案 0 :(得分: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;
答案 1 :(得分:2)
DataTable tbl = new DataTable();
foreach (DataRow row in tbl.Rows)
{
foreach (DataColumn col in tbl.Columns)
{
object cellData = row[col];
}
}