Login    
 
 
 
 
Text/HTML
  
You are here :: Blogs Saturday, May 19, 2012

Search
Note: This uses the internal blog search engine. The Google search engine is also available at the top of the page.
  
Disclaimer

Please review the site disclaimer before downloading or using content found on this site

  
Categories
  
DEVSHED Blog
As always, I welcome your comments!
Mar 23

Written by: Steve Gray
3/23/2010 3:05 PM  RssIcon

Code to read a tab delimited file into a datatable:

 

Imports System.IO
 
 
Dim dir As New DirectoryInfo(strFolder)
Dim files As FileInfo() = dir.GetFiles("*RM Master.txt")
Dim myfile As FileInfo
Dim oDT As New DataTable
Dim strFileLine As String
 
oDT = CreateCustomerDataTable()
 
For Each myfile In files
    Dim filestream As StreamReader
    filestream = File.OpenText(myfile.FullName)
 
    While filestream.Peek <> -1
        strFileLine = filestream.ReadLine()
        Dim astrFileLine = Split(strFileLine, vbTab)
 
        Dim oRow As DataRow = oDT.NewRow
        oRow("custnmbr") = astrFileLine(0)
        oRow("custname") = astrFileLine(1)
    End While
 
    filestream.Close()
Next

 

Function CreateCustomerDataTable() As DataTable
    Dim oDT As New DataTable
 
    Dim custnmbr As DataColumn = New DataColumn("custnmbr",_ 
 System.Type.GetType("System.String"))
    oDT.Columns.Add(custnmbr)
 
    Dim custname As DataColumn = New DataColumn("custname",_ 
 System.Type.GetType("System.String"))
    oDT.Columns.Add(custname)
 
 
    Return oDT
End Function

Tags:
Categories:
As always, I welcome your comments!
  
 
 
Home | Products | Blogs | Contact Us | Links | God's Plan
Privacy Statement | Terms Of Use
 
Copyright 2011 by Devshed.us