Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
CONOCIMIENTO
AP04 - AA08 EV3
Descripcin breve
Establecer niveles de servicio de acuerdo con los requerimientos de la organizacin.
Luego de haber diligenciado la base de datos en MS SQL Server, se procede con la realizacin
del formulario, agregando la parte grfica y de control de este. Est compuesto por cinco (5) que
permiten manipular el contenido de la base de datos de conocimiento.
El script detallado anteriormente, inicialmente crea la conexin con el servidor de MS SQL Server
especificando la base de datos y tabla que se desea manipular, adems se especifican las
credenciales para confirmar el acceso a esta. A manera de verificacin, se diligencian los valores
desde la celda A2 hasta la celda J2.
Figura 3. Agregar registro a la KB
De igual manera se puede validar dicho resultado, realizando una consulta desde MS SQL Server
como se observa en la siguiente figura.
Figura 5. Verificacin registro agregado MS SQL Server.
El siguiente botn de control est relacionado con la eliminacin de registros, para lo cual se
emplea el siguiente script desde MS Excel:
Sub DeleteFromSQLServer()
Application.ScreenUpdating = False
Range("A3:A8").EntireRow.Select
Selection.ClearContents
Range("A10:A800").EntireRow.Select
Selection.ClearContents
Dim SQLServerToExcel As ADODB.Connection
Dim SQLSentence As ADODB.Recordset
Set SQLServerToExcel = New ADODB.Connection
Set SQLSentence = New ADODB.Recordset
SQLServerToExcel.ConnectionString = "Driver={SQL Server}; Server=(local); uid=sa; pwd=sena;
database=SENA.ESP.DB.KB"
SQLServerToExcel.ConnectionTimeout = 30
SQLServerToExcel.Open
If Not Range("A2") = 0 Then
Set SQLSentence = SQLServerToExcel.Execute("Delete from INCIDENT_REPORT Where
Numero_Incidencia = " & Range("A2"))
GoTo ShowAllRecords
End If
If Not Range("B2") = 0 Then
Set SQLSentence = SQLServerToExcel.Execute("Delete from INCIDENT_REPORT Where
Numero_Incidencia = " & Range("B2"))
GoTo ShowAllRecords
End If
If Not Range("C2") = 0 Then
Set SQLSentence = SQLServerToExcel.Execute("Delete from INCIDENT_REPORT Where
Numero_Incidencia = " & Range("C2"))
GoTo ShowAllRecords
End If
If Not Range("D2") = 0 Then
Set SQLSentence = SQLServerToExcel.Execute("Delete from INCIDENT_REPORT Where
Numero_Incidencia = " & Range("D2"))
GoTo ShowAllRecords
End If
If Not Range("E2") = 0 Then
Set SQLSentence = SQLServerToExcel.Execute("Delete from INCIDENT_REPORT Where
Numero_Incidencia = " & Range("E2"))
GoTo ShowAllRecords
End If
If Not Range("F2") = 0 Then
Set SQLSentence = SQLServerToExcel.Execute("Delete from INCIDENT_REPORT Where
Numero_Incidencia = " & Range("F2"))
GoTo ShowAllRecords
End If
If Not Range("G2") = 0 Then
Set SQLSentence = SQLServerToExcel.Execute("Delete from INCIDENT_REPORT Where
Numero_Incidencia = " & Range("G2"))
GoTo ShowAllRecords
End If
If Not Range("H2") = 0 Then
Set SQLSentence = SQLServerToExcel.Execute("Delete from INCIDENT_REPORT Where
Numero_Incidencia = " & Range("H2"))
GoTo ShowAllRecords
End If
If Not Range("I2") = 0 Then
Set SQLSentence = SQLServerToExcel.Execute("Delete from INCIDENT_REPORT Where
Numero_Incidencia = " & Range("I2"))
GoTo ShowAllRecords
End If
If Not Range("J2") = 0 Then
Set SQLSentence = SQLServerToExcel.Execute("Delete from INCIDENT_REPORT Where
Numero_Incidencia = " & Range("J2"))
GoTo ShowAllRecords
End If
Range("A2").Select
Exit Sub
El script detallado anteriormente, se encarga de eliminar registros, para el cual se debe
especificar alguno de los criterios de bsqueda. A manera de ensayo se realiza la eliminacin del
registro anteriormente almacenado en la KB.
Esto puede ser validado desde MS SQL Server, realizando la consulta sobre la tabla relacionada
con la KB, validando la eliminacin del registro utilizando los controles en MS Excel.
El siguiente control est relacionado con la bsqueda de registros en la KB, el script asociado a
este botn es descrito a continuacin.
Sub SearchInSQLServer()
Application.ScreenUpdating = False
Range("A3:A8").EntireRow.Select
Selection.ClearContents
Range("A10:A800").EntireRow.Select
Selection.ClearContents
Dim SQLServerToExcel As ADODB.Connection
Dim SQLSentence As ADODB.Recordset
Set SQLServerToExcel = New ADODB.Connection
Set SQLSentence = New ADODB.Recordset
SQLServerToExcel.ConnectionString = "Driver={SQL Server}; Server=(local); uid=sa; pwd=sena;
database=SENA.ESP.DB.KB"
SQLServerToExcel.ConnectionTimeout = 30
SQLServerToExcel.Open
If Not Range("A2") = 0 Then
Set SQLSentence = SQLServerToExcel.Execute("Select * from INCIDENT_REPORT Where
Numero_Incidencia = " & Range("A2"))
ActiveSheet.Range("A10").CopyFromRecordset SQLSentence
GoTo ShowAllRecords
End If
If Not Range("B2") = 0 Then
Set SQLSentence = SQLServerToExcel.Execute("Select * from INCIDENT_REPORT Where
Fecha_Recibido = '" & Range("B2") & "'")
ActiveSheet.Range("A10").CopyFromRecordset SQLSentence
GoTo ShowAllRecords
End If
If Not Range("C2") = 0 Then
Set SQLSentence = SQLServerToExcel.Execute("Select * from INCIDENT_REPORT Where
Descripcion_Problema = '" & Range("C2") & "'")
ActiveSheet.Range("A10").CopyFromRecordset SQLSentence
GoTo ShowAllRecords
End If
If Not Range("D2") = 0 Then
Set SQLSentence = SQLServerToExcel.Execute("Select * from INCIDENT_REPORT Where
Prioridad = '" & Range("D2") & "'")
ActiveSheet.Range("A10").CopyFromRecordset SQLSentence
GoTo ShowAllRecords
End If
Adicionalmente se cuenta con un control que se encarga de mostrar todos los registros que se
encuentran en la KB, cuyo script relacionado es detallado a continuacin:
Sub ExtractDataFromSQLServer()
Application.ScreenUpdating = False
Range("A3:A8").EntireRow.Select
Selection.ClearContents
Range("A10:A800").EntireRow.Select
Selection.ClearContents
Dim SQLServerToExcel As ADODB.Connection
Dim SQLSentence As ADODB.Recordset
Set SQLServerToExcel = New ADODB.Connection
Set SQLSentence = New ADODB.Recordset
SQLServerToExcel.ConnectionString = "Driver={SQL Server}; Server=(local); uid=sa; pwd=sena;
database=SENA.ESP.DB.KB"
SQLServerToExcel.ConnectionTimeout = 30
SQLServerToExcel.Open
Set SQLSentence = SQLServerToExcel.Execute("SELECT * FROM INCIDENT_REPORT;")
ActiveSheet.Range("A10").CopyFromRecordset SQLSentence
Range("A2").Select
Application.CutCopyMode = False
SQLSentence.Close
Set SQLServerToExcel = Nothing
Set SQLSentence = Nothing
End Sub
Una vez el botn Mostrar Todo es seleccionado, todos los registros presentes en la KB son
exportados hacia MS Excel como se observa en la siguiente figura.
Figura 9. Mostrar Todo
Finalmente, se cuenta con un botn que se encarga de limpiar la ventana de bsqueda, para lo
cual se emplea el siguiente script:
Sub ClearSearch()
Application.ScreenUpdating = False
Range("A2:A8").EntireRow.Select
Selection.ClearContents
Range("A10:A800").EntireRow.Select
Selection.ClearContents
Range("A2").Select
End Sub