Private Function readerCSV(ByVal strPath As String) As DataTable Dim ds As New DataSet Dim dt As New DataTable("dtCSV") Dim newRow As DataRow Dim objFS ' FileSystemObject Dim objTS ' TextStreamObject Dim arrColumn() As String = {"T_SRANO", "T_NEBIKI", "T_CTGCD", "T_STRCD", "T_HAIF"} Dim strLine As String objFS = Server.CreateObject("Scripting.FileSystemObject") objTS = objFS.OpenTextFile(strPath, 1) Dim strLst As ArrayList strLst = New ArrayList Do Until objTS.AtEndOfStream strLine = objTS.ReadLine strLst.Add(strLine) Loop objTS.Close() objTS = Nothing objFS = Nothing For i As Integer = 0 To arrColumn.Length - 1 dt.Columns.Add(New DataColumn(arrColumn(i))) Next Dim arrSraNo() As String = CStr(strLst.Item(3)).Split(",") Dim arrRevate() As String = CStr(strLst.Item(5)).Split(",") viewstate("T_SRANO") = arrSraNo(0) viewstate("T_NEBIKI") = arrRevate(0) For j As Integer = 10 To strLst.Count - 1 Dim arrlist() As String = CStr(strLst.Item(j)).Split(",") If arrlist(0).ToString().Equals("**終了**") Then Exit For End If newRow = dt.NewRow newRow.Item("T_SRANO") = arrSraNo(0).ToString() newRow.Item("T_NEBIKI") = arrRevate(0).ToString() newRow.Item("T_CTGCD") = arrlist(0).ToString() newRow.Item("T_STRCD") = arrlist(4).ToString() newRow.Item("T_HAIF") = arrlist(9).ToString() dt.Rows.Add(newRow) Next ds.Tables.Add(dt) viewstate("ds") = ds Return dt End Function
Dim ds As New DataSet
Dim dt As New DataTable("dtCSV")
Dim newRow As DataRow
Dim objFS ' FileSystemObject
Dim objTS ' TextStreamObject
Dim arrColumn() As String = {"T_SRANO", "T_NEBIKI", "T_CTGCD", "T_STRCD", "T_HAIF"}
Dim strLine As String objFS = Server.CreateObject("Scripting.FileSystemObject") objTS = objFS.OpenTextFile(strPath, 1) Dim strLst As ArrayList
strLst = New ArrayList Do Until objTS.AtEndOfStream
strLine = objTS.ReadLine
strLst.Add(strLine)
Loop objTS.Close()
objTS = Nothing
objFS = Nothing For i As Integer = 0 To arrColumn.Length - 1
dt.Columns.Add(New DataColumn(arrColumn(i)))
Next Dim arrSraNo() As String = CStr(strLst.Item(3)).Split(",")
Dim arrRevate() As String = CStr(strLst.Item(5)).Split(",")
viewstate("T_SRANO") = arrSraNo(0)
viewstate("T_NEBIKI") = arrRevate(0) For j As Integer = 10 To strLst.Count - 1
Dim arrlist() As String = CStr(strLst.Item(j)).Split(",")
If arrlist(0).ToString().Equals("**終了**") Then
Exit For
End If
newRow = dt.NewRow
newRow.Item("T_SRANO") = arrSraNo(0).ToString()
newRow.Item("T_NEBIKI") = arrRevate(0).ToString()
newRow.Item("T_CTGCD") = arrlist(0).ToString()
newRow.Item("T_STRCD") = arrlist(4).ToString()
newRow.Item("T_HAIF") = arrlist(9).ToString()
dt.Rows.Add(newRow)
Next
ds.Tables.Add(dt)
viewstate("ds") = ds Return dt
End Function