Advertisement
Guest User

Untitled

a guest
Jun 19th, 2019
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.50 KB | None | 0 0
  1. Dim objCon As ADODB.Connection
  2.  
  3. Sub Conectar()
  4. Set objCon = New ADODB.Connection
  5. objCon.ConnectionString = "driver={PostgreSQL Unicode(x64)};server=localhost;database=Nomina;port=5432;uid=nolberto;pwd=nolberto;"
  6. objCon.Open
  7. Debug.Print "Conectado..."
  8. End Sub
  9.  
  10. Sub CloseConnection()
  11. On Error Resume Next
  12. objCon.Close
  13. Debug.Print "coneccion cerrada..."
  14. Set objCon = Nothing
  15. On Error GoTo 0
  16. End Sub
  17.  
  18. Sub Insertar()
  19. strSQL = "INSERT INTO empleados(nombre, apellido_pat, apellido_Mat, fecha_alta,fecha_nac, email, telefono, sueldo, empresa) " & _
  20. "Values('Maria', 'Perez', 'Armenta', '21-06-2011', '12-03-1994', 'maria@test.com', '66778365', '12000', 2)"
  21. objCon.Execute strSQL
  22. End Sub
  23.  
  24. Sub Actualizar()
  25. strSQL = "UPDATE Alumnos SET Nombre= 'Ruben' WHERE ID=4"
  26. objCon.Execute strSQL
  27. End Sub
  28.  
  29. Sub Eliminar()
  30. strSQL = "DELETE FROM Alumnos WHERE ID=5"
  31. objCon.Execute strSQL
  32. End Sub
  33.  
  34. Sub Consulta()
  35. Dim fila, column As Long
  36. Dim miRango As Range
  37.  
  38. fila = 0
  39. column = 0
  40. strSQL = "SELECT * FROM Empleados"
  41. Set objRecordSet = New ADODB.Recordset
  42. objRecordSet.Open strSQL, objCon
  43. 'imprime etiquetas
  44. ThisWorkbook.Sheets(1).Range("A1").Activate
  45. For Each objField In objRecordSet.Fields
  46. ActiveCell.Offset(fila, column).Value = objField.Name
  47. column = column + 1
  48. Next
  49. Set miRango = ThisWorkbook.Sheets(1).Range("A2")
  50. miRango.CopyFromRecordset objRecordSet
  51. Range("A1").CurrentRegion.EntireColumn.AutoFit
  52. End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement