Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1074
  • Last Modified:

Import CSV to DataSet, Limited to 255 fields

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)
        MsgBox(ds.GetXmlSchema)
        'Debug.Write(ds.GetXmlSchema)
        sw.Write(ds.GetXml)
        sw.Close()
        ds.Dispose()
    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"""
        Else
            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()

        Try
            con.Open()
            da.Fill(dt)
            con.Close()
            com.Dispose()
            con.Dispose()
        Catch ex As Exception
            'whatever you want to do with the error here
        Finally
            If (con.State = ConnectionState.Open) Then
                con.Close()
            End If
        End Try
        ds.Tables.Add(dt)

        Return ds

    End Function


Thanks in advance,


Mark
0
cmgtech
Asked:
cmgtech
1 Solution
 
rafranciscoCommented:
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.
0

Featured Post

 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

Tackle projects and never again get stuck behind a technical roadblock.
Join Now