我如何使用MS excel 2010-2013作为数据库制作VB 2010应用程序。 [英] How I'm make VB 2010 application using MS excel 2010-2013 as database.

查看:57
本文介绍了我如何使用MS excel 2010-2013作为数据库制作VB 2010应用程序。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

那里,



请建议我做什么,因为我使用的是MS Office 2013版本,并且在运行时错误中不支持此代码得到的电脑错误是'Microsoft Office 2013未在您的本地机器上注册'。



请做必要的代码,请尽快回答我。



我尝试过:



there,

Kindly suggest what I do, because I'm using MS office 2013 version and they are not supported in this code in run time error get from pc error is 'the Microsoft office 2013 is not registered on your local machine'.

Please do needful code and please answer me asap.

What I have tried:

Imports System.Data
Public Class Form1


    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Try

            Dim con As System.Data.OleDb.OleDbConnection
            Dim ds As System.Data.DataSet
            Dim cmd As System.Data.OleDb.OleDbDataAdapter
            Dim path As String
            path = "C:\\Users\\Bhargav Ginoya\\Documents\\Visual Studio 2010\\Projects\\Country Club india ltd\\Book1.xls"
            con = New System.Data.OleDb.OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + path + "; Extended Properties=Excel 12.0;")
            cmd = New System.Data.OleDb.OleDbDataAdapter("Select * From[ALL MEMBERSHIP DETAIL$]", con)

            ds = New System.Data.DataSet
            cmd.Fill(ds)
            DataGridView1.DataSource = ds.Tables(0)
            con.Close()

        Catch ex As Exception
            MsgBox(ex.Message)
        End Try


    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click


        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.ACE.OLEDB.12.0;Data Source=C:\\Users\\Bhargav Ginoya\\Documents\\Visual Studio 2010\\Projects\\Country Club india ltd\\Book1.xls; Extended Properties=Excel 12.0;")
            MyCommand = New System.Data.OleDb.OleDbDataAdapter _
                ("select * from [ALL MEMBERSHIP DETAIL$]", 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
            MessageBox.Show(ex.Message)
        End Try
    End Sub

End Class

推荐答案

,con)

ds =新的System.Data.DataSet
cmd.Fill(ds )
DataGridView1.DataSource = ds.Tables(0)
con.Close()

Catch ex As Exception
MsgBox(ex.Message)
结束尝试


结束子

私人子按钮2_Click(ByVal sender As System.O bject,ByVal e As System.EventArgs)处理Button2.Click


尝试
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.ACE.OLEDB.12.0 ;数据来源= C:\\Users \\ Bhargav Ginoya \\Documents \\ Visual Studio 2010 \\Projects \\ CountryCountry india ltd \\ .Book1.xls;扩展属性= Excel 12.0;)
MyCommand = New System.Data.OleDb.OleDbDataAdapter _
(select * from [ALL MEMBERSHIP DETAIL
", con) ds = New System.Data.DataSet cmd.Fill(ds) DataGridView1.DataSource = ds.Tables(0) con.Close() Catch ex As Exception MsgBox(ex.Message) End Try End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click 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.ACE.OLEDB.12.0;Data Source=C:\\Users\\Bhargav Ginoya\\Documents\\Visual Studio 2010\\Projects\\Country Club india ltd\\Book1.xls; Extended Properties=Excel 12.0;") MyCommand = New System.Data.OleDb.OleDbDataAdapter _ ("select * from [ALL MEMBERSHIP DETAIL


,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
MessageBox.Show(ex.Message)
End Try
End Sub

结束类
", 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 MessageBox.Show(ex.Message) End Try End Sub End Class


如评论中所述,您需要安装Office或找到没有它的第三方dll。我相信你也可以使用Open XML SDK, [ ^ ]
As mentioned in the comments, you need to install Office or find a 3rd party dll that will work without it. I believe you can also use the Open XML SDK, [^]


这篇关于我如何使用MS excel 2010-2013作为数据库制作VB 2010应用程序。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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