0% found this document useful (0 votes)
46 views8 pages

Plantilla de Visual Basic

This document contains code for multiple forms that are used to manage a database using ADO.NET and SQL Server. The forms allow selecting, inserting, updating and displaying data across multiple tables in a database for tasks like managing products, customers and invoices. The forms are connected to database tables and use data adapters and datasets to populate controls and handle data operations like searching, sorting and filtering of records.

Uploaded by

Rey Dy
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
46 views8 pages

Plantilla de Visual Basic

This document contains code for multiple forms that are used to manage a database using ADO.NET and SQL Server. The forms allow selecting, inserting, updating and displaying data across multiple tables in a database for tasks like managing products, customers and invoices. The forms are connected to database tables and use data adapters and datasets to populate controls and handle data operations like searching, sorting and filtering of records.

Uploaded by

Rey Dy
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 8

Clase 1

Imports System.Data Imports System.Data.SqlClient Public Class Form1 Dim cn As New SqlConnection("server (local!"Data#ase #DFAC$%&A"Inte'rate( Security true"! Private Sub #tnSalir)Clic*(#y+al sen(er As System.,b-ect. #y+al e As System./ventAr's! 0an(les #tnSalir.Clic* /n( /n( Sub Public Sub mostrar(#y+al ca(sql As Strin'! Dim (t As New Data$able Dim (a As New SqlDataA(apter(ca(sql. cn! (a.Fill((t! 1llenar (atable Data2ri(+iew1.DataSource (t (a.Dispose(! 13ibera ob-etos (t.Dispose(! /n( Sub Private Sub Form1)3oa((#y+al sen(er As System.,b-ect. #y+al e As System./ventAr's! 0an(les 4y#ase.3oa( Dim ca(sql As Strin' "select 5 6rom articulos" $ry Call mostrar(ca(sql! 1llamar al meto(o Catc7 8 As System.Data.SqlClient.Sql/8ception Select Case 8./rrorCo(e Case 9:;: < 4essa'e#o8.S7ow("#ase (e (atos invali(a"! Case 1=;. 1>: < 4essa'e#o8.S7ow("/rror (e sinta8is"! Case 1> < 4essa'e#o8.S7ow("Servi(or invali(o"! /n( Select /n( $ry /n( Sub Private Sub &(nAsc)C7ec*e(C7an'e((#y+al sen(er As System.,b-ect. #y+al e As System./ventAr's! 0an(les &(nAsc.C7ec*e(C7an'e( Dim ca(sql As Strin' "select 5 6rom articulos or(er by art)nombre asc" Call mostrar(ca(sql! 1llamar al meto(o /n( Sub Private Sub &(nDes)C7ec*e(C7an'e((#y+al sen(er As System.,b-ect. #y+al e As System./ventAr's! 0an(les &(nDes.C7ec*e(C7an'e(

Dim ca(sql As Strin' "select 5 6rom articulos or(er by art)nombre (esc" Call mostrar(ca(sql! 1llamar al meto(o /n( Sub Private Sub #utton1)Clic*(#y+al sen(er As System.,b-ect. #y+al e As System./ventAr's! 0an(les #utton1.Clic* Dim ca(sql As Strin' "select top = 5 6rom articulos or(er by art)precio (esc" Call mostrar(ca(sql! 1llamar al meto(o /n( Sub Private Sub #tnS't)Clic*(#y+al sen(er As System.,b-ect. #y+al e As System./ventAr's! 0an(les #tnS't.Clic* Form?.S7ow(! /n( Sub /n( Class

Imports System.Data Imports System.Data.SqlClient Public Class Form? Dim cn As New SqlConnection("Server (local!" Data#ase #DFAC$%&A" Inte'rate( Security true"! Public Sub 3impiar(! Dim 8 As Control For /ac7 8 In 4e.Controls I6 $ype,6 8 Is $e8t#o8 $7en 8.$e8t "" 8.#ac*Color Color.#lac* /n( I6 Ne8t /n( Sub Private Sub Form?)3oa((#y+al sen(er As System.,b-ect. #y+al e As System./ventAr's! 0an(les 4y#ase.3oa( Call 3impiar(! $e8t#o81.Focus(!

/n( Sub Private Sub btn#uscar)Clic*(#y+al sen(er As System.,b-ect. #y+al e As System./ventAr's! 0an(les btn#uscar.Clic* Dim (t As New Data$able Dim ca(sql As Strin' "select 5 6rom articulos w7ere art)co(i'o 1" @ 4e.$e8t#o81.$e8t @ "1" Dim nr As IntA? 1In(ica la canti(a( (e re'istros $ry Dim (a As New SqlDataA(apter(ca(sql. cn! (a.Fill((t! nr (t.&ows.Count 1canti(a( (e re'istros I6 nr B : $7en 4e.$e8t#o8?.$e8t (t.&ows(:!(1! 1Fila 1 col 1 4e.$e8t#o8A.$e8t (t.&ows(:!(?! 4e.$e8t#o89.$e8t (t.&ows(:!(A!.$oStrin' 4e.$e8t#o8=.$e8t (t.&ows(:!(9!.$oStrin' /lse 4essa'e#o8.S7ow("/rror". "Co(i'o no e8iste". 4essa'e#o8#uttons.,C. 4essa'e#o8Icon./rror! Call 3impiar(! $e8t#o81.Focus(! /n( I6 Catc7 e8 As /8ception 4essa'e#o8.S7ow("/rrorDDD" @ e8.4essa'e! /n( $ry /n( Sub Private Sub btnContinuar)Clic*(#y+al sen(er As System.,b-ect. #y+al e As System./ventAr's! 0an(les btnContinuar.Clic* Call 3impiar(! $e8t#o81.Focus(! /n( Sub Private Sub #utton1)Clic*(#y+al sen(er As System.,b-ect. #y+al e As System./ventAr's! 0an(les #utton1.Clic* FormA.S7ow(! /n( Sub /n( Class

Imports System.Data Imports System.Data.SqlClient

Public Class FormA Dim cn As New SqlConnection("Server (local!"Data#ase #DFAC$%&A" Inte'rate( Security true"! Private Sub FormA)3oa((#y+al sen(er As System.,b-ect. #y+al e As System./ventAr's! 0an(les 4y#ase.3oa( Dim (s As New DataSet Dim ca(sql As Strin' "Select cli)co(i'o. cli)nombre 6rom Clientes" $ry Dim (a As New SqlDataA(apter(ca(sql. cn! (a.Fill((s. "Clientes"! 1+inculan(o el ori'en (e (atos al control 4e.3ist#o81.DataSource (s.$ables("Clientes"! 4e.3ist#o81.Display4ember "Cli)nombre" 4e.3ist#o81.+alue4ember "Cli)co(i'o" Catc7 e8 As /8ception /n( $ry /n( Sub /n( Class

Clase 2:

Imports System.Data Imports System.Data.SqlClient Public Class Form1 Dim cn As New SqlConnection("Server (local!" (atabase #DFAC$%&A"" Inte'rate( Security true"! Dim (s As New DataSet Private Sub Form1)3oa((#y+al sen(er As System.,b-ect. #y+al e As System./ventAr's! 0an(les 4y#ase.3oa( $ry Dim ca(sql "select cli)co(i'o. cli)nombre 6rom clientes" Dim (a As New SqlDataA(apter(ca(sql. cn! (a.Fill((s. "clientes"! Combo#o81.DataSource (s.$ables("clientes"! Combo#o81.Display4ember "cli)nombre"

Combo#o81.+alue4ember "cli)co(i'o" Catc7 e8 As /8ception 4essa'e#o8.S7ow(e8.4essa'e! /n( $ry /n( Sub Private Sub Combo#o81)Selecte(In(e8C7an'e((#y+al sen(er As System.,b-ect. #y+al e As System./ventAr's! 0an(les Combo#o81.Selecte(In(e8C7an'e( $ry Dim ca(sql1 As Strin' "select 5 6rom 6ac)cabe w7ere cli)co(i'o 1" @ 4e.Combo#o81.Selecte(+alue @ "1" Dim ca(sql? As Strin' "select cli)tele6ono. cli)ruc 6rom clientes w7ere cli)co(i'o 1" @ 4e.Combo#o81.Selecte(+alue @ "1" Dim (a As New SqlDataA(apter(ca(sql1. cn! Dim (a1 As New SqlDataA(apter(ca(sql?. cn! Dim (c As New DataSet (s New DataSet (c New DataSet (a.Fill((s. "6acturas"! (a1.Fill((c. "clientes"! Data2ri(+iew1.DataSource (s.$ables("6acturas"! 3abelA.$e8t (s.$ables("6acturas"!.Compute("count(6ac)numero!". ""! Catc7 e8 As /8ception /n( $ry /n( Sub Private Sub #utton1)Clic*(#y+al sen(er As System.,b-ect. #y+al e As System./ventAr's! 0an(les #utton1.Clic* /n( /n( Sub Private Sub #utton?)Clic*(#y+al sen(er As System.,b-ect. #y+al e As System./ventAr's! 0an(les #utton?.Clic* 4e.0i(e(! Form?.S7ow(! /n( Sub /n( Class

Imports System.Data Imports System.Data.SqlClient Public Class Form? Dim cn As New SqlConnection("Server (local!" (atabase #DFAC$%&A" Inte'rate( Security true"! Dim (s As New DataSet Private Sub Form?)3oa((#y+al sen(er As System.,b-ect. #y+al e As System./ventAr's! 0an(les 4y#ase.3oa( $ry Dim ca(sql "select 5 6rom 6ac)cabe" Dim (a As New SqlDataA(apter(ca(sql. cn! (a.Fill((s. "6acturas"! Data2ri(+iew1.DataSource (s.$ables("6acturas"! Catc7 e8 As /8ception /n( $ry /n( Sub Private Sub Data2ri(+iew1)CurrentCellC7an'e((#y+al sen(er As ,b-ect. #y+al e As System./ventAr's! 0an(les Data2ri(+iew1.CurrentCellC7an'e( $ry 1,btener el co(i'o (e la columna : y 6ila selecciona(a Dim co(i'o As Strin' co(i'o Data2ri(+iew1(:. Data2ri(+iew1.CurrentCell.&owIn(e8!.+alue Dim (s New DataSet Dim ca(sql? "select 5 6rom 6ac)(eta w7ere 6ac)numero 1" @ co(i'o @ "1" Dim (a As New SqlDataA(apter(ca(sql?. cn! (a.Fill((s. "(etalle"! Data2ri(+iew?.DataSource (s.tables("(etalle"! Catc7 e8 As /8ception /n( $ry /n( Sub Private Sub #utton1)Clic*(#y+al sen(er As System.,b-ect. #y+al e As System./ventAr's! 0an(les #utton1.Clic* 4e.0i(e(! Form1.S7ow(! /n( Sub Private Sub #utton?)Clic*(#y+al sen(er As System.,b-ect. #y+al e As System./ventAr's! 0an(les #utton?.Clic* 4e.0i(e(! FormA.S7ow(! /n( Sub /n( Class

Imports System.Data Imports System.Data.SqlClient Public Class FormA Dim cn As New SqlConnection("Server (local!" (atabase #DFAC$%&A" Inte'rate( Security true"! Dim (s As New DataSet Private Sub FormA)3oa((#y+al sen(er As System.,b-ect. #y+al e As System./ventAr's! 0an(les 4y#ase.3oa( $ry Dim ca(sql "select cli)co(i'o. cli)nombre 6rom clientes" Dim (a As New SqlDataA(apter(ca(sql. cn! (a.Fill((s. "clientes"! Combo#o81.DataSource (s.$ables("clientes"! 1,ri'en (e (atos conteni(o en la tabla Combo#o81.Display4ember "Cli)nombre" 14ostrar el campo en el combo Combo#o81.+alue4ember "Cli)co(i'o" 1Almacenar el co(i'o Catc7 e8 As /8ception 4essa'e#o8.S7ow(e8.4essa'e! /n( $ry /n( Sub Private Sub Combo#o81)Selecte(In(e8C7an'e((#y+al sen(er As System.,b-ect. #y+al e As System./ventAr's! 0an(les Combo#o81.Selecte(In(e8C7an'e( $ry Dim ca(sql1 "select 6ac)numero. cli)co(i'o 6rom 6ac)cabe " ca(sql1 E "w7ere cli)co(i'o 1" @ 4e.Combo#o81.Selecte(+alue @ "1" Dim (a As New SqlDataA(apter(ca(sql1. cn! (s New DataSet (a.Fill((s. "6acturas"! 4e.3ist#o81.DataSource (s.$ables("6acturas"! 1,ri'en (e (atos conteni(o en la tabla 4e.3ist#o81.Display4ember "6ac)numero" 14ostrar el campo en el combo 4e.3ist#o81.+alue4ember "6ac)numero" 1Almacenar el co(i'o Catc7 e8 As /8ception /n( $ry /n( Sub Private Sub 3ist#o81)Selecte(In(e8C7an'e((#y+al sen(er As System.,b-ect. #y+al e As System./ventAr's! 0an(les 3ist#o81.Selecte(In(e8C7an'e( $ry Dim ca(sql? "select 6ac)numero. art)co(i'o. art)canti(a(. art)precio. total art)canti(a(5art)precio 6rom 6ac)(eta " ca(sql? E "w7ere 6ac)numero 1" @ 4e.3ist#o81.Selecte(+alue @ "1" Dim (a As New SqlDataA(apter(ca(sql?. cn! (s New DataSet (a.Fill((s. "(etalle"! 4e.Data2ri(+iew1.DataSource (s.$ables("(etalle"! 1,ri'en (e (atos conteni(o en la tabla 3abelA.$e8t (s.$ables("(etalle"!.&ows.Count 3abel=.$e8t (s.$ables("(etalle"!.Compute("sum(total!". ""! Catc7 e8 As /8ception /n( $ry /n( Sub Private Sub #utton1)Clic*(#y+al sen(er As System.,b-ect. #y+al e As System./ventAr's! 0an(les #utton1.Clic* 4e.0i(e(! Form?.S7ow(! /n( Sub Private Sub #utton?)Clic*(#y+al sen(er As System.,b-ect. #y+al e As System./ventAr's! 0an(les #utton?.Clic* 4e.0i(e(!

Form9.S7ow(! /n( Sub End Class

Imports System.Data Imports System.Data.SqlClient Public Class Form9 Dim cn As New SqlConnection("Server (local!" (atabase #DFAC$%&A" Inte'rate( Security true"! Dim (s As New DataSet Private Sub Form9)3oa((#y+al sen(er As System.,b-ect. #y+al e As System./ventAr's! 0an(les 4y#ase.3oa( $ry Dim ca(sql "select (istinct aFo year(6ac)6ec7a! 6rom 6ac)cabe" Dim (a As New SqlDataA(apter(ca(sql. cn! (s New DataSet (a.Fill((s. "aFos"! 4e.3ist#o81.DataSource (s.$ables("aFos"! 1,ri'en (e (atos conteni(o en la tabla 4e.3ist#o81.Display4ember "aFo" 14ostrar el campo en el combo 4e.3ist#o81.+alue4ember "aFo" 1Almacenar el co(i'o Catc7 e8 As /8ception /n( $ry /n( Sub Private Sub 3ist#o81)Selecte(In(e8C7an'e((#y+al sen(er As System.,b-ect. #y+al e As System./ventAr's! 0an(les 3ist#o81.Selecte(In(e8C7an'e( $ry Dim ca(sql? "select 5 6rom 6ac)cabe " ca(sql? E "w7ere year(6ac)6ec7a! 1" @ 4e.3ist#o81.Selecte(+alue @ "1" Dim (a As New SqlDataA(apter(ca(sql?. cn! (s New DataSet (a.Fill((s. "6acturass"! 4e.Data2ri(+iew1.DataSource (s.$ables("6acturass"! 1,ri'en (e (atos conteni(o en la tabla Catc7 e8 As /8ception /n( $ry /n( Sub Private Sub #utton1)Clic*(#y+al sen(er As System.,b-ect. #y+al e As System./ventAr's! 0an(les #utton1.Clic* /n( /n( Sub /n( Class

You might also like