MSFN Forum: Read Excel file into Datagrid using VB.net - MSFN Forum

Jump to content



Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Read Excel file into Datagrid using VB.net Rate Topic: -----

#1 User is offline   Hitman47 

  • Group: Members
  • Posts: 4
  • Joined: 21-August 07

Posted 08 February 2008 - 11:11 AM

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 :realmad: . 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 Sub
End Class


#2 User is offline   eyeball 

  • Have you tried turning it off and on again?
  • PipPipPipPipPipPip
  • Group: Members
  • Posts: 1,150
  • Joined: 28-October 05

Posted 08 February 2008 - 02:19 PM

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.

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users



All trademarks mentioned on this page are the property of their respective owners
Copyright © 2001 - 2011 msfn.org
Privacy Policy