DataTable.Rows returns c# 中的第二行

DataTable.Rows returns second row in c#

我正在阅读 Excel sheet 使用 OleDbDataReader 并将其转换为 Datatable。 Excel sheet 中的前几列行讲述了 excel.

的详细信息

例如:

Month ---- First Row
Year --- Second Row
Payment ---THird row

Excel sheet 中的余额行包含所有员工的工资详细信息。

我编码如下:

OleDbCommand ocmd = new OleDbCommand(query, conn);

OleDbDataReader odr = ocmd.ExecuteReader();    

DataTable dtable = new DataTable(); 
dtable.Load(odr);

if (dtable.Rows.Count > 0)
{                             
    DataRow row = dtable.Rows[0];
    sMonth = row[2].ToString();
    row = dtable.Rows[1];
    sYear = row[2].ToString();
    row = dtable.Rows[2];
    sPayDate = row[2].ToString();         

    ///Salary details
    for (int i = 6; i < dtable.Rows.Count; i++)
    {        
        row = dtable.Rows[i];
        colName = odr[1].ToString();
        colBasic = row[9].ToString();
        colHRA = row[10].ToString();
        ......
    }
}

但是

DataRow row = dtable.Rows[0]; 

returns第二行。 (即)年份详细信息

我无法在第一行获取月份详细信息。

请根据我的评论将连接字符串的 HDR=YES 属性 更改为 NO

conn.ConnectionString = 
@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source = '" + path + "'" + 
@";Extended Properties=""Excel 8.0;HDR=NO;IMEX=1;ImportMixedTypes=Text;
TypeGuessRows=0""";

"HDR=Yes;" indicates that the first row contains columnnames, not data. "HDR=No;" indicates the opposite..