Click here to Skip to main content
15,921,577 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi all,

i am using visual studio 2010 for my project. Now i have been given a database which is in Excel 2010.I want to display this data using a data grid view or table.Please can somebody help me on this.I want to do it via code. Thanks in advance

The OP added:
Imports System.Data
Imports System.Data.OleDb
Public Class Form1

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim connstring As String = "Provider= Microsoft.ACE.OLEDB.12.0;Data Source=C:\Documents and Settings\sku.TIMENGOGDC\Desktop\data.mdb.accdb"
        Dim myconn As OleDbConnection = New OleDbConnection
        myconn.ConnectionString = connstring
        Dim da As OleDbDataAdapter = New OleDbDataAdapter("Select * from Costing Details", myconn)
        Dim ds As DataSet = New DataSet
        da.Fill(ds, "Costing")
        DataGridView1.DataSource = ds.DefaultViewManager
    End Sub
End Class


[edit]Moved OP code into question, with code block, tags, subject - OriginalGriff[/edit]

[edit]After reading the whole question with the code, this has nothing to do with Excel or ASP.NET: removed - OriginalGriff[/edit]
Posted
Updated 16-Feb-11 21:56pm
v4
Comments
Sunasara Imdadhusen 17-Feb-11 3:30am    
Did you try to write a code?
angel5 17-Feb-11 3:40am    
yes i have written the code as follows-

Imports System.Data
Imports System.Data.OleDb
Public Class Form1

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim connstring As String = "Provider= Microsoft.ACE.OLEDB.12.0;Data Source=C:\Documents and Settings\sku.TIMENGOGDC\Desktop\data.mdb.accdb"
Dim myconn As OleDbConnection = New OleDbConnection
myconn.ConnectionString = connstring
Dim da As OleDbDataAdapter = New OleDbDataAdapter("Select * from Costing Details", myconn)
Dim ds As DataSet = New DataSet
da.Fill(ds, "Costing")
DataGridView1.DataSource = ds.DefaultViewManager
End Sub
End Class


But when i try to run,there is no data displayed

1 solution

HI,
angel5

try to change the oledb connection to

MyConnection = New System.Data.OleDb.OleDbConnection("provider=Microsoft.Jet.OLEDB.4.0; data source='" & myPath & " '; " & "Extended Properties=Excel 8.0;")

and try it once.

Thanks,
Prasant
 
Share this answer
 
Comments
Sandeep Mewara 17-Feb-11 4:58am    
Comment from OP:
Hi Prasant,

I tried your soultion but it is still diplaying blank data.I think i m using access database wherein i get a error called as "Could not retrieve schema information".Can u suggest me on this.

Thanks

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900