Import CSV to DataSet, Limited to 255 fields

Posted on 2005-04-15
Last Modified: 2008-02-01
I have a CSV that is 300 cols and I am importing it to a dataset.  It  only imports 255 cols and then it trunc's the rest of them.

Here is my code:

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim ds As DataSet = New DataSet()
        Dim sw As System.IO.StreamWriter = New System.IO.StreamWriter("c:\xml.xml")

        ds = OpenCSVFile("C:\outgoing\cms\pmastr\pmastr-2005-01.txt", False)
    End Sub

    Public Function OpenCSVFile(ByVal fileName As String, ByVal hasHeader As Boolean) As DataSet

        Dim _path As String = System.IO.Path.GetDirectoryName(fileName)
        Dim _file As String = System.IO.Path.GetFileName(fileName)
        Dim strConn As String = ""

        If (hasHeader) Then
            strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + _path + ";Extended Properties=""text;HDR=Yes;FMT=Delimited"""
            strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + _path + ";Extended Properties=""text;HDR=No;FMT=Delimited"""
        End If

        Dim con As New OleDbConnection(strConn)
        Dim com As New OleDbCommand("select * from [" + _file + "]", con)
        Dim da As New OleDbDataAdapter(com)
        Dim dt As New DataTable()
        Dim ds As New DataSet()

        Catch ex As Exception
            'whatever you want to do with the error here
            If (con.State = ConnectionState.Open) Then
            End If
        End Try

        Return ds

    End Function

Thanks in advance,

Question by:cmgtech
    1 Comment
    LVL 28

    Accepted Solution

    I believe this is the limitation of Microsoft.Jet.OLEDB.4.0 and nothing can be to increase it.  Excel is using the same provider and Excel is also limited to 255 columns.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    IT, Stop Being Called Into Every Meeting

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Normally a window is moved by clicking on the caption bar and dragging. You may want your user to be able to move borderless forms or move a form by clicking anywhere in the form without the limitation to the caption bar. There are many ways to do i…
    This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
    Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
    Here's a very brief overview of the methods PRTG Network Monitor ( offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    22 Experts available now in Live!

    Get 1:1 Help Now