experchange > dotnet.languages.* > dotnet.languages.vb

damian (04-18-05, 11:38 AM)
I want to split a large csv file into smaller files. How
can i go about this?..

thank you !
Ken Tucker [MVP] (04-18-05, 12:25 PM)
Hi,

You would have to manually break the csv into several files.
Here is some code that might help. It creates a csv and reads it into
dataset and displays it in a datagrid.

If Not Directory.Exists("C:\CSV Test") Then
Directory.CreateDirectory("C:\CSV Test")

'

' Create a csv file

'

Dim sw As New StreamWriter("C:\CSV Test\Test.csv", False)

sw.WriteLine("Column1,Column2,Column3")

For x As Integer = 0 To 20

sw.WriteLine("{0},{0},{0}", x)

Next

sw.Close()

'

' Open an oledb connection and show it in a datagrid

'

Dim strConn As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\CSV
Test;Extended Properties=""text;HDR=Yes;FMT=Delimited"""

Dim conn As New OleDb.OleDbConnection(strConn)

Dim da As OleDb.OleDbDataAdapter

Dim ds As New DataSet

Dim mycmd As New OleDb.OleDbCommand("Select * from Test.csv", conn)

Try

da = New OleDb.OleDbDataAdapter(mycmd)

da.Fill(ds)

Catch ex As Exception

Trace.WriteLine(ex.ToString)

Return

End Try

DataGrid1.DataSource = ds.Tables(0)

DataGrid1.CaptionText = "CSV Test"

Ken

------------------------------
"damian" <anonymous> wrote in message
news:280a
I want to split a large csv file into smaller files. How
can i go about this?..

thank you !
damian (04-18-05, 12:39 PM)
cheers
[..]
Similar Threads