Dim strfilename As String
Dim num_rows As Long
Dim num_cols As Long
Dim x As Integer
Dim y As Integer
Dim strarray(1, 1) As String
strfilename = "C:\Documents and Settings\test.csv"
If File.Exists(strfilename) Then
Dim tmpstream As StreamReader = File.OpenText(strfilename)
Dim strlines() As String
Dim strline() As String
'Load content of file to strLines array
strlines = tmpstream.ReadToEnd().Split(Environment.NewLine)
' Redimension the array.
num_rows = UBound(strlines)
strline = strlines(0).Split(",")
num_cols = UBound(strline)
ReDim strarray(num_rows, num_cols)
' Copy the data into the array.
For x = 0 To num_rows
strline = strlines(x).Split(",")
For y = 0 To num_cols
strarray(x, y) = strline(y)
Next
Next
rsTable = New DataTable
rsTable.Columns.Add("CUSN15")
rsTable.Columns.Add("LREF15")
rsTable.Columns.Add("DOCD15")
rsTable.Columns.Add("SOPN15")
rsTable.Columns.Add("BTMT15")
rsTable.Columns.Add("BVAT15")
rsTable.Columns.Add("BASENVAT")
rsTable.Columns.Add("BASEVAT")
rsTable.Columns.Add("WHT")
' Display the data in textbox
For x = 0 To num_rows - 1
For y = 0 To num_cols - 1
rsTable.Rows(x)(y) = strarray(x, y)
Next
rsTable.Rows(x)(y) = rsTable.Rows(x)(y) & Environment.NewLine
Next
lstdata.DataSource = rsTable
End If
ผมต้องการอ่านค่าจากไฟล์ csv อ่ะครับ แล้วแปลงให้เป็น datatable แล้วทีนี้มันขึ้น errorว่า There is no row at position 0.