Private m_CadenaConexion As String = "Data Source=.\SQLEXPRESS;" _
& "Initial Catalog=futbol;" _
& "Integrated Security=SSPI;" _
& "Connect TimeOut=30"
Private Function DimeCadenaConexion() As String
DimeCadenaConexion = m_CadenaConexion
End Function
Private Sub OpenConexionDB(ByVal cn As SqlConnection)
cn.ConnectionString = DimeCadenaConexion()
cn.Open()
End Sub
Private Sub CloseConexionDB(ByVal cn As SqlConnection)
cn.Close()
cn.Dispose()
End Sub
'-------------------------------------------------------------------------------------------------------------------------
Public Function ExecuteSql(ByVal Sql As String) As Integer
Dim cn As New SqlConnection
Try
OpenConexionDB(cn)
Dim SqlCmd As New SqlCommand(Sql, cn)
Dim res As Integer = SqlCmd.ExecuteNonQuery()
CloseConexionDB(cn)
ExecuteSql = res
Catch ex As Exception
MsgBox(ex.Message)
ExecuteSql = -1
End Try
End Function
Public Function GetDataSet(ByVal Sql As String, ByVal sTableName As String) As DataSet
Dim cn As New SqlConnection
Dim da As SqlDataAdapter
Dim ds As New DataSet
Dim dt As New DataTable
Try
OpenConexionDB(cn)
da = New SqlDataAdapter(Sql, cn)
da.Fill(dt)
dt.TableName = sTableName
ds.Tables.Add(dt)
GetDataSet = ds
CloseConexionDB(cn)
Catch ex As Exception
MsgBox(ex.Message)
GetDataSet = Nothing
End Try
End Function
Public Sub SetDataSet(ByVal sTableName As String, ByVal ds As DataSet)
Dim cn As New SqlConnection
Dim da As SqlDataAdapter
Dim cb As SqlCommandBuilder
Try
OpenConexionDB(cn)
Dim Sql As String = "SELECT TOP 0 * FROM " & sTableName
da = New SqlDataAdapter(Sql, cn)
cb = New SqlCommandBuilder(da)
da.Update(ds, sTableName)
CloseConexionDB(cn)
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
Suscribirse a:
Entradas (Atom)
VBA Access. Redondeo de números decimales con el método medio redondeo. Alternativa a la función Round (bankers round)
Private Function Redondeo(ByVal Numero As Variant, ByVal Decimales As Integer) As Double 'Aplica método medio redondeo (half round ...
-
Option Compare Database Option Explicit '***************************** ' 'Ejemplo de uso ' 'selecciona 1 ficher...
-
Option Compare Database Option Explicit 'Zip / UnZip file or folder 'http://www.codekabinett.com/rdumps.php?Lang=2&targetDoc...