显示system.data.datarow中的行号
本文关键字:datarow system data 显示 | 更新日期: 2023-09-27 17:54:44
我要导入一个excel文档到我的项目中
DataSet result = excelReader.AsDataSet();
if (result != null)
{
foreach (System.Data.DataTable t in result.Tables)
{
if (t != null && t is System.Data.DataTable)
{
System.Data.DataTable table = t as System.Data.DataTable;
Items Lastitem = new Items();
foreach (System.Data.DataRow r in t.Rows)
{
if (r != null && r is System.Data.DataRow)
{
//new ItemType
if (r.ItemArray[0] != null)
{
然后我运行检查来检查哪一列是空的,当我得到空列,然后我想要得到空行。我试过了:
if (checkIfColumnisEmpty(r.ItemArray[0]) && !checkIfColumnisEmpty(r.ItemArray[1]))
{
throw new ImportBOQException("Error importing document: First column is empty at row " + r);
r作为数据流,感知允许我rowError, rowState等…但不是行号....有什么想法吗?}
在遍历行时,可以使用For Loop
而不是Foreach
,如下所示:
for (int i = 0; i < t.Rows.Count; i++)
{
// Do Your Null Checking and throw the exception with iteration number + 1
if (checkIfColumnisEmpty(t.Rows[i].ItemArray[0]) && !checkIfColumnisEmpty(t.Rows[i].ItemArray[1]))
{
throw new ImportBOQException("Error importing document: First column is empty at row " + (i + 1));
}
}