通过访问在DataGridView中显示数据 [英] Display data in DataGridView from access

查看:64
本文介绍了通过访问在DataGridView中显示数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我正在为我的项目使用Visual Studio 2010.现在我已经获得了Excel 2010中的数据库.我想使用数据网格视图或表格显示此数据.请有人帮我解决这个问题.我想通过代码来实现.在此先感谢

OP已添加:

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]将OP代码质疑,带有代码块,标签,主题-OriginalGriff [/edit]

[edit]阅读完整的代码问题后,与Excel或ASP.NET无关:删除-OriginalGriff [/edit]



[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]

推荐答案

HI,
angel5

尝试将oledb连接更改为

MyConnection =新的System.Data.OleDb.OleDbConnection("provider = Microsoft.Jet.OLEDB.4.0;数据源="& amp; myPath& amp;"'';& amp;"扩展属性= Excel 8.0;)

并尝试一次.

谢谢,
流行

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


这篇关于通过访问在DataGridView中显示数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆