Hi all
The following code uses a OFD to import an Excel spreadsheet to a a DGV.
The code works fine... except if i load the OFD and select a new file. If i do this, the DGV doesnt load anything... i mean, its litrally empty, even if i try loading the orignal file.Code:Private Sub btnImport_Click(sender As Object, e As EventArgs) Handles btnImport.Click Dim strConnectionString$ = "Provider=Microsoft.ACE.OLEDB.12.0; Data Source={0}; Extended Properties=""Excel 12.0; HDR=No;IMEX=1""" 'DataGridView1.DataSource.rows.clear() If ofdSelectFile.ShowDialog = Windows.Forms.DialogResult.OK Then strFileName = ofdSelectFile.FileName Dim strExcelFileName$ = String.Format(strConnectionString, strFileName) con = New OleDbConnection(strExcelFileName) DA = New OleDbDataAdapter("select * from [Sheet1$]", con) DT.Reset() DA.Fill(DT) DataGridView1.DataSource = DT con.Close() Else End If End Sub
I've tried adding code to refresh the DGV, i've tried nulling the datasource before loading the new datatable. I'm clean out of ideas. Any help appreciated.




Reply With Quote
