0% found this document useful (0 votes)
34 views4 pages

Sesion 05: Domingo 12 de Marzo Del 2011 Instrucciones de Mantenimiento de Sqlserver

The document provides instructions for maintaining SQL Server tables. It discusses using INSERT, UPDATE, and DELETE statements and creating a form to perform maintenance on the Region table in the Northwind database. It also discusses creating a form to perform maintenance on the Products table, including inserting, updating, and deleting records.

Uploaded by

Gina Huertas
Copyright
© © All Rights Reserved
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)
34 views4 pages

Sesion 05: Domingo 12 de Marzo Del 2011 Instrucciones de Mantenimiento de Sqlserver

The document provides instructions for maintaining SQL Server tables. It discusses using INSERT, UPDATE, and DELETE statements and creating a form to perform maintenance on the Region table in the Northwind database. It also discusses creating a form to perform maintenance on the Products table, including inserting, updating, and deleting records.

Uploaded by

Gina Huertas
Copyright
© © All Rights Reserved
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/ 4

SESION 05

Domingo 12 de Marzo del 2011

INSTRUCCIONES DE MANTENIMIENTO DE SQLSERVER


Objetivos : Después de completar este capítulo Ud. Estará en condición de:
 Emplear instrucciones insert into,update,delete
 Realizar mantenimiento a una tabla de sqlserver

APLICACIÓN MANTENIMIENTO A UNA TABLA

Diseñar un Formulario que de mantenimiento a la tabla Region de la base de datos Northwind

Codigo del modulo


Imports System.Data.SqlClient
Public Class Class1
Public Shared Sub MOSTRAR(ByVal dg As DataGridView)
Dim DA As New SqlDataAdapter("select * from region order by regionid", CN)
ds.Clear()
DA.Fill(ds, "reg")
dg.DataSource = ds.Tables("reg")
End Sub

Codigo del formulario


Imports System.Data.SqlClient
Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As
Class1.MOSTRAR(DataGridView1)
txtcodigo.DataBindings.Add(New Binding("text", ds, "reg.regionid"))

Lic. Gina Huertas Camacho Paá gina 1


txtRegion.DataBindings.Add(New Binding("text", ds, "reg.regiondescription"))
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
sql = "insert into region (RegionId,RegionDescription) values ( '" & txtcodigo.Text & "','" & txtRegion.Text & "')"
Dim cmd As New SqlCommand(sql, CN)
CN.Open()
Dim I As Integer
I = cmd.ExecuteNonQuery
If I > 0 Then
MsgBox("Registro Guardado con exito")
CN.Close()
End If
Class1.MOSTRAR(DataGridView1)
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
sql = "update region set RegionDescription='" & txtRegion.Text & "' where RegionId='" & txtcodigo.Text & "'"
Dim cmd As New SqlCommand(sql, CN)
CN.Open()
Dim I As Integer
I = cmd.ExecuteNonQuery
If I > 0 Then
MsgBox("Registro Guardado con exito")
CN.Close()
End If
Class1.MOSTRAR(DataGridView1)
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As
sql = "delete from region where regionid='" & txtcodigo.Text & "'"
Dim cmd As New SqlCommand(sql, CN)
CN.Open()
Dim I As Integer
I = cmd.ExecuteNonQuery
If I > 0 Then
MsgBox("Registro eliminado con exito")
CN.Close()
End If
Class1.MOSTRAR(DataGridView1)
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As
Me.BindingContext(ds, "reg").Position = 0
End Sub
Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As
Me.BindingContext(ds, "reg").Position -= 1
End Sub
Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As
Me.BindingContext(ds, "reg").Position += 1
End Sub
Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As
Me.BindingContext(ds, "reg").Position = ds.Tables(0).Rows.Count - 1
End Sub

Lic. Gina Huertas Camacho Paá gina 2


APLICACIÓN MANTENIMIENTO A LA TABLA PRODUCTOS

Crear la base de datos ejemplo con la tabla PRODUCTOS

Realizar el mantenimiento a dicha tabla


Clase
Imports System.Data
Imports System.Data.SqlClient

Public Class Class1


Public Shared Sub mostrar()
Dim da As New SqlDataAdapter("select * from Productos", cn)
dsproductos.Clear()
da.Fill(dsproductos, "prod")
End Sub

End class
formulario
Imports System.Data
Imports System.Data.SqlClient
Public Class Productos

Dim sql As String

Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As


TxtCodigo.Clear()
TxtNombre.Clear()
NudPrecio.Value = 0
End Sub

Private Sub Productos_Load(ByVal sender As System.Object, ByVal e As


Class1.mostrar()
DataGridView1.DataSource = dsproductos.Tables(0)
TxtCodigo.DataBindings.Add(New Binding("text", dsproductos, "prod.idprod"))
TxtNombre.DataBindings.Add(New Binding("text", dsproductos,
"prod.descrip"))
NudPrecio.DataBindings.Add(New Binding("text", dsproductos, "prod.precio"))
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As
Me.BindingContext(dsproductos, "prod").Position += 1
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
Me.BindingContext(dsproductos, "prod").Position =
dsproductos.Tables(0).Rows.Count - 1
End Sub

Lic. Gina Huertas Camacho Paá gina 3


Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As
sql = "update productos set descrip='" & TxtNombre.Text & "', precio = '" &
NudPrecio.Value & "' where idprod='" & TxtCodigo.Text & "'"
cn.Open()
Dim comando As New SqlCommand(sql, cn)
comando.ExecuteNonQuery()
cn.Close()
Class1.mostrar()
DataGridView1.DataSource = dsproductos.Tables(0)
End Sub

Private Sub Button8_Click(ByVal sender As System.Object, ByVal e As


sql = "insert into productos (idprod,descrip,precio) values('" &
TxtCodigo.Text & "','" & TxtNombre.Text & "','" & NudPrecio.Value & "')"
cn.Open()
Dim comando As New SqlCommand(sql, cn)
comando.ExecuteNonQuery()
cn.Close()
Class1.mostrar()
DataGridView1.DataSource = dsproductos.Tables(0)
End Sub

Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As


sql = "delete from productos where idprod='" & TxtCodigo.Text & "'"
cn.Open()
Dim comando As New SqlCommand(sql, cn)
comando.ExecuteNonQuery()
cn.Close()
Class1.mostrar()
DataGridView1.DataSource = dsproductos.Tables(0)
End Sub
End Class

Realiza el mantenimiento a la tabla


employees de la base
de datos norhtwind

Lic. Gina Huertas Camacho Paá gina 4

You might also like