我正在从CSV文件中读取数据,我的目标是只获取选定的列,但到目前为止,我只能循环获取标题。有人可以协助我循环直到我得到行吗?
导入System.IO 公共类Form1
Private Sub btn_import_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_import.Click
Call csvmanagement()
End Sub
Structure systemstructure
Dim cGroupName As String
Dim cTransactDate As String
Dim cRow_ID As String
Dim cFullName As String
End Structure
Public Sub csvmanagement()
Dim systemspecs As New systemstructure
'Dim raw, column As Integer
Using csvparser As New FileIO.TextFieldParser _
("C:\Users\Eranji\Downloads\new.csv")
Dim csvalue As String()
csvparser.TextFieldType = Microsoft.VisualBasic.FileIO.FieldType.Delimited
csvparser.Delimiters = New String() {","}
csvalue = csvparser.ReadFields()
systemspecs.cGroupName = csvalue(0)
systemspecs.cTransactDate = csvalue(1)
systemspecs.cRow_ID = csvalue(2)
systemspecs.cFullName = csvalue(2)
While Not csvparser.EndOfData
End While
csvalue = csvparser.ReadFields()
End
ListBox1.Items.Add(systemspecs.cFullName & Chr(9) & systemspecs.cGroupName & Chr(9) & systemspecs.cRow_ID & systemspecs.cTransactDate)
End Using
End Sub
结束班
答案 0 :(得分:4)
你只有ReadFields一次
ReadFields是一行
你需要循环结束
While Not MyReader.EndOfData
csvalue = csvparser.ReadFields()
...
End