Ver Mensaje Individual
  #1 (permalink)  
Antiguo 24/03/2011, 04:58
fernan2010
 
Fecha de Ingreso: febrero-2010
Mensajes: 105
Antigüedad: 14 años, 2 meses
Puntos: 1
Pasar datos de Excell a SQL

Estoy utilizando este código para pasar un fichero Excell a SQl pero obtengo un error en "adExecuteNoRecords"

Alguna sugerencia?

Gracias.



Código vb:
Ver original
  1. Dim cn As ADODB.Connection
  2.     Dim strSQL As String
  3.     Dim lngRecsAff As Long
  4.     Set cn = New ADODB.Connection
  5.     cn.Open "Provider=SQLOLEDB;Data Source=<server>;" & _
  6.         "Initial Catalog=<database>;User ID=<user>;Password=<password>"
  7.  
  8.     'Import by using OPENDATASOURCE.
  9.    strSQL = "SELECT * INTO XLImport6 FROM " & _
  10.         "OPENDATASOURCE('Microsoft.Jet.OLEDB.4.0', " & _
  11.         "'Data Source=C:\test\xltest.xls;" & _
  12.         "Extended Properties=Excel 8.0')...[Customers$]"
  13.     Debug.Print strSQL
  14.     cn.Execute strSQL, lngRecsAff, adExecuteNoRecords
  15.     Debug.Print "Records affected: " & lngRecsAff
  16.  
  17.     'Import by using OPENROWSET and object name.
  18.    strSQL = "SELECT * INTO XLImport7 FROM " & _
  19.         "OPENROWSET('Microsoft.Jet.OLEDB.4.0', " & _
  20.         "'Excel 8.0;Database=C:\test\xltest.xls', " & _
  21.         "[Customers$])"
  22.     Debug.Print strSQL
  23.     cn.Execute strSQL, lngRecsAff, adExecuteNoRecords
  24.     Debug.Print "Records affected: " & lngRecsAff
  25.  
  26.     'Import by using OPENROWSET and SELECT query.
  27.    strSQL = "SELECT * INTO XLImport8 FROM " & _
  28.         "OPENROWSET('Microsoft.Jet.OLEDB.4.0', " & _
  29.         "'Excel 8.0;Database=C:\test\xltest.xls', " & _
  30.         "'SELECT * FROM [Customers$]')"
  31.     Debug.Print strSQL
  32.     cn.Execute strSQL, lngRecsAff, adExecuteNoRecords
  33.     Debug.Print "Records affected: " & lngRecsAff
  34.  
  35.     cn.Close
  36.     Set cn = Nothing