120 lines
3.3 KiB
VB.net
120 lines
3.3 KiB
VB.net
Public Class Command
|
|
'declaraciòn de conexiòn a la BD
|
|
Public cn As New SqlClient.SqlConnection()
|
|
'declaraciòn de comando SQL
|
|
Public cm As New SqlClient.SqlCommand()
|
|
Public cnString As String
|
|
'Decalracion commandText
|
|
Public spsql As String
|
|
'Nuemro de regitrs que lee
|
|
Public Datos As Integer
|
|
'Declaro DataReader
|
|
Public dtReader As SqlClient.SqlDataReader
|
|
'Declaracion de SqlDataAdapter
|
|
Private daSelect As New SqlClient.SqlDataAdapter()
|
|
'Tabla Combo
|
|
Private dtCombo As New DataTable()
|
|
|
|
Public Sub sbGuardaModifica(ByVal SQL As String)
|
|
sbConectaBD()
|
|
cm.Connection = dmModulo.SqlConnection
|
|
cm.CommandText = SQL
|
|
cm.ExecuteNonQuery()
|
|
sbCierraCn()
|
|
End Sub
|
|
Public Sub sbConectaBD()
|
|
'realiza la conexiòn a la BD
|
|
Try
|
|
cn.ConnectionString = dmModulo.SqlConnection.ConnectionString
|
|
cn.Open()
|
|
Catch er As Exception
|
|
MsgBox("No se pudo establecer la conexion al servidor. Clase Command " & er.Message)
|
|
End Try
|
|
|
|
End Sub
|
|
|
|
Public Sub sbCierraCn()
|
|
'cierra la conexiòn a la BD
|
|
cn.Close()
|
|
End Sub
|
|
|
|
Public Function Count(ByVal SQL As String) As Integer
|
|
cm.Connection = dmModulo.SqlConnection
|
|
cm.CommandText = SQL
|
|
'MsgBox("Inicio! " & SQL & " fin!")
|
|
dtReader = cm.ExecuteReader
|
|
dtReader.Read()
|
|
Datos = CType(dtReader("Numero"), Integer)
|
|
dtReader.Close()
|
|
Return Datos
|
|
|
|
End Function
|
|
Public Function Lee(ByVal SQL As String) As Integer
|
|
Try
|
|
cm.Connection = dmModulo.SqlConnection
|
|
cm.CommandText = SQL
|
|
dtReader = cm.ExecuteReader
|
|
dtReader.Read()
|
|
Catch Ex As Exception
|
|
MessageBox.Show(Ex.Message)
|
|
End Try
|
|
|
|
|
|
End Function
|
|
Public Function SeleccionCombo(ByVal SQL As String, ByVal Tabla As DataTable) As DataTable
|
|
Try
|
|
Tabla.Clear()
|
|
Catch
|
|
|
|
End Try
|
|
Try
|
|
|
|
cm.Connection = dmModulo.SqlConnection
|
|
cm.CommandText = SQL
|
|
daSelect.SelectCommand = cm
|
|
daSelect.Fill(Tabla)
|
|
daSelect.SelectCommand.Dispose()
|
|
daSelect.Dispose()
|
|
|
|
Catch e As Exception
|
|
MessageBox.Show(e.Message)
|
|
|
|
|
|
End Try
|
|
Return Tabla
|
|
End Function
|
|
Public Function SeleccionGrid(ByVal SQL As String, ByVal Tabla As DataTable) As DataTable
|
|
Try
|
|
Tabla.Clear()
|
|
Catch
|
|
|
|
End Try
|
|
Try
|
|
cm.Connection = dmModulo.SqlConnection
|
|
cm.CommandTimeout = 0
|
|
cm.CommandText = SQL
|
|
daSelect.SelectCommand = cm
|
|
daSelect.Fill(Tabla)
|
|
daSelect.SelectCommand.Dispose()
|
|
daSelect.Dispose()
|
|
Catch e As Exception
|
|
MessageBox.Show(e.Message)
|
|
End Try
|
|
|
|
Return Tabla
|
|
End Function
|
|
|
|
Public Function Ejecuta(ByVal SQL As String) As Integer
|
|
Try
|
|
cm.Connection = dmModulo.SqlConnection
|
|
cm.CommandText = SQL
|
|
daSelect.SelectCommand = cm
|
|
cm.ExecuteNonQuery()
|
|
daSelect.SelectCommand.Dispose()
|
|
daSelect.Dispose()
|
|
Catch Ex As Exception
|
|
MessageBox.Show(Ex.Message)
|
|
End Try
|
|
End Function
|
|
End Class
|