Public Class menuprin
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles
Button...
DataGridView1.DataSource = datase.Tables(0)
conexion.Close()
End Try
End Sub
Private Sub registro_Load(ByVal sender As Sys...
TextBox3.Enabled = "true"
TextBox2.Enabled = "true"
TextBox5.Text = Dato1
TextBox2.Text = Dato2
TextBox3.Text = Dato3
Text...
Dim Dato1, Dato2, Dato3, Dato4 As String
Private Sub VolverInicioToolStripMenuItem_Click(ByVal sender As System.Object, By...
command.Parameters.AddWithValue("@id", TextBox5.Text)
command.Parameters.AddWithValue("@nom", TextBox2.Text)
command.Param...
INSERT INTO usuario(ide, nombre, apellido, tel) VALUES (@id,@nom ,@ape,@telefo)
ALTER PROCEDURE [dbo].[modificarusuario]
(...
Upcoming SlideShare
Loading in...5
×

Ejercicio sql server vs visual .net

1,190

Published on

By Carlos Castro

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
1,190
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
112
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Transcript of "Ejercicio sql server vs visual .net"

  1. 1. Public Class menuprin Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click 'Se compara si el control esta seleccionado If RadioButton1.Checked Then registro.Show() Me.Hide() End If 'Se compara si el control esta seleccionado If RadioButton2.Checked Then modificar.Show() Me.Hide() End If 'Se compara si la propiedad del control es verdadera If RadioButton3.Checked = True Then eliminar.Show() Me.Hide() End If End Sub End Class Imports System.Data.SqlClient Public Class registro Private Sub VolverToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles VolverToolStripMenuItem.Click menuprin.Show() Me.Hide() End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim conexion As New SqlConnection("Data Source=CASTROSQLEXPRESS;Initial Catalog=prueba;Integrated Security=True") Dim command As New SqlCommand("insertarusuario", conexion) Dim adapter As New SqlDataAdapter("mostrarusuarios", conexion) Dim datase As New DataSet command.CommandType = Data.CommandType.StoredProcedure command.Parameters.AddWithValue("@id", TextBox1.Text) command.Parameters.AddWithValue("@nom", TextBox2.Text) command.Parameters.AddWithValue("@ape", TextBox3.Text) command.Parameters.AddWithValue("@telefo", TextBox4.Text) Try conexion.Open() command.ExecuteNonQuery() Catch ex As Exception MessageBox.Show(ex.Message) Finally MsgBox("Usuario Registrado", vbInformation, "Sistema") TextBox1.Text = "" TextBox1.Enabled = "false" TextBox2.Text = "" TextBox2.Enabled = "false" TextBox3.Text = "" TextBox3.Enabled = "false" TextBox4.Text = "" TextBox4.Enabled = "false" Button1.Enabled = "false" Button2.Enabled = "true" adapter.Fill(datase)
  2. 2. DataGridView1.DataSource = datase.Tables(0) conexion.Close() End Try End Sub Private Sub registro_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Button2.Enabled = "false" End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click TextBox1.Text = "" TextBox1.Enabled = "true" TextBox2.Text = "" TextBox2.Enabled = "true" TextBox3.Text = "" TextBox3.Enabled = "true" TextBox4.Text = "" TextBox4.Enabled = "true" Button1.Enabled = "true" Button2.Enabled = "false" End Sub End Class Imports System.Data.SqlClient Public Class modificar Dim Dato1, Dato2, Dato3, Dato4 As String Private Sub VolverInicioToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles VolverInicioToolStripMenuItem.Click menuprin.Show() Me.Hide() End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim conexion As New SqlConnection("Data Source=CASTROSQLEXPRESS;Initial Catalog=prueba;Integrated Security=True") Dim command As New SqlCommand("buscausuario", conexion) Dim adapter As New SqlDataAdapter(command) Dim datase As New DataSet command.CommandType = Data.CommandType.StoredProcedure command.Parameters.AddWithValue("@id", TextBox1.Text) Try conexion.Open() command.ExecuteNonQuery() Catch ex As Exception MessageBox.Show(ex.Message) Finally TextBox1.Text = "" Button2.Enabled = "true" Button3.Enabled = "true" adapter.Fill(datase) DataGridView1.DataSource = datase.Tables(0) conexion.Close() End Try End Sub Private Sub Button2_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click TextBox5.Enabled = "false" TextBox4.Enabled = "true"
  3. 3. TextBox3.Enabled = "true" TextBox2.Enabled = "true" TextBox5.Text = Dato1 TextBox2.Text = Dato2 TextBox3.Text = Dato3 TextBox4.Text = Dato4 End Sub Private Sub DataGridView1_MouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles DataGridView1.MouseClick Dato1 = DataGridView1.CurrentRow.Cells(0).EditedFormattedValue.ToString Dato2 = DataGridView1.CurrentRow.Cells(1).EditedFormattedValue.ToString Dato3 = DataGridView1.CurrentRow.Cells(2).EditedFormattedValue.ToString Dato4 = DataGridView1.CurrentRow.Cells(3).EditedFormattedValue.ToString End Sub Private Sub modificar_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load TextBox5.Enabled = "false" TextBox4.Enabled = "false" TextBox3.Enabled = "false" TextBox2.Enabled = "false" End Sub Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click Dim conexion As New SqlConnection("Data Source=CASTROSQLEXPRESS;Initial Catalog=prueba;Integrated Security=True") Dim command As New SqlCommand("modificarusuario", conexion) Dim adapter As New SqlDataAdapter(command) Dim datase As New DataSet command.CommandType = Data.CommandType.StoredProcedure command.Parameters.AddWithValue("@id", TextBox5.Text) command.Parameters.AddWithValue("@nom", TextBox2.Text) command.Parameters.AddWithValue("@ape", TextBox3.Text) command.Parameters.AddWithValue("@telefo", TextBox4.Text) Try conexion.Open() command.ExecuteNonQuery() Catch ex As Exception MessageBox.Show(ex.Message) Finally MsgBox("Usuario Actualizado", vbInformation, "Sistema") TextBox2.Text = "" TextBox2.Enabled = "false" TextBox3.Text = "" TextBox3.Enabled = "false" TextBox4.Text = "" TextBox4.Enabled = "false" TextBox5.Text = "" TextBox5.Enabled = "false" Button3.Enabled = "false" Button2.Enabled = "false" adapter.Fill(datase) DataGridView1.Columns.Clear() conexion.Close() End Try End Sub End Class Imports System.Data.SqlClient Public Class eliminar
  4. 4. Dim Dato1, Dato2, Dato3, Dato4 As String Private Sub VolverInicioToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles VolverInicioToolStripMenuItem.Click menuprin.Show() Me.Hide() End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim conexion As New SqlConnection("Data Source=CASTROSQLEXPRESS;Initial Catalog=prueba;Integrated Security=True") Dim command As New SqlCommand("buscausuario", conexion) Dim adapter As New SqlDataAdapter(command) Dim datase As New DataSet command.CommandType = Data.CommandType.StoredProcedure command.Parameters.AddWithValue("@id", TextBox1.Text) Try conexion.Open() command.ExecuteNonQuery() Catch ex As Exception MessageBox.Show(ex.Message) Finally TextBox1.Text = "" Button2.Enabled = "true" Button3.Enabled = "true" adapter.Fill(datase) DataGridView1.DataSource = datase.Tables(0) conexion.Close() End Try End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click TextBox5.Enabled = "false" TextBox4.Enabled = "true" TextBox3.Enabled = "true" TextBox2.Enabled = "true" TextBox5.Text = Dato1 TextBox2.Text = Dato2 TextBox3.Text = Dato3 TextBox4.Text = Dato4 End Sub Private Sub DataGridView1_MouseClick(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles DataGridView1.MouseClick Dato1 = DataGridView1.CurrentRow.Cells(0).EditedFormattedValue.ToString Dato2 = DataGridView1.CurrentRow.Cells(1).EditedFormattedValue.ToString Dato3 = DataGridView1.CurrentRow.Cells(2).EditedFormattedValue.ToString Dato4 = DataGridView1.CurrentRow.Cells(3).EditedFormattedValue.ToString End Sub Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click Dim conexion As New SqlConnection("Data Source=CASTROSQLEXPRESS;Initial Catalog=prueba;Integrated Security=True") Dim command As New SqlCommand("borrarusuario", conexion) Dim adapter As New SqlDataAdapter(command) Dim datase As New DataSet command.CommandType = Data.CommandType.StoredProcedure
  5. 5. command.Parameters.AddWithValue("@id", TextBox5.Text) command.Parameters.AddWithValue("@nom", TextBox2.Text) command.Parameters.AddWithValue("@ape", TextBox3.Text) command.Parameters.AddWithValue("@telefo", TextBox4.Text) Try conexion.Open() command.ExecuteNonQuery() Catch ex As Exception MessageBox.Show(ex.Message) Finally MsgBox("Usuario Eliminado", vbInformation, "Sistema") TextBox2.Text = "" TextBox2.Enabled = "false" TextBox3.Text = "" TextBox3.Enabled = "false" TextBox4.Text = "" TextBox4.Enabled = "false" TextBox5.Text = "" TextBox5.Enabled = "false" Button3.Enabled = "false" Button2.Enabled = "false" adapter.Fill(datase) DataGridView1.Columns.Clear() conexion.Close() End Try End Sub End Class ALTER PROCEDURE [dbo].[borrarusuario] -- Add the parameters for the stored procedure here ( @id nvarchar(3), @nom nvarchar (50), @ape nvarchar (50), @telefo nvarchar(12) ) AS BEGIN -- SET NOCOUNT ON added to prevent extra result sets from -- interfering with SELECT statements. SET NOCOUNT ON; -- Insert statements for procedure here DELETE FROM usuario WHERE ide=@id and nombre=@nom and apellido=@ape and tel=@telefo END ALTER PROCEDURE [dbo].[buscausuario] ( @id nvarchar(3) ) AS BEGIN -- SET NOCOUNT ON added to prevent extra result sets from -- interfering with SELECT statements. SET NOCOUNT ON; -- Insert statements for procedure here SELECT * FROM usuario WHERE ide=@id ALTER PROCEDURE [dbo].[insertarusuario] ( @id nvarchar(3), @nom nvarchar(50), @ape nvarchar(70), @telefo nvarchar(15) ) AS SET NOCOUNT ON
  6. 6. INSERT INTO usuario(ide, nombre, apellido, tel) VALUES (@id,@nom ,@ape,@telefo) ALTER PROCEDURE [dbo].[modificarusuario] ( @id nvarchar(3), @nom nvarchar(50), @ape nvarchar(50), @telefo nvarchar(12) ) AS BEGIN -- SET NOCOUNT ON added to prevent extra result sets from -- interfering with SELECT statements. SET NOCOUNT ON; -- Insert statements for procedure here UPDATE usuario SET nombre=@nom, apellido=@ape, tel=@telefo WHERE ide=@id ALTER PROCEDURE [dbo].[mostrarusuarios] AS BEGIN -- SET NOCOUNT ON added to prevent extra result sets from -- interfering with SELECT statements. SET NOCOUNT ON; SELECT * FROM usuario

×