Visual Basic.NET - LIBRERIA

   
Vista:

LIBRERIA

Publicado por OLBAP28 (5 intervenciones) el 09/11/2007 12:09:59
Hola
He conseguido esta librería en la sección de código fuente de esta pagina y no se como usarla
Os paso la parte que me interesa

Public Class SQLSvr
Inherits BaseConfig

Private mServer As String
Private mUser As String
Private mPass As String
Private mDb As String

Private WithEvents __cnx As SqlConnection
Private mCmd As SqlCommand

Public WithEvents Adapter As SqlDataAdapter
Public Param As SqlParameter
Public Event SQLError(ByVal Numero As Integer, ByVal Descripcion As String)
Public Sub New(ByVal sServer As String, ByVal sUser As String, ByVal sPass As String, ByVal sDatabase As String)
Try

MyBase.Server = sServer ''ESTO LO SACA DE OTRA CLASE
MyBase.User = sUser
MyBase.Pass = sPass
MyBase.Database = sDatabase

__cnx = New SqlConnection
__cnx.ConnectionString = _
"Server=" & sServer & ";" & _
"User Id=" & sUser & ";" & _
"Pwd=" & sPass & ";" & _
"Database=" & sDatabase

__cnx.Open()
Call Conectar()
Catch SqlEx As SqlException
RaiseEvent SQLError(Err.Number, SqlEx.ToString)
Catch ex As Exception
RaiseEvent SQLError(Err.Number, ex.ToString)
End Try
End Sub

Public Sub Destroy()
MyBase.Finalize()
End Sub

Protected Overrides Sub Finalize()
MyBase.Finalize()
End Sub

Public ReadOnly Property State() As System.Data.ConnectionState
Get
Return __cnx.State
End Get
End Property

Public Sub Close()
If __cnx.State <> ConnectionState.Closed Then __cnx.Close()
End Sub

Public Sub Conectar()
Static Reintento As Integer = 0

Try

If __cnx.State <> ConnectionState.Open Then

Reintento += 1
If Reintento < 3 Then
Call Close()
__cnx.Open()
Else
Reintento = 0
Throw New Exception("Ocurrió un error al intentar conectar a la base de datos")
End If
End If
Catch SqlEx As SqlException
If Reintento < 3 Then
Call Conectar()
Else
RaiseEvent SQLError(Err.Number, SqlEx.ToString)
End If
Catch ex As Exception
RaiseEvent SQLError(Err.Number, ex.ToString)
End Try
End Sub

Public Sub PrepareProcedure(ByVal sProcName As String)
Try
mCmd = New SqlCommand
mCmd.Connection = __cnx
mCmd.CommandText = sProcName
mCmd.CommandType = CommandType.StoredProcedure
Catch SqlEx As SqlException
RaiseEvent SQLError(Err.Number, SqlEx.ToString)
Catch ex As Exception
RaiseEvent SQLError(Err.Number, ex.ToString)
End Try
End Sub

Public Sub AddParameter()
Try
mCmd.Parameters.Add(Param)
Param = Nothing
Catch SqlEx As SqlException
RaiseEvent SQLError(Err.Number, SqlEx.ToString)
Catch ex As Exception
RaiseEvent SQLError(Err.Number, ex.ToString)
End Try
End Sub

Public Function ExecProcedure(ByVal nParams As Integer, ByVal ParamArray Params() As Object) As Object
Try
Dim i As Integer
Dim RetVal As Object

For i = 1 To nParams - 1
mCmd.Parameters(i).Value = Params(i)
Next
mCmd.Prepare()
mCmd.ExecuteNonQuery()
RetVal = mCmd.Parameters(0).Value
mCmd.Dispose()
Return RetVal

Catch SqlEx As SqlException
RaiseEvent SQLError(Err.Number, SqlEx.ToString)
Catch ex As Exception
RaiseEvent SQLError(Err.Number, ex.ToString)
End Try
End Function
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder