Connecting to a .CSV File?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Mark S.

    #1

    Connecting to a .CSV File?

    Hello,

    I have to pull data from a comma delimited textfile into a dataset. I have
    the ole db connection string, but need to know the syntax for the select
    statement when selecting data from the .csv file.

    Any help would be greatly appreciated!
    Thanks in advance.

  • Cor Ligthert

    #2
    Re: Connecting to a .CSV File?

    Hi Mark,


    \\\\Needs a datagrid on a form
    Private Sub Form1_Load(ByVa l sender As Object, _
    ByVal e As System.EventArg s) Handles MyBase.Load
    Dim file As String = "Test2.txt"
    Dim path As String = "C:\Test1\"
    Dim ds As New DataSet
    Try
    Dim f As System.IO.File
    If f.Exists(path & file) Then
    Dim ConStr As String = _
    "Provider=Micro soft.Jet.OLEDB. 4.0;Data Source=" & _
    path & ";Extended Properties=""Te xt;HDR=No;FMT=D elimited\"""
    Dim conn As New OleDb.OleDbConn ection(ConStr)
    Dim da As New OleDb.OleDbData Adapter("Select * from " & _
    file, conn)
    da.Fill(ds, "TextFile")
    End If
    Catch ex As Exception
    MessageBox.Show (ex.ToString)
    End Try
    DataGrid1.DataS ource = ds.Tables(0)
    End Sub
    ///

    I hope this helps a little bit?

    Cor


    Comment

    • Mark

      #3
      Re: Connecting to a .CSV File?

      Thanks Guys!

      "Cor Ligthert" wrote:
      [color=blue]
      > Hi Mark,
      >
      >
      > \\\\Needs a datagrid on a form
      > Private Sub Form1_Load(ByVa l sender As Object, _
      > ByVal e As System.EventArg s) Handles MyBase.Load
      > Dim file As String = "Test2.txt"
      > Dim path As String = "C:\Test1\"
      > Dim ds As New DataSet
      > Try
      > Dim f As System.IO.File
      > If f.Exists(path & file) Then
      > Dim ConStr As String = _
      > "Provider=Micro soft.Jet.OLEDB. 4.0;Data Source=" & _
      > path & ";Extended Properties=""Te xt;HDR=No;FMT=D elimited\"""
      > Dim conn As New OleDb.OleDbConn ection(ConStr)
      > Dim da As New OleDb.OleDbData Adapter("Select * from " & _
      > file, conn)
      > da.Fill(ds, "TextFile")
      > End If
      > Catch ex As Exception
      > MessageBox.Show (ex.ToString)
      > End Try
      > DataGrid1.DataS ource = ds.Tables(0)
      > End Sub
      > ///
      >
      > I hope this helps a little bit?
      >
      > Cor
      >
      >
      >[/color]

      Comment

      Working...