[RESOLVED] Open File Dialogue -- Datagridview
Hi all
The following code uses a OFD to import an Excel spreadsheet to a a DGV.
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
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.
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.
Re: Open File Dialogue -- Datagridview
Don't reset the DT... clear it. Or create a new one.
-tg
Re: Open File Dialogue -- Datagridview
Argh - why didnt i think of that! Cheers techgnome :).