Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
.csv file
Message
 
 
To
19/08/2004 16:32:26
Mike Cole
Yellow Lab Technologies
Stanley, Iowa, United States
General information
Forum:
ASP.NET
Category:
Other
Title:
Miscellaneous
Thread ID:
00934644
Message ID:
00943061
Views:
25
Here's a blog entry that tells shows how to do it.

http://blogs.worldnomads.com.au/matthewb/archive/2004/03/19/207.aspx

Here's the code
Dim csvConnection As OdbcConnection
Dim ConnectionString As String = "Driver={Microsoft Text Driver (*.txt; *.csv)};Dbq=" & _                                 Directory.GetCurrentDirectory() & ";" 

Try  
   ' Create connection to folder containing CSV file  
   csvConnection = New OdbcConnection(ConnectionString)  
   csvConnection.Open()   

   Dim csvCommand As OdbcCommand  
   Dim csvReader As OdbcDataReader   

   Try    
      ' Select all rows from the    
      csvCommand = csvConnection.CreateCommand()    
      csvCommand.CommandText = "select * from [filename.csv]"    
      csvCommand.CommandType = CommandType.Text     

      ' Use a reader to iterate through the rows    
      csvReader = csvCommand.ExecuteReader()    
      If csvReader.Read() Then      
         Do        
            ' ... Perform actions on the row      
         Loop While csvReader.Read()    
      End If  

   Catch    
      ' Close and de-reference the Reader    
      If Not csvReader Is Nothing Then      
            If Not csvReader.IsClosed Then        
               csvReader.Close()      
            End If      

            csvReader = Nothing    
      End If    

      ' De-reference the Command    
      If Not csvCommand Is Nothing Then      
         csvCommand = Nothing    
      End If  
  End Try

  Catch  

      ' De-reference the Connection  
      If Not csvConnection Is Nothing Then    
         csvConnection.Close()  
      End If
  End Try
>Is there a graceful way to import a .csv file into a datatable, and a way to export a datatable into a .csv? TIA!
>
>MAC
Rick Hodder
MCP Visual Foxpro
C#, VB.NET Developer
Independent Consultant
www.RickHodder.com
MyBlog
Previous
Reply
Map
View

Click here to load this message in the networking platform