Importazione Xls in Vb.Net (Vs2010)

venerdì 20 luglio 2012 - 12.13
Tag Elenco Tags  VB.NET  |  Visual Studio 2010  |  Office 2010

vittosss Profilo | Junior Member

Scenario:
macchina 64 Bit 2008 Server
office 2010
visual studio 2010
suppongo che tutto quanto elencato sopra giri come 64 bit ( la cartella program files liscia o x86 fornisce già di per se una indicazione in merito?)

ho quindi creato in vb la mia maschera con pulsante e codice, che riporto, per leggere dati da xls a vb.
l'errore che mi viene rilasciato è il seguente:
" The 'Microsoft.Jet.OLEDB.4.0' provider is not registered on the local machine "
c'è forse un problema di compatibilità fra 32 e 64 bit?


allego codice usato per importazione dati.
______________________________________________________________________________________________
Option Explicit On
Option Strict On

Imports System
Imports Microsoft.VisualBasic

'//<Ref>System.Data.dll</Ref>
'//<Ref>System.Xml.dll</Ref>
Imports System.Data
Imports System.Data.OleDb
Imports System.Xml

Namespace SyteLine.FormScripts
Public Class Z380WcmMCI_OLEDB
Inherits FormScript

'
'Methods go here
'

Private m_sConn1 As String = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=C:\ExcelData1.xls;" & _
"Extended Properties=""Excel 8.0;HDR=YES"""

Private m_sConn2 As String = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=C:\ExcelData2.xls;" & _
"Extended Properties=""Excel 8.0;HDR=YES"""

Private m_sAction As String


Sub Button1_Click()

m_sAction = "Create_Workbook"

Try
' Call the associated routine to add/update/modify the workbook.
Select Case m_sAction
Case "Create_Workbook" : Create_Workbook()
End Select

Catch ex As OleDbException
Dim er As OleDbError
For Each er In ex.Errors
MsgBox(er.Message)
Next
Catch ex2 As System.InvalidOperationException
MsgBox(ex2.Message)
End Try


End Sub

Public Sub Create_Workbook()

' If the workbooks already exist, prompt to delete.
Dim answer As MsgBoxResult
If Dir("C:\ExcelData1.xls") <> "" Or Dir("C:\ExcelData2.xls") <> "" Then
answer = MsgBox("Delete existing workbooks (C:\ExcelData1.xls and " & _
"C:\ExcelData2.xls)?", MsgBoxStyle.YesNo)
If answer = MsgBoxResult.Yes Then
If Dir("C:\ExcelData1.xls") <> "" Then Kill("C:\ExcelData1.xls")
If Dir("C:\ExcelData2.xls") <> "" Then Kill("C:\ExcelData2.xls")
Else
Exit Sub
End If
End If

'==========================================================================
' Create a workbook with a table named EmployeeData. The table has 3
' fields: ID (char 255), Name (char 255) and Birthdate (date).
'==========================================================================
Dim conn As New OleDbConnection()

conn.ConnectionString = m_sConn1
conn.Open()
Dim cmd1 As New OleDbCommand()
cmd1.Connection = conn
cmd1.CommandText = "CREATE TABLE EmployeeData (Id char(255), Name char(255), BirthDate date)"
cmd1.ExecuteNonQuery()
cmd1.CommandText = "INSERT INTO EmployeeData (Id, Name, BirthDate) values ('AAA', 'Andrew', '12/4/1955')"
cmd1.ExecuteNonQuery()
conn.Close()

'==========================================================================
' Create a workbook with a table named InventoryData. The table has 3
' fields: Product (char 255), Qty (float) and Price (currency).
'==========================================================================

conn.ConnectionString = m_sConn2
conn.Open()
Dim cmd2 As New OleDbCommand()
cmd2.Connection = conn
cmd2.CommandText = "CREATE TABLE InventoryData (Product char(255), Qty float, Price currency)"
cmd2.ExecuteNonQuery()
cmd2.CommandText = "INSERT INTO InventoryData (Product, Qty, Price) values ('Cola', 200, 1.35)"
cmd2.ExecuteNonQuery()
cmd2.CommandText = "INSERT INTO InventoryData (Product, Qty, Price) values ('Chips', 550, 0.89)"
cmd2.ExecuteNonQuery()
conn.Close()

' NOTE: You can ALTER and DROP tables in a similar fashion.

End Sub


End Class
End Namespace

nico839 Profilo | Senior Member

ciao, se non ricordo male, microsoft ha abbandonato lo sviluppo di alcuni driver db per sistemi a 64bit e quindi esistono solo i 32bit. tra questi ci sono il vfpole, il jet e access credo.
Per farli andare su sistemi a 64 bit, devi compilare l'applicazione forzandola a 32bit (x86 nella cpu di destinazione).

Ciao.
Nicolas

http://perledinico.blogspot.com

avarrati Profilo | Newbie

noto una cosa (non so se potrebbe esser quella la causa)
cmq usi come parametri di connessione oledb4 excel 8.0.. dovresti usare excel14 che corrisponde a office2010 che sarebbe la versione che dici di usare.. se vuoi utilizzare sta cosa, aggiungi come riferimento COM l'excel library 14.0 (lui ti importa altri 3 oggetti com)
poi da codice dichiari un ExcelApp e usi quella al posto della connessione..
specificando il worksheet e/o il range dovresti poter leggere/scrivere nelle relative celle di riferimento..
se vuoi del codice scrivimi pure che ti posto qualche esempio (anche se su web se ne trovano un bel po)
testato e funzionante con xp pro 32bit, 7 ultimate 32/64 bit, potrei provare su windows server 2003 r2, ma non ho un 2008 a disposizione :)
Partecipa anche tu! Registrati!
Hai bisogno di aiuto ?
Perchè non ti registri subito?

Dopo esserti registrato potrai chiedere
aiuto sul nostro Forum oppure aiutare gli altri

Consulta le Stanze disponibili.

Registrati ora !
Copyright © dotNetHell.it 2002-2025
Running on Windows Server 2008 R2 Standard, SQL Server 2012 & ASP.NET 3.5