Sie sind auf Seite 1von 6

DESARROLLO Y APLICACIN DE WINDOWS

ALUMNO: GARCIA NEIRA, LUIS

APLICACIN 1:

LISTADO DE MARCAS CON IMAGEN

Imports System.Data.SqlClient Public Class FrmMarcas_Listado Sub ConfiguraTabla() dgvlista.Columns(0).Width = 100 dgvlista.Columns(1).Width = 200 dgvlista.Columns(2).Visible = False End Sub Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load Dim cn As New SqlConnection cn.ConnectionString = "data source=.;initial catalog=ORION;uid=sa;pwd=123" cn.Open()

Enviar Solicitudes Dim SQL As String = "SELECT * From Marcas order by NOMBRE" Dim da As New SqlDataAdapter(SQL, cn) Obtener resultados en memoria Dim dt As New DataTable da.Fill(dt) Cerrar la conexion cn.Close() Mostrar la informacin en el datagridview dgvlista.DataSource = dt ConfiguraTabla() End Sub Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click Me.Close() End Sub 'Mostrar la imagen desde el dato de la tabla oculta Private Sub dgvlista_SelectionChanged(sender As Object, e As EventArgs) Handles dgvlista.SelectionChanged Dim fila As Integer = dgvlista.CurrentRow.Index Dim Imagen As String = dgvlista.Item(2, fila).Value picImagen.Image = Image.FromFile("C:\imagen\" + Imagen)

End Sub End Class

APLICACION2:

BUSQUEDA DE PRODUCTO POR CODIGO

Imports System.Data.SqlClient Public Class FrmProductos_Buscar Private cn As SqlConnection Private Function Conectar() As SqlConnection Try cn = New SqlConnection cn.ConnectionString = "data source=.;initial catalog=ORION;uid=sa;pwd=123" cn.Open() Return cn Catch ex As Exception Return Nothing End Try End Function Private Sub BuscarProducto(codigo As String) cn = Conectar() Dim Sql As String = " Select * from productos where codigo = '" + codigo + "' " Dim da As New SqlDataAdapter(Sql, cn) ( COMO ES STRING) Dim dt As New DataTable da.Fill(dt) cn.Close() If dt.Rows.Count > 0 Then lblcategoria.Text = dt.Rows(0).Item(1) lbldetalle.Text = dt.Rows(0).Item(3) lblstock.Text = dt.Rows(0).Item(5) lblprecio.Text = dt.Rows(0).Item(6) Else MessageBox.Show("no se encuentra el producto") lblcategoria.Text = "" lbldetalle.Text = "" lblstock.Text = "" lblprecio.Text = "" txtcodigo.Focus() End If

End Sub Private Sub btncerrar_Click(sender As Object, e As EventArgs) Handles btncerrar.Click Me.Close() End Sub Private Sub btnbuscar_Click(sender As Object, e As EventArgs) Handles btnbuscar.Click

BuscarProducto(txtcodigo.Text) End Sub End Class

APLICACION 3
1) ClsDistrito:
Public Class clsDistrito Private _DistritoId As Integer Private _Nombre As String Public Property DistritoId() As Integer Get Return _DistritoId End Get Set(ByVal value As Integer) _DistritoId = value End Set End Property Public Property Nombre() As String Get Return _Nombre End Get Set(ByVal value As String) _Nombre = value End Set End Property End Class

2) En el Form1 codificamos la Conexin y los mtodos: 3)


Imports System.Data.SqlClient Public Class Form1 Private cn As SqlConnection Private Function conectar() As SqlConnection cn = New SqlConnection Try cn.ConnectionString = "date source=.;initial catalog=ORION;uid=sa;pwd=123" cn.Open() Return cn Catch ex As Exception Return Nothing End Try End Function Private Function Listado() As DataTable Try cn = conectar() Dim da As New SqlDataAdapter Dim dt As New DataTable Dim cm As New SqlCommand cm.Connection = cn cm.CommandType = CommandType.Text cm.CommandText = "Select * from Distritos" da.SelectCommand = cm da.Fill(dt) cn.Close() Return dt Catch ex As Exception Return Nothing End Try

End Function Private Function Buscar(id As Integer) As clsDistrito Try cn = conectar() Dim dr As SqlDataReader Dim cm As New SqlCommand cm.Connection = cn cm.CommandType = CommandType.Text cm.CommandText = "Select * from Distritos Where DistritoID=@valor" cm.Parameters.AddWithValue("@valor", id) dr = cm.ExecuteReader Dim obj As New clsDistrito If dr.HasRows Then While dr.Read obj.DistritoId = dr.Item(0) obj.Nombre = dr.Item(1) End While End If cn.Close() Return obj Catch ex As Exception Return Nothing End Try End Function Private Sub ConfiguraTabla() dgvlista.Columns(0).Width = 80 dgvlista.Columns(1).Width = 150 End Sub Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load Listado() ConfiguraTabla() Me.Height = 450 End Sub Private Sub btnbuscar_Click(sender As Object, e As EventArgs) Handles btnbuscar.Click Dim valor As Integer = InputBox("DistritoID:") Try Dim obj As clsDistrito = Buscar(valor) If obj Is Nothing Then MessageBox.Show("no se encontro el valor") Else txtid.Text = obj.DistritoId txtnombre.Text = obj.Nombre Me.Height = 500 End If Catch ex As Exception MessageBox.Show(" error al realizar la busqueda ") End Try End Sub End Class

Das könnte Ihnen auch gefallen