文檔文檔讀入Datatable表問題
Dim objReader As New System.IO.StreamReader(ImportName)
Dim sLine As String = " "
Dim arrText As New ArrayList()
Do
sLine = objReader.ReadLine
Loop Until sLine Is Nothing
objReader.Close()
以上代碼是每行每行讀
現在我想把每一行數據放入datatable中
請問怎么放,因為每一行有N多列,列數未知!
或是有其它辦法沒?
[解决办法]
楼主可以试试使用OLeDB来读取,类似于从Excel读取数据到DataSet中
[解决办法]
”1,2,3,4,5,6,7
a,b,c,d,e,f,g
.......“
dim arrRow as String()
dim dt as new datatable( "dtTest ")
arrRow = objReader.ReadLine.split( ", ")
for i as integer =0 to ubound(arrRow)
dim col as new datacolumn( "col " & i,gettype(system.string))
dt.columns.add(col)
next
循环读行
dt.rows.add(arrRow)
循环结束
[解决办法]
dim arrRow as String()
dim dt as new datatable( "dtTest ")
arrRow = objReader.ReadLine.split( ", ")
for i as integer =0 to ubound(arrRow)
dim col as new datacolumn( "col " & i,gettype(system.string))
dt.columns.add(col)
next
循环读行
dt.rows.add(arrRow)
循环结束
取最大的列数,组table