Results 1 to 3 of 3

Thread: Diaplay contents of a CSV File

  1. #1

    Thread Starter
    New Member
    Join Date
    May 2002
    Posts
    1

    Question Diaplay contents of a CSV File

    Hey all... I am totally new to VB in every aspect... I am starting with VB .NET and hope someone can help me.

    I have a text file that has Comma Seperated Values. The information in this file is DATA ONLY (no labels at all) and I want to write an application that can take this data and display it and also show the labels (that I will put into the application). Each column in the file has a set description, but it is not in the text file itself... I hope this is making sense...

    I basically want the screen split into 2 sections.

    The left will show the Modules in the files (in the text, they are seperated by <LABEL_S> and <LABLE_E> (for Start and End)...

    In the right hand side, I want to show the data from that file in their respective locations (with labels)...

    If someone can just get me started on how to open the file and start the Parsing of it for output to the screen, I would appreciate it. If you know of a site that can get me started, that would be great too!!!

    Thanks all!!

    Dennis.

  2. #2
    Hyperactive Member Dodger's Avatar
    Join Date
    Mar 2001
    Posts
    433
    Hi Dennis,

    Here is some code to display CSV data in a datagrid. I realize this reply is a bit late, but it may help someone else.

    Code:
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            Dim xDataSet As New Data.DataSet()
            Dim xTable As New DataTable()
            Dim xFile As StreamReader = New StreamReader("C:\csvpath.csv")
    
            With xTable.Columns
                .Add("Column0")
                .Add("Column1")
            End With
    
            While xFile.Peek <> -1
                xTable.Rows.Add(Split(xFile.ReadLine, ",", , CompareMethod.Text))
            End While
    
            xDataSet.Tables.Add(xTable)
            DataGrid1.DataSource = xDataSet
    End Sub
    _Dodger.
    Last edited by Dodger; Sep 7th, 2003 at 05:59 AM.

  3. #3
    Lively Member
    Join Date
    May 2002
    Posts
    94
    Thankx, for posting this a year later then the actual post. This helps me out a great deal.
    If your post is resolved, mark it as such using the thread tools, Keep the forums tidy.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width