Foros del Web » Programando para Internet » ASP Clásico »

Subir Excel a SQL

Estas en el tema de Subir Excel a SQL en el foro de ASP Clásico en Foros del Web. Option Base 0 Option Explicit Private Sub K() Dim lngRow As Long Dim rst As ADODB.Recordset Sheets("Hoja2").Select Sheets("Hoja2").Range("A1").Select lngRow = 2 Set rst = New ...
  #1 (permalink)  
Antiguo 19/08/2003, 09:04
 
Fecha de Ingreso: julio-2003
Mensajes: 14
Antigüedad: 21 años, 9 meses
Puntos: 0
Subir Excel a SQL

Option Base 0
Option Explicit
Private Sub K()
Dim lngRow As Long
Dim rst As ADODB.Recordset
Sheets("Hoja2").Select
Sheets("Hoja2").Range("A1").Select
lngRow = 2
Set rst = New ADODB.Recordset
Set rst = GetRecordset("TRUNCATE TABLE tbl_Teléfonos")
Do
Set rst = GetRecordset("INSERT INTO tbl_Teléfonos VALUES( " & _
IIf(Sheets("Hoja2").Range("B" & lngRow).Value <> vbNullString, "'" & Trim(Sheets("Hoja2").Range("B" & lngRow).Value) & "'", "NULL") & ", '" & _
Trim(Sheets("Hoja2").Range("C" & lngRow).Value) & "', " & _
IIf(Trim(Sheets("Hoja2").Range("D" & lngRow).Value) <> vbNullString, "'" & Replace(Trim(Sheets("Hoja2").Range("D" & lngRow).Value), "'", "''") & "'", "NULL") & ", " & _
IIf(Trim(Sheets("Hoja2").Range("E" & lngRow).Value) <> vbNullString, Trim(Sheets("Hoja2").Range("E" & lngRow).Value), "NULL") & ", " & _
IIf(Trim(Sheets("Hoja2").Range("F" & lngRow).Value) <> vbNullString, Trim(Sheets("Hoja2").Range("F" & lngRow).Value), "NULL") & ", " & _
IIf(Trim(Sheets("Hoja2").Range("G" & lngRow).Value) <> vbNullString, Trim(Sheets("Hoja2").Range("G" & lngRow).Value), "NULL") & ", " & _
IIf(Trim(Sheets("Hoja2").Range("H" & lngRow).Value) <> vbNullString, "'" & Trim(Sheets("Hoja2").Range("H" & lngRow).Value) & "'", "NULL") & ", " & _
IIf(Trim(Sheets("Hoja2").Range("I" & lngRow).Value) <> vbNullString, Trim(Sheets("Hoja2").Range("I" & lngRow).Value), "NULL") & ", " & _
IIf(Trim(Sheets("Hoja2").Range("J" & lngRow).Value) <> vbNullString, Trim(Sheets("Hoja2").Range("J" & lngRow).Value), "NULL") & ", " & _
IIf(Trim(Sheets("Hoja2").Range("K" & lngRow).Value) <> vbNullString, "'" & Trim(Sheets("Hoja2").Range("K" & lngRow).Value) & "'", "NULL") & ", " & _
"'" & Trim(Sheets("Hoja2").Range("L" & lngRow).Value) & "', " & _
"'" & Trim(Sheets("Hoja2").Range("M" & lngRow).Value) & "' )")
Set rst = Nothing
lngRow = lngRow + 1
Loop Until Sheets("Hoja2").Range("A" & lngRow).Value = vbNullString
End Sub
Private Function GetRecordset(ByVal pstrSQLCommand As String) As ADODB.Recordset
'Ejecuta el elemento de SQL y regresa un juego de registros.
Dim cnnConnection As ADODB.Connection
Set cnnConnection = New ADODB.Connection
cnnConnection.ConnectionTimeout = 3
cnnConnection.CommandTimeout = 21
cnnConnection.CursorLocation = adUseClient
cnnConnection.Open "Provider = SQLOLEDB.1; Data Source = INTRANETBB; Initial Catalog = IntraNET; User ID = intranet; Password = permit"
Set GetRecordset = New ADODB.Recordset
Set GetRecordset.ActiveConnection = cnnConnection
GetRecordset.CursorLocation = adUseClient
GetRecordset.CursorType = adOpenDynamic
GetRecordset.LockType = adLockBatchOptimistic
GetRecordset.StayInSync = False
Debug.Print pstrSQLCommand
GetRecordset.Open pstrSQLCommand
Set GetRecordset.ActiveConnection = Nothing
cnnConnection.Close
Set cnnConnection = Nothing
End Function
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 11:26.