En la Capa de Acceso a Datos
Imports System.Data.SqlClient
Public Class Conexion
Dim objConexion As New SqlConnection(Configuration.ConfigurationManager.ConnectionStrings("connectionString").ConnectionString)
Public Function ObtenerDatos(ByVal strConsulta As String) As DataTable
Dim dt As New DataTable
Dim da As New SqlDataAdapter(strConsulta, objConexion)
Dim ds As New DataSet
objConexion.Open()
da.Fill(ds)
objConexion.Close()
dt = ds.Tables(0)
Return dt
End Function
Public Sub RealizarComando(ByVal strConsulta As String)
Dim objComando As New SqlCommand(strConsulta, objConexion)
Dim iResultado As Integer
objConexion.Open() ' abrir conexión
iResultado = objComando.ExecuteNonQuery() ' ejecutar comando
objConexion.Close() ' cerrar conexión
End Sub
End Class
En la Capa de Negocios
Public Class Producto
Protected strNombreProducto As String
Protected intExistencia As Integer
Protected dblPrecio As Double
Public Property NombreProducto() As String
Get Return (strNombreProducto)
End Get
Set(ByVal Value As String)
strNombreProducto = Value
End Set
End Property
Public Property Existencia() As String
Get Return (intExistencia)
End Get
Set(ByVal Value As String)
intExistencia = Value
End Set
End Property
Public Property Precio() As String
Get Return (dblPrecio)
End Get
Set(ByVal Value As String)
dblPrecio= Value
End Set
End Property
End Class
En la Capa de Presentación
Imports BLL
Partial Class Formularios_wfProducto
Inherits System.Web.UI.Page
Dim _objProducto As New Producto
Dim _objConexion As New DAL.Conexion
Private Sub GuardarProducto()
Dim strConsulta As String = Nothing
_objProducto.NombreProducto = txtNombre.Text
_objProducto.Existencia = CInt(txtExistencia.Text)
_objProducto.Precio = CDbl(txtPrecio.Text)
With _objProducto
strConsulta = String.Format("EXEC SpInsertarProducto '{0}',{1},{2}", .NombreProducto, .Existencia, .Precio)
End With
_objConexion.RealizarComando(strConsulta)
End Sub
Private Sub CargarProducto()
Dim dt As Data.DataTable = _objConexion.ObtenerDatos("SELECT * FROM Producto")
grdReja.DataSource = dt
grdReja.DataBind()
End Sub
End Class
No hay comentarios.:
Publicar un comentario