Ver Mensaje Individual
  #5 (permalink)  
Antiguo 26/01/2012, 01:37
wwwmaster
 
Fecha de Ingreso: noviembre-2002
Ubicación: DF
Mensajes: 1.056
Antigüedad: 21 años, 5 meses
Puntos: 37
Respuesta: Como migras excel a tabla sql

Con codigo ASP.NET:

Abro un archivo .XLS como si fuera una database

Dim connString As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & archivoExcel & ";" & "Extended Properties=Excel 8.0;" 'HDR=Yes;IMEX=0;"
Dim oledbConn As OleDbConnection = New OleDbConnection(connString)
oledbConn.Open()

ACCEDO A LA HOJA COMO SI FUERA UNA TABLA

Dim rsTiemposExcel
strSql = "SELECT * FROM [" & hoja & "$]"
Dim cmd = New OleDbCommand(strSql, oledbConn)
rsTiemposExcel = cmd.ExecuteReader()

y luego ya voy ciclando y recuperando como cualquier reader para armar los inserts y colocar la info en mi tabla Sql Server (ejemplo):



If Not IsDBNull(rsTiemposExcel(0)) Then colA = rsTiemposExcel(0)
If Not IsDBNull(rsTiemposExcel(1)) Then colB = rsTiemposExcel(1)
If Not IsDBNull(rsTiemposExcel(2)) Then colC = rsTiemposExcel(2)
If Not IsDBNull(rsTiemposExcel(3)) Then colD = rsTiemposExcel(3)


strSql = "INSErT INTO CARRERAS (idCategoria, moto, nombre, marca, estado, CH01_ideal, transponder) VALUES("
strSql = strSql & "" & idCategoria & ","
strSql = strSql & "'" & moto & "',"
strSql = strSql & "'" & Nombre.ToUpper() & "',"