farooq82 0 Light Poster

Hi everyone,

Below is code snippet to load excel file in datagrid. When my excel file is load is show unnecessary column with blank data. I did not want to show these columns. Can any help me how I will remove this column. I don't know how much blank column this datagrid will have.

Dim LoadCashDataAdapter As New OleDbDataAdapter
        Dim Connection As OleDb.OleDbConnection

        Try

            Me.OpenExcelFile.FileName = ""
            Me.OpenExcelFile.Filter = "Microsoft Excel (.xls) | *.xls"
            Me.OpenExcelFile.ShowDialog()
            Me.TextLoadCashBook.Text = OpenExcelFile.FileName

            If TextLoadCashBook.Text <> Nothing Then

                Connection = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; " & "data source=" & TextLoadCashBook.Text & "; " & "Extended Properties=Excel 8.0;")
                LoadCashDataAdapter = New OleDbDataAdapter("SELECT * FROM [Sheet1$]", Connection)
                Connection.Open()

                LoadCashDataAdapter.TableMappings.Add("Table", "CashBook")
                LoadCashDataAdapter.Fill(LoadCashBookDataSet)


                DataGridViewCashBook.DataSource = LoadCashBookDataSet.Tables(0)
                'DataGridViewCashBook.DataBindings()
                SetGrids()
                Connection.Close()

            End If

        Catch ex As Exception

            MsgBox(Err.Description)

        End Try
Be a part of the DaniWeb community

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