Hello,
I tried using the following code from http://vb.net-informations.com/excel...xcel_oledb.htm but I cannot tell what's wrong with it.
What I want to do is to only view excel data from a datagrid in vb.net. I have modified the file path to the one I am using as follows:
I have attached a pic of what my table looks like and what I get when I press run.Code:Imports System.Data Public Class TR_Viewer Private Sub TR_Viewer_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Try Dim MyConnection As System.Data.OleDb.OleDbConnection Dim DtSet As System.Data.DataSet Dim MyCommand As System.Data.OleDb.OleDbDataAdapter MyConnection = New System.Data.OleDb.OleDbConnection("provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=C:\Users\u618863\Documents\TestFile.xlsx;Extended Properties=Excel 8.0;") MyCommand = New System.Data.OleDb.OleDbDataAdapter _ ("select * from [Sheet1$]", MyConnection) MyCommand.TableMappings.Add("Table", "TestTable") DtSet = New System.Data.DataSet MyCommand.Fill(DtSet) DataGridView1.DataSource = DtSet.Tables(0) MyConnection.Close() Catch ex As Exception MsgBox(ex.ToString) End Try End Sub End Class
My spreadsheet [Sheet1] contains cells in row 1 only, columns A to D.
Any help would be appreciated




Reply With Quote
