Hitman47 Posted February 8, 2008 Share Posted February 8, 2008 I want data from an excel file(g:\recordsheet.xls) to be imported into a Datagrid using VB.nwt windows application. I use the following code got from net, but after running the program the datagrid remains blank . What to do??--------------------------Imports System.Data.OleDb Private Sub form1_load() Dim con As OleDbConnection Dim da As OleDbDataAdapter Dim ds As DataSet Try con = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;data source=g:\recordsheet.xls;Extended Properties=Excel 8.0") con.Open() da = New OleDbDataAdapter("select * from [sheet1$]", con) da.TableMappings.Add("Table", "Details") da.Fill(ds) DataGrid1.DataSource = ds.Tables(0).DefaultView DataGrid1.AlternatingBackColor = Color.Yellow Catch ex As Exception MsgBox(ex.Message) Finally con.Close() End Try End SubEnd Class Link to comment Share on other sites More sharing options...
eyeball Posted February 8, 2008 Share Posted February 8, 2008 i can see what this code is attempting to do although im more familiar with interacting with access not excel, however i would suggest stepping through the program line by line and finding out for example if the the dataset has been filled with the values from the xls document let us know how it goes and il help more if i can. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now