can someone help me take a look i face (oledbexception was unhandled (too many fields defined))
below is my code .

Private Sub btnBrowse_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBrowse.Click

 Properties='Excel 12.0;HDR=NO;'"
 Dim Chosen_File As String = ""

    If openFileDialog1.ShowDialog() = DialogResult.OK Then
        Chosen_File = openFileDialog1.FileName
    End If

    If Chosen_File = String.Empty Then
    End If

    InputExcel.Text = Chosen_File

    Dim ds = New DataSet()
    Dim path = InputExcel.Text
    Dim con As String = "provider=Microsoft.Jet.OLEDB.4.0; Data Source=" + path + ";Extended Properties='Excel 8.0;HDR=NO;IMEX=1;';"

    If InputExcel.Text = ".xlsx" Then
        MessageBox.Show("Wrong File Type", "Error Message")
    End If

    Using connection As OleDbConnection = New OleDbConnection(con)
        Dim sheets As DataTable = GetSchemaTable(con)
        For Each r As DataRow In sheets.Rows
            Dim data As DataTable = New DataTable()
            Dim query As String = "SELECT * FROM [" & r("TABLE_NAME").ToString() & "]"
            Dim adapter = New OleDbDataAdapter(query, connection)
            ds.Tables.Add(data) 'Table1
    End Using
End Sub
Private Function GetSchemaTable(ByVal connectionString As String) As DataTable
    Using connection As OleDbConnection = New OleDbConnection(connectionString)
        Dim schemaTable As DataTable = connection.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, New Object() {Nothing, Nothing, Nothing, "TABLE"})
        Return schemaTable
    End Using
End Function


Recommended Answers

How many columns are defined in your table?

Jump to Post

All 2 Replies

How many columns are defined in your table?

commented: thanks for you replay. My excel file current have around 1000 column +0

1000? Do you need all of them? Apart from the adapter not loading them, this will become a huge performance hit.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.20 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.