Documente Academic
Documente Profesional
Documente Cultură
Imports Microsoft.VisualBasic
Imports System
Imports System.Collections.Generic
Imports System.Text
Imports System.Data
Imports System.Data.Sql
Imports System.Data.SqlClient
Imports System.Data.SqlTypes
Namespace Contabilidad.data ' Nombre del Namespace como vamos a instancias nuestras paginas aspx
Public Class dbOpciones 'Creacion de la Clase dbOperaciones
Sub New()
End Sub
'Atributos de nuestra clase
Private _Database As String
Private _Delete_command As SqlCommand
Private _Insert_command As SqlCommand
Private _Password As String
Private _Select_Command As SqlCommand
Private _Server As String
Private _Update_command As SqlCommand
Private _UserId As String
Public [Error] As String
Public Property Database() As String ' Propiedades de la Clase para acceder desde las paginas aspx
Get
Return _Database
End Get
Set(ByVal value As String)
_Database = value
End Set
End Property
Public Property Delete_Command() As SqlCommand
Get
Return _Delete_command
End Get
Set(ByVal value As SqlCommand)
_Delete_command = value
End Set
End Property
Public Property Insert_Command() As SqlCommand
Get
Return _Insert_command
End Get
Set(ByVal value As SqlCommand)
_Insert_command = value
End Set
End Property
Public Property Password() As String
Get
Return _Password
End Get
Set(ByVal value As String)
_Password = value
End Set
End Property
Public Property Select_Command() As SqlCommand
Get
Return _Select_Command
End Get
Set(ByVal value As SqlCommand)
_Select_Command = value
End Set
End Property
Public Property Server() As String
Get
Return _Server
End Get
Set(ByVal value As String)
_Server = value
End Set
End Property
Public Property Update_command() As SqlCommand
Get
Return _Update_command
End Get
Set(ByVal value As SqlCommand)
_Update_command = value
End Set
End Property
Public Property UserId() As String
Get
Return _UserId
End Get
Set(ByVal value As String)
_UserId = value
End Set
End Property
'Metodos de nuestra calse
Public Function GetStringConection() As SqlConnection
' Return New SqlConnection("Data Source
=..\SQLEXPRESS;AttachDbFilename=C:\MODCONTABILIDAD\App_Data\Base.mdf;Integrated
Security=True;User Instance=True")
Return New SqlConnection("Data source=DESARROLLO;" & _
"Database= BASE.mdf;" & _
"User ID=sa;" & _
"Password=sa;" & _
"Persist Security Info=True")
End Function
'Métodos que interactúan directamente con la base de datos
'BUSQUEDA Y SELECCION (SELECT)
Public Function SelectFields() As DataTable
Dim strCon As String = Me.GetStringConection.ConnectionString
Dim ds As New DataSet
Dim oCon As New SqlConnection(strCon)
Dim da As New SqlDataAdapter(Me.Select_Command.CommandText, oCon)
Try
oCon.Open()
da.Fill(ds)
Catch ex As Exception
Me.Error = ex.ToString
Finally
oCon.Open()
End Try
Return ds.Tables.Item(0)
End Function
'INSERTAR (INSERT)
Public Function InsertFields() As Boolean
Dim success As Boolean
Dim oCon As New SqlConnection(Me.GetStringConection.ConnectionString)
Dim myCommand As New SqlCommand(Me.Insert_Command.CommandText, Me.GetStringConection)
Try
myCommand.Connection.Open()
myCommand.ExecuteNonQuery()
success = True
Catch ex As Exception
Me.Error = ex.ToString
success = False
Finally
oCon.close()
End Try
Return success
End Function
'ELIMINAR (DELETE)
Public Function DeleteFields() As Boolean
Dim success As Boolean
Dim oCon As New SqlConnection(Me.GetStringConection.ConnectionString)
Dim myCommand As New SqlCommand(Me.Delete_Command.CommandText, Me.GetStringConection)
Try
myCommand.Connection.Open()
myCommand.ExecuteNonQuery()
success = True
Catch ex As Exception
Me.Error = ex.ToString
success = False
Finally
oCon.Close()
End Try
Return success
End Function
'ACTUALIZAR (UPDATE)
Public Function UpdateFields() As Boolean
Dim success As Boolean
Dim oCon As New SqlConnection(Me.GetStringConection.ConnectionString)
Dim myCommand As New SqlCommand(Me.Update_command.CommandText, Me.GetStringConection)
Try
myCommand.Connection.Open()
myCommand.ExecuteNonQuery()
success = True
Catch ex As Exception
Me.Error = ex.ToString
success = False
Finally
oCon.close()
End Try
Return success
End Function
End Class
End Namespace