Rami Masri

Rami Masri

  • NA
  • 5
  • 0

Insert information into a CSV file

Apr 4 2008 6:26 PM

Hi guys,

Alright I'm writing this VB 2005 program for work and i'm stuck at one part only.  I need to write to a CSV file.  I've been doing some digging around for 2 days; I know that it's better coding to use ADO.Net instead of streaming (not sure whether i should use oledb or odbc though .. it doesn't matter i guess) and I know how to read from a CSV file but can't find anything on how to write to it.  So I would appreciate any help in this matter. 

The CSV file contains 6 columns; line# (which will need to be incremented), version #, minor version #, description, and 2 other columns which i can't remember the titles to.

Here's the code I have so far

Imports System.Data
Imports System.Data.OleDb
Imports ADODB

Dim sConnectionString As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\test\VCS;Extended Properties=Text;"

Dim conn As New OleDbConnection(sConnectionString) 
Dim objAdapter1 As New OleDbDataAdapter() 
Dim StrCmdInsert As New OleDbCommand("INSERT INTO test.csv VALUES (12, 2, 0.2, , eG3.2)", conn)  (the 12 needs to be incremented I guess .. i.e. previous+1)

conn.Open()

 objAdapter1.InsertCommand = StrCmdInsert 
 StrCmdInsert.ExecuteNonQuery()

 conn.Close()

Thank you very much in advance for all the help.


Answers (4)