我想从我的数据表中选择一系列数据
我在datatable.Select()方法中尝试过。
考虑一下,我在 dtExcelSource 中有10行数据,现在从第4行过滤并从第5行到最后一行插入记录。
我在vb.Net编码
dtExcelSource = DS.Tables("SourceTbl")
dtExcelSource.Columns(0).ColumnName = "A"
dtExcelSource.Columns(1).ColumnName = "B "
dtExcelSource.Columns(2).ColumnName = "CNo"
dtExcelSource.Columns(3).ColumnName = "DNo"
dtExcelSource.Columns(4).ColumnName = "E"
dtExcelSource.Columns(5).ColumnName = " F"
Dim filterDT As DataTable = dtExcelSource.Clone()
Dim rows As DataRow() = dtExcelSource.[Select](???)
For Each row As DataRow In rows
filterDT.ImportRow(row)
Next
gridView.datasource = filterDT
答案 0 :(得分:1)
怎么样:
For Each row As DataRow In dtExcelSource.Rows
If *your range criteria*
filterDT.ImportRow(row)
End If
Next
答案 1 :(得分:1)
也许您需要使用For Loop
代替For Each
,如果您只是按行号过滤,则不需要SELECT
:
For iRowNo As Integer = 3 To dtExcelSource.Rows.Count - 1
filterDT.ImportRow(dtExcelSource.Rows(iRowNo))
Next