Visual Basic如何读取CSV文件并在数据网格中显示值?

4 .net vb.net csv file-io .net-2.0

我正在使用VB 2005,如何打开CSV文件并读取列/行并在数据网格中显示值?

CSV文件示例:jsmith,jsmith @ hotmail.com

然后我想对每一行(即每个用户)执行一个操作,我该怎么做?

我是新手,你可以说但很高兴学习.

谢谢

Mar*_*rkJ 7

使用TextFieldParser多数民众赞成内置到 VB.NET.谷歌找到了我这个例子

Using MyReader As New Microsoft.VisualBasic.FileIO.TextFieldParser _
  ("C:\test\info.csv")

  'Specify that reading from a comma-delimited file'
  MyReader.TextFieldType = FileIO.FieldType.Delimited
  MyReader.SetDelimiters(",")

  Dim currentRow As String()
  While Not MyReader.EndOfData
    Try
      currentRow = MyReader.ReadFields()
      With Me.dgvReport.Rows
        .Add(currentRow) 'Add new row to data grid view'
     End With
   Catch ex As Microsoft.VisualBasic.FileIO.MalformedLineException
     MsgBox("Line " & ex.Message & _
       "is not valid and will be skipped.")
   End Try
 End While
End Using
Run Code Online (Sandbox Code Playgroud)