vb.net Microsoft.ace.oledb.12.0 未在本地机器上注册
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/22473779/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Microsoft.ace.oledb.12.0 not registered on the local machine
提问by Developerzzz
i have a situation in which i have to inport the Excel sheet or file to my database using vb.net i know the code and the process for doing this but the issue is
我有一种情况,我必须使用 vb.net 将 Excel 工作表或文件导入我的数据库,我知道执行此操作的代码和过程,但问题是
- I have 64 bit operating system
- having 32 bit MS Office
- 我有 64 位操作系统
- 拥有 32 位 MS Office
and i don't want to change my Configuration from to 86bit due to some othere reason so now what should i do any prefer solution any one face same solution like this
由于某些其他原因,我不想将我的配置从 86 位更改为 86 位,所以现在我应该怎么做?
my code is
我的代码是
Dim MyConnection As System.Data.OleDb.OleDbConnection
Dim DtSet As System.Data.DataSet
Dim MyCommand As System.Data.OleDb.OleDbDataAdapter
Dim fBrowse As New OpenFileDialog
With fBrowse
.Filter = "Excel files(*.xlsx)|*.xlsx|All files (*.*)|*.*"
.FilterIndex = 1
.Title = "Import data from Excel file"
End With
If fBrowse.ShowDialog() = Windows.Forms.DialogResult.OK Then
Dim fname As String
fname = fBrowse.FileName
MyConnection = New System.Data.OleDb.OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0; Data Source='" & fname & " '; " & "Extended Properties=Excel 8.0;")
MyCommand = New System.Data.OleDb.OleDbDataAdapter("select * from [Sheet1$]", MyConnection)
MyCommand.TableMappings.Add("Table", "CurrencyRate")
DtSet = New System.Data.DataSet
MyCommand.Fill(DtSet)
MyConnection.Close()
For Each Dr As DataRow In DtSet.Tables(0).Rows
Next
MsgBox("Successfully Saved")
End If
but in this code i got error of
但在这段代码中我得到了错误
Microsoft.ace.oledb.12.0 not registered on the local machine
Microsoft.ace.oledb.12.0 未在本地机器上注册
采纳答案by Developerzzz
i solve my problem time ago but i saw many user visiting this Question so i think i should answer for others help in my question i ask that
我前一段时间解决了我的问题,但我看到很多用户访问了这个问题,所以我想我应该回答其他人对我的问题的帮助我问
- I have 64 bit operating system
having 32 bit MS Office so for this we can not sure that what oledb connection version we have to use so for this we have alternate library from Microsoft to integrate ms office products to our applications.
Microsoft.Office.Interop
- 我有 64 位操作系统
拥有 32 位 MS Office,因此我们无法确定必须使用什么 oledb 连接版本,因此为此我们有来自 Microsoft 的替代库,以将 ms office 产品集成到我们的应用程序中。
Microsoft.Office.Interop
to download and install this library follow this link Interop
要下载并安装此库,请按照此链接互操作
and bellow is my code sample for further help
下面是我的代码示例以获得进一步的帮助
Dim table As New DataTable("CurrencyRate")
Dim OFD As New OpenFileDialog
Dim strDestination As String
With OFD
.Filter = "Excel Office|*.xls;*.xlsx"
.FileName = ""
If .ShowDialog() <> Windows.Forms.DialogResult.OK Then
Return False
End If
strDestination = .FileName
End With
Dim xlApp As Microsoft.Office.Interop.Excel.Application
Dim xlWorkbook As Microsoft.Office.Interop.Excel.Workbook
Dim xlWorkSheet As Microsoft.Office.Interop.Excel.Worksheet
Dim xlRange As Microsoft.Office.Interop.Excel.Range
Dim xlCol As Integer
Dim xlRow As Integer
Dim Data(0 To 3) As String
With table
.Clear()
If strDestination <> "" Then
xlApp = New Microsoft.Office.Interop.Excel.Application
xlWorkbook = xlApp.Workbooks.Open(strDestination)
xlWorkSheet = xlWorkbook.ActiveSheet()
xlRange = xlWorkSheet.UsedRange
If xlRange.Columns.Count > 0 Then
If xlRange.Rows.Count > 0 Then
For xlRow = 2 To xlRange.Rows.Count 'here the xlRow is start from 2 coz in exvel sheet mostly 1st row is the header row
For xlCol = 1 To xlRange.Columns.Count
Data(xlCol - 1) = xlRange.Cells(xlRow, xlCol).text
Next
.LoadDataRow(Data, True)
Next
xlWorkbook.Close()
xlApp.Quit()
KillExcelProcess()
End If
End If
Else
MessageBox.Show("Please Select Excel File", "Information", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
End If
End With
by doing this you will have you excel data in your DataTable and then its on you where you want to save like save it in the sql server or storage area. let me know for further clarification.
通过这样做,您将在 DataTable 中获得 excel 数据,然后将其保存在您想要保存的位置,例如将其保存在 sql server 或存储区域中。让我知道进一步澄清。
回答by NullReferenceException
I solved it by installing 2007 Office System Driver and Microsoft Access Database Engine 2010 Redistributable.Even I'm using 32 bit Office and 64 bit OS and its working well.The download links http://www.microsoft.com/en-in/download/details.aspx?id=13255and http://www.microsoft.com/en-in/download/confirmation.aspx?id=23734
我通过安装 2007 Office System Driver 和 Microsoft Access Database Engine 2010 Redistributable 解决了这个问题。即使我使用的是 32 位 Office 和 64 位操作系统并且它运行良好。下载链接http://www.microsoft.com/en-in /download/details.aspx?id=13255和http://www.microsoft.com/en-in/download/confirmation.aspx?id=23734
The connection code i used :
我使用的连接代码:
OleDbConnection myConnection = new OleDbConnection(
"Provider=Microsoft.ACE.OLEDB.12.0; " +
"data source='" + path + "';" +
"Extended Properties=\"Excel 12.0;HDR=YES;IMEX=1\" ");
回答by ????? ?????????
I solve it by using "Microsoft.Jet.OLEDB.4.0" as below. Hope this help others.
我通过使用“Microsoft.Jet.OLEDB.4.0”来解决它,如下所示。希望这对其他人有帮助。
Public OledbString32Bit As String = "Provider=Microsoft.ACE.OLEDB.12.0;" ' 32 Bit
Public OledbString64Bit As String = "Provider=Microsoft.Jet.OLEDB.4.0;" ' 64 Bit
For value As Integer = 0 To 1
vCNNstring = OledbString & _
"Data Source= " & vPath & ";" & _
"Extended Properties=""Excel 8.0;HDR=YES;IMEX=1"""
ExcelCNN = New System.Data.OleDb.OleDbConnection(vCNNstring)
ExcelCMD = New System.Data.OleDb.OleDbDataAdapter(vSQL, ExcelCNN)
If SheetName = "Sheet2" Then
Dim a As Integer = 0
End If
Try
ExcelCNN.Open()
Exit For
Catch ex As Exception
' If using Default OledbString32Bit not work , change to use OledbString64Bit and save for further call
OledbString = OledbString64Bit
If value = 1 Then
MsgBox("Error in mc_ExcelTableToDataTable using : " & OledbString & ", Error : " & ex.ToString())
End If
End Try
Next