Sei sulla pagina 1di 15

Imports System.Data.

SqlClient
Public Class Form1

Inherits System.Windows.Forms.Form

Dim CadenaConexion As New SqlConnection("Data


Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename= C:\Users\Usuario\Desktop\Sistemas
de información\ENVIOS 24 JUN 2020\Northwind.mdf");"Integrated
Security=True;Connect Timeout=30")
Dim sentencia, mensaje As String
Private Sub ListarBaseDatos(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

End Sub

Sub Mostrar()
Dim da As New SqlDataAdapter("select * From Customers", CadenaConexion)
Dim ds As New DataSet

da.Fill(ds)
DataGridView1.DataSource = ds.Tables(0)
CadenaConexion.Close()
End Sub

Sub EjecutarSql(sql As String, msg As String)


Try
Dim cmd As New SqlCommand(sql, CadenaConexion)
CadenaConexion.Open()
cmd.ExecuteNonQuery()
CadenaConexion.Close()
MsgBox(msg)
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub

Private Sub btnInsertar_Click(sender As Object, e As EventArgs) Handles


btnInsertar.Click
sentencia = "INSERT INTO Customers values('" & txtId.Text & "', '" &
txtCompañia.Text & "', '" & txtContacto.Text & "', '" & txtCargo.Text & "', '" &
txtDireccion.Text & "', '" & txtCiudad.Text & "', '" & txtRegion.Text & "', '" &
txtPostal.Text & "', '" & txtPais.Text & "', '" & txtTelefono.Text & "', '" &
txtFax.Text & "')"
mensaje = "Datos insertados correctamente"
EjecutarSql(sentencia, mensaje)
End Sub

Private Sub btnActualizar_Click(sender As Object, e As EventArgs) Handles


btnActualizar.Click
sentencia = "UPDATE Customers set CompanyName ='" & txtCompañia.Text &
"', ContactName='" & txtContacto.Text & "', ContactTitle='" & txtCargo.Text & "',
Address='" & txtDireccion.Text & "', City='" & txtCiudad.Text & "', Region='" &
txtRegion.Text & "', PostalCode='" & txtPostal.Text & "', Country='" &
txtPais.Text & "', Phone='" & txtTelefono.Text & "', Fax='" & txtFax.Text & "'
WHERE CustomerID='" & txtId.Text & "'"
mensaje = "Datos actualizados correctamente"
EjecutarSql(sentencia, mensaje)
End Sub
Private Sub btnEliminar_Click(sender As Object, e As EventArgs) Handles
btnEliminar.Click
sentencia = "delete from Customers where CustomerID = '" + txtId.Text +
"'"
mensaje = "Datos eliminados correctamente"
EjecutarSql(sentencia, mensaje)
End Sub

End Class

<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _

Partial Class Form1

Inherits System.Windows.Forms.Form

'Form reemplaza a Dispose para limpiar la lista de componentes.

<System.Diagnostics.DebuggerNonUserCode()> _

Protected Overrides Sub Dispose(ByVal disposing As Boolean)

Try

If disposing AndAlso components IsNot Nothing Then

components.Dispose()

End If

Finally

MyBase.Dispose(disposing)

End Try

End Sub

'Requerido por el Diseñador de Windows Forms

Private components As System.ComponentModel.IContainer

'NOTA: el Diseñador de Windows Forms necesita el siguiente procedimiento

'Se puede modificar usando el Diseñador de Windows Forms.

'No lo modifique con el editor de código.

<System.Diagnostics.DebuggerStepThrough()> _
Private Sub InitializeComponent()

Me.components = New System.ComponentModel.Container()

Me.btnInsertar = New System.Windows.Forms.Button()

Me.btnActualizar = New System.Windows.Forms.Button()

Me.btnEliminar = New System.Windows.Forms.Button()

Me.btnMostrar = New System.Windows.Forms.Button()

Me.DataGridView1 = New System.Windows.Forms.DataGridView()

Me.txtId = New System.Windows.Forms.TextBox()

Me.txtCompañia = New System.Windows.Forms.TextBox()

Me.txtContacto = New System.Windows.Forms.TextBox()

Me.txtCargo = New System.Windows.Forms.TextBox()

Me.txtPostal = New System.Windows.Forms.TextBox()

Me.txtRegion = New System.Windows.Forms.TextBox()

Me.txtCiudad = New System.Windows.Forms.TextBox()

Me.txtDireccion = New System.Windows.Forms.TextBox()

Me.txtFax = New System.Windows.Forms.TextBox()

Me.txtTelefono = New System.Windows.Forms.TextBox()

Me.txtPais = New System.Windows.Forms.TextBox()

Me.Label1 = New System.Windows.Forms.Label()

Me.Label2 = New System.Windows.Forms.Label()

Me.Label3 = New System.Windows.Forms.Label()

Me.Label4 = New System.Windows.Forms.Label()

Me.Label5 = New System.Windows.Forms.Label()

Me.Label6 = New System.Windows.Forms.Label()

Me.Label7 = New System.Windows.Forms.Label()

Me.Label8 = New System.Windows.Forms.Label()

Me.Label9 = New System.Windows.Forms.Label()

Me.Label10 = New System.Windows.Forms.Label()

Me.Label11 = New System.Windows.Forms.Label()

Me.NorthwindDataSet = New WindowsApp11.NorthwindDataSet()


Me.NorthwindDataSetBindingSource = New
System.Windows.Forms.BindingSource(Me.components)

Me.CustomerID = New System.Windows.Forms.DataGridViewTextBoxColumn()

Me.CompanyName = New System.Windows.Forms.DataGridViewTextBoxColumn()

Me.ContactName = New System.Windows.Forms.DataGridViewTextBoxColumn()

Me.ContactTitle = New System.Windows.Forms.DataGridViewTextBoxColumn()

Me.Adress = New System.Windows.Forms.DataGridViewTextBoxColumn()

Me.City = New System.Windows.Forms.DataGridViewTextBoxColumn()

Me.Region = New System.Windows.Forms.DataGridViewTextBoxColumn()

Me.PostalCode = New System.Windows.Forms.DataGridViewTextBoxColumn()

CType(Me.DataGridView1, System.ComponentModel.ISupportInitialize).BeginInit()

CType(Me.NorthwindDataSet, System.ComponentModel.ISupportInitialize).BeginInit()

CType(Me.NorthwindDataSetBindingSource,
System.ComponentModel.ISupportInitialize).BeginInit()

Me.SuspendLayout()

'

'btnInsertar

'

Me.btnInsertar.Location = New System.Drawing.Point(616, 16)

Me.btnInsertar.Name = "btnInsertar"

Me.btnInsertar.Size = New System.Drawing.Size(237, 34)

Me.btnInsertar.TabIndex = 0

Me.btnInsertar.Text = "Insertar"

Me.btnInsertar.UseVisualStyleBackColor = True

'

'btnActualizar

'

Me.btnActualizar.Location = New System.Drawing.Point(616, 56)

Me.btnActualizar.Name = "btnActualizar"

Me.btnActualizar.Size = New System.Drawing.Size(237, 34)

Me.btnActualizar.TabIndex = 1

Me.btnActualizar.Text = "Actualizar"
Me.btnActualizar.UseVisualStyleBackColor = True

'

'btnEliminar

'

Me.btnEliminar.Location = New System.Drawing.Point(616, 96)

Me.btnEliminar.Name = "btnEliminar"

Me.btnEliminar.Size = New System.Drawing.Size(237, 34)

Me.btnEliminar.TabIndex = 2

Me.btnEliminar.Text = "Eliminar"

Me.btnEliminar.UseVisualStyleBackColor = True

'

'btnMostrar

'

Me.btnMostrar.Location = New System.Drawing.Point(616, 136)

Me.btnMostrar.Name = "btnMostrar"

Me.btnMostrar.Size = New System.Drawing.Size(237, 34)

Me.btnMostrar.TabIndex = 3

Me.btnMostrar.Text = "Mostrar"

Me.btnMostrar.UseVisualStyleBackColor = True

'

'DataGridView1

'

Me.DataGridView1.AutoGenerateColumns = False

Me.DataGridView1.ColumnHeadersHeightSizeMode =
System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize

Me.DataGridView1.Columns.AddRange(New
System.Windows.Forms.DataGridViewColumn() {Me.CustomerID, Me.CompanyName,
Me.ContactName, Me.ContactTitle, Me.Adress, Me.City, Me.Region, Me.PostalCode})

Me.DataGridView1.DataSource = Me.NorthwindDataSetBindingSource

Me.DataGridView1.Location = New System.Drawing.Point(384, 186)

Me.DataGridView1.Name = "DataGridView1"

Me.DataGridView1.Size = New System.Drawing.Size(539, 246)


Me.DataGridView1.TabIndex = 4

'

'txtId

'

Me.txtId.Location = New System.Drawing.Point(204, 56)

Me.txtId.Name = "txtId"

Me.txtId.Size = New System.Drawing.Size(156, 20)

Me.txtId.TabIndex = 5

'

'txtCompañia

'

Me.txtCompañia.Location = New System.Drawing.Point(204, 82)

Me.txtCompañia.Name = "txtCompañia"

Me.txtCompañia.Size = New System.Drawing.Size(156, 20)

Me.txtCompañia.TabIndex = 6

'

'txtContacto

'

Me.txtContacto.Location = New System.Drawing.Point(204, 108)

Me.txtContacto.Name = "txtContacto"

Me.txtContacto.Size = New System.Drawing.Size(156, 20)

Me.txtContacto.TabIndex = 7

'

'txtCargo

'

Me.txtCargo.Location = New System.Drawing.Point(204, 134)

Me.txtCargo.Name = "txtCargo"

Me.txtCargo.Size = New System.Drawing.Size(156, 20)

Me.txtCargo.TabIndex = 8

'

'txtPostal
'

Me.txtPostal.Location = New System.Drawing.Point(204, 238)

Me.txtPostal.Name = "txtPostal"

Me.txtPostal.Size = New System.Drawing.Size(156, 20)

Me.txtPostal.TabIndex = 12

'

'txtRegion

'

Me.txtRegion.Location = New System.Drawing.Point(204, 212)

Me.txtRegion.Name = "txtRegion"

Me.txtRegion.Size = New System.Drawing.Size(156, 20)

Me.txtRegion.TabIndex = 11

'

'txtCiudad

'

Me.txtCiudad.Location = New System.Drawing.Point(204, 186)

Me.txtCiudad.Name = "txtCiudad"

Me.txtCiudad.Size = New System.Drawing.Size(156, 20)

Me.txtCiudad.TabIndex = 10

'

'txtDireccion

'

Me.txtDireccion.Location = New System.Drawing.Point(204, 160)

Me.txtDireccion.Name = "txtDireccion"

Me.txtDireccion.Size = New System.Drawing.Size(156, 20)

Me.txtDireccion.TabIndex = 9

'

'txtFax

'

Me.txtFax.Location = New System.Drawing.Point(204, 316)

Me.txtFax.Name = "txtFax"
Me.txtFax.Size = New System.Drawing.Size(156, 20)

Me.txtFax.TabIndex = 15

'

'txtTelefono

'

Me.txtTelefono.Location = New System.Drawing.Point(204, 290)

Me.txtTelefono.Name = "txtTelefono"

Me.txtTelefono.Size = New System.Drawing.Size(156, 20)

Me.txtTelefono.TabIndex = 14

'

'txtPais

'

Me.txtPais.Location = New System.Drawing.Point(204, 264)

Me.txtPais.Name = "txtPais"

Me.txtPais.Size = New System.Drawing.Size(156, 20)

Me.txtPais.TabIndex = 13

'

'Label1

'

Me.Label1.AutoSize = True

Me.Label1.Location = New System.Drawing.Point(128, 63)

Me.Label1.Name = "Label1"

Me.Label1.Size = New System.Drawing.Size(70, 13)

Me.Label1.TabIndex = 16

Me.Label1.Text = "ID del Cliente"

'

'Label2

'

Me.Label2.AutoSize = True

Me.Label2.Location = New System.Drawing.Point(76, 88)

Me.Label2.Name = "Label2"
Me.Label2.Size = New System.Drawing.Size(122, 13)

Me.Label2.TabIndex = 17

Me.Label2.Text = "Nombre de la Compañía"

'

'Label3

'

Me.Label3.AutoSize = True

Me.Label3.Location = New System.Drawing.Point(91, 111)

Me.Label3.Name = "Label3"

Me.Label3.Size = New System.Drawing.Size(107, 13)

Me.Label3.TabIndex = 18

Me.Label3.Text = "Nombre del Contacto"

'

'Label4

'

Me.Label4.AutoSize = True

Me.Label4.Location = New System.Drawing.Point(151, 137)

Me.Label4.Name = "Label4"

Me.Label4.Size = New System.Drawing.Size(35, 13)

Me.Label4.TabIndex = 19

Me.Label4.Text = "Cargo"

'

'Label5

'

Me.Label5.AutoSize = True

Me.Label5.Location = New System.Drawing.Point(151, 167)

Me.Label5.Name = "Label5"

Me.Label5.Size = New System.Drawing.Size(52, 13)

Me.Label5.TabIndex = 20

Me.Label5.Text = "Dirección"

'
'Label6

'

Me.Label6.AutoSize = True

Me.Label6.Location = New System.Drawing.Point(151, 193)

Me.Label6.Name = "Label6"

Me.Label6.Size = New System.Drawing.Size(40, 13)

Me.Label6.TabIndex = 21

Me.Label6.Text = "Ciudad"

'

'Label7

'

Me.Label7.AutoSize = True

Me.Label7.Location = New System.Drawing.Point(158, 215)

Me.Label7.Name = "Label7"

Me.Label7.Size = New System.Drawing.Size(41, 13)

Me.Label7.TabIndex = 22

Me.Label7.Text = "Región"

'

'Label8

'

Me.Label8.AutoSize = True

Me.Label8.Location = New System.Drawing.Point(128, 241)

Me.Label8.Name = "Label8"

Me.Label8.Size = New System.Drawing.Size(72, 13)

Me.Label8.TabIndex = 23

Me.Label8.Text = "Código Postal"

'

'Label9

'

Me.Label9.AutoSize = True

Me.Label9.Location = New System.Drawing.Point(162, 271)


Me.Label9.Name = "Label9"

Me.Label9.Size = New System.Drawing.Size(29, 13)

Me.Label9.TabIndex = 24

Me.Label9.Text = "País"

'

'Label10

'

Me.Label10.AutoSize = True

Me.Label10.Location = New System.Drawing.Point(149, 297)

Me.Label10.Name = "Label10"

Me.Label10.Size = New System.Drawing.Size(49, 13)

Me.Label10.TabIndex = 25

Me.Label10.Text = "Teléfono"

'

'Label11

'

Me.Label11.AutoSize = True

Me.Label11.Location = New System.Drawing.Point(150, 319)

Me.Label11.Name = "Label11"

Me.Label11.Size = New System.Drawing.Size(24, 13)

Me.Label11.TabIndex = 26

Me.Label11.Text = "Fax"

'

'NorthwindDataSet

'

Me.NorthwindDataSet.DataSetName = "NorthwindDataSet"

Me.NorthwindDataSet.SchemaSerializationMode =
System.Data.SchemaSerializationMode.IncludeSchema

'

'NorthwindDataSetBindingSource

'
Me.NorthwindDataSetBindingSource.DataSource = Me.NorthwindDataSet

Me.NorthwindDataSetBindingSource.Position = 0

'

'CustomerID

'

Me.CustomerID.HeaderText = "CustomerID"

Me.CustomerID.Name = "CustomerID"

'

'CompanyName

'

Me.CompanyName.HeaderText = "CompanyName"

Me.CompanyName.Name = "CompanyName"

'

'ContactName

'

Me.ContactName.HeaderText = "ContactName"

Me.ContactName.Name = "ContactName"

'

'ContactTitle

'

Me.ContactTitle.HeaderText = "ContactTitle"

Me.ContactTitle.Name = "ContactTitle"

'

'Adress

'

Me.Adress.HeaderText = "Adress"

Me.Adress.Name = "Adress"

'

'City

'

Me.City.HeaderText = "City"
Me.City.Name = "City"

'

'Region

'

Me.Region.HeaderText = "Region"

Me.Region.Name = "Region"

'

'PostalCode

'

Me.PostalCode.HeaderText = "PostalCode"

Me.PostalCode.Name = "PostalCode"

'

'Form1

'

Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)

Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font

Me.ClientSize = New System.Drawing.Size(935, 450)

Me.Controls.Add(Me.Label11)

Me.Controls.Add(Me.Label10)

Me.Controls.Add(Me.Label9)

Me.Controls.Add(Me.Label8)

Me.Controls.Add(Me.Label7)

Me.Controls.Add(Me.Label6)

Me.Controls.Add(Me.Label5)

Me.Controls.Add(Me.Label4)

Me.Controls.Add(Me.Label3)

Me.Controls.Add(Me.Label2)

Me.Controls.Add(Me.Label1)

Me.Controls.Add(Me.txtFax)

Me.Controls.Add(Me.txtTelefono)

Me.Controls.Add(Me.txtPais)
Me.Controls.Add(Me.txtPostal)

Me.Controls.Add(Me.txtRegion)

Me.Controls.Add(Me.txtCiudad)

Me.Controls.Add(Me.txtDireccion)

Me.Controls.Add(Me.txtCargo)

Me.Controls.Add(Me.txtContacto)

Me.Controls.Add(Me.txtCompañia)

Me.Controls.Add(Me.txtId)

Me.Controls.Add(Me.DataGridView1)

Me.Controls.Add(Me.btnMostrar)

Me.Controls.Add(Me.btnEliminar)

Me.Controls.Add(Me.btnActualizar)

Me.Controls.Add(Me.btnInsertar)

Me.Name = "Form1"

Me.Text = "Form1"

CType(Me.DataGridView1, System.ComponentModel.ISupportInitialize).EndInit()

CType(Me.NorthwindDataSet, System.ComponentModel.ISupportInitialize).EndInit()

CType(Me.NorthwindDataSetBindingSource,
System.ComponentModel.ISupportInitialize).EndInit()

Me.ResumeLayout(False)

Me.PerformLayout()

End Sub

Friend WithEvents btnInsertar As Button

Friend WithEvents btnActualizar As Button

Friend WithEvents btnEliminar As Button

Friend WithEvents btnMostrar As Button

Friend WithEvents DataGridView1 As DataGridView

Friend WithEvents txtId As TextBox

Friend WithEvents txtCompañia As TextBox


Friend WithEvents txtContacto As TextBox

Friend WithEvents txtCargo As TextBox

Friend WithEvents txtPostal As TextBox

Friend WithEvents txtRegion As TextBox

Friend WithEvents txtCiudad As TextBox

Friend WithEvents txtDireccion As TextBox

Friend WithEvents txtFax As TextBox

Friend WithEvents txtTelefono As TextBox

Friend WithEvents txtPais As TextBox

Friend WithEvents Label1 As Label

Friend WithEvents Label2 As Label

Friend WithEvents Label3 As Label

Friend WithEvents Label4 As Label

Friend WithEvents Label5 As Label

Friend WithEvents Label6 As Label

Friend WithEvents Label7 As Label

Friend WithEvents Label8 As Label

Friend WithEvents Label9 As Label

Friend WithEvents Label10 As Label

Friend WithEvents Label11 As Label

Friend WithEvents NorthwindDataSetBindingSource As BindingSource

Friend WithEvents NorthwindDataSet As NorthwindDataSet

Friend WithEvents CustomerID As DataGridViewTextBoxColumn

Friend WithEvents CompanyName As DataGridViewTextBoxColumn

Friend WithEvents ContactName As DataGridViewTextBoxColumn

Friend WithEvents ContactTitle As DataGridViewTextBoxColumn

Friend WithEvents Adress As DataGridViewTextBoxColumn

Friend WithEvents City As DataGridViewTextBoxColumn

Friend WithEvents Region As DataGridViewTextBoxColumn

Friend WithEvents PostalCode As DataGridViewTextBoxColumn

End Class

Potrebbero piacerti anche